From f5b68d8c06d5a10dc89de6be63aa0c8a7be757b4 Mon Sep 17 00:00:00 2001 From: Martin Basti Date: Tue, 13 Aug 2024 18:36:50 +0200 Subject: [PATCH] refactor(remote_sources): make build_args property We don't need to havbe build_args as function anymore, it can be a property of RemoteSources Signed-off-by: Martin Basti --- .../plugins/resolve_remote_source.py | 51 +++++++------------ tests/plugins/test_resolve_remote_source.py | 1 - 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/atomic_reactor/plugins/resolve_remote_source.py b/atomic_reactor/plugins/resolve_remote_source.py index 6b0350a1e..a7df9de7a 100644 --- a/atomic_reactor/plugins/resolve_remote_source.py +++ b/atomic_reactor/plugins/resolve_remote_source.py @@ -52,7 +52,6 @@ class RemoteSource: json_data: dict json_env_data: Dict[str, Dict[str, str]] json_config_data: List[Dict[str, str]] - build_args: Dict[str, str] tarball_path: Path @classmethod @@ -83,6 +82,24 @@ def json_env_filename(cls, name: Optional[str]): else: return REMOTE_SOURCE_JSON_ENV_FILENAME + @property + def build_args(self) -> Dict[str, str]: + build_args = {} + + for env_var, value_info in self.json_env_data.items(): + build_arg_value = value_info['value'] + kind = value_info['kind'] + if kind == 'path': + name = self.name or '' + build_arg_value = os.path.join(REMOTE_SOURCE_DIR, name, value_info['value']) + build_args[env_var] = build_arg_value + elif kind == 'literal': + build_args[env_var] = build_arg_value + else: + raise RuntimeError(f'Unknown kind {kind} got from Cachito.') + + return build_args + class ResolveRemoteSourcePlugin(Plugin): """Initiate a new Cachito request for sources @@ -244,36 +261,6 @@ def inject_into_build_dir( return created_dirs - def get_buildargs( - self, env_vars: Dict[str, Dict[str, str]], - remote_source_name: Optional[str] - ) -> Dict[str, str]: - build_args = {} - - for env_var, value_info in env_vars.items(): - build_arg_value = value_info['value'] - kind = value_info['kind'] - if kind == 'path': - name = remote_source_name or '' - build_arg_value = os.path.join(REMOTE_SOURCE_DIR, name, value_info['value']) - self.log.debug( - 'Setting the Cachito environment variable "%s" to the absolute path "%s"', - env_var, - build_arg_value, - ) - build_args[env_var] = build_arg_value - elif kind == 'literal': - self.log.debug( - 'Setting the Cachito environment variable "%s" to a literal value "%s"', - env_var, - build_arg_value, - ) - build_args[env_var] = build_arg_value - else: - raise RuntimeError(f'Unknown kind {kind} got from Cachito.') - - return build_args - def source_request_to_json(self, source_request): """Create a relevant representation of the source request""" required = ('packages', 'ref', 'repo') @@ -329,7 +316,6 @@ def process_request(self, source_request: dict, name: Optional[str]) -> RemoteSo ) env_vars = self.cachito_session.get_request_env_vars(source_request["id"]) - build_args = self.get_buildargs(env_vars, name) remote_source = RemoteSource( id=source_request["id"], @@ -337,7 +323,6 @@ def process_request(self, source_request: dict, name: Optional[str]) -> RemoteSo json_data=self.source_request_to_json(source_request), json_env_data=env_vars, json_config_data=self.cachito_session.get_request_config_files(source_request["id"]), - build_args=build_args, tarball_path=Path(tarball_dest_path), ) return remote_source diff --git a/tests/plugins/test_resolve_remote_source.py b/tests/plugins/test_resolve_remote_source.py index 78e10a0d1..5dc5746b7 100644 --- a/tests/plugins/test_resolve_remote_source.py +++ b/tests/plugins/test_resolve_remote_source.py @@ -980,7 +980,6 @@ def test_inject_remote_sources_dest_already_exists(workflow): json_data={}, json_env_data={}, json_config_data={}, - build_args={}, tarball_path=Path("/does/not/matter"), ), ]