Skip to content

Commit

Permalink
refactor(remote_sources): make build_args property
Browse files Browse the repository at this point in the history
We don't need to havbe build_args as function anymore, it can be a
property of RemoteSources

Signed-off-by: Martin Basti <mbasti@redhat.com>
  • Loading branch information
MartinBasti committed Aug 14, 2024
1 parent 73ee4b4 commit f5b68d8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
51 changes: 18 additions & 33 deletions atomic_reactor/plugins/resolve_remote_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -329,15 +316,13 @@ 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"],
name=name,
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
Expand Down
1 change: 0 additions & 1 deletion tests/plugins/test_resolve_remote_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
]
Expand Down

0 comments on commit f5b68d8

Please sign in to comment.