Skip to content

Commit

Permalink
Black formatting.
Browse files Browse the repository at this point in the history
No-Issue

Signed-off-by: James Tanner <[email protected]>
  • Loading branch information
jctanner committed Nov 11, 2024
1 parent 74c2495 commit d128e48
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
14 changes: 10 additions & 4 deletions galaxy_importer/ansible_test/builders/local_image_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def get_container_engine(cfg):
@staticmethod
def _build_dockerfile(dirname):
file_location = os.path.join(dirname, "Dockerfile")
with resource_filename_compat("galaxy_importer", "ansible_test/container/Dockerfile") as pkg_dockerfile:
with resource_filename_compat(
"galaxy_importer", "ansible_test/container/Dockerfile"
) as pkg_dockerfile:
shutil.copyfile(pkg_dockerfile, file_location)
with open(file_location, "r+") as f:
lines = f.readlines()
Expand All @@ -92,11 +94,15 @@ def _build_dockerfile(dirname):
@staticmethod
def _build_image_with_artifact(container_engine, dirname):

with resource_filename_compat("galaxy_importer", "ansible_test/container/entrypoint.sh") as pkg_entrypoint:
shutil.copyfile(pkg_entrypoint, os.path.join(dirname, "entrypoint.sh"))
with resource_filename_compat(
"galaxy_importer", "ansible_test/container/entrypoint.sh"
) as pkg_entrypoint:
shutil.copyfile(pkg_entrypoint, os.path.join(dirname, "entrypoint.sh"))

os.mkdir(os.path.join(dirname, "eda"))
with resource_filename_compat("galaxy_importer", "ansible_test/container/eda/tox.ini") as eda_linting:
with resource_filename_compat(
"galaxy_importer", "ansible_test/container/eda/tox.ini"
) as eda_linting:
shutil.copyfile(eda_linting, os.path.join(dirname, "eda", "tox.ini"))

cmd = [container_engine, "build", ".", "--quiet"]
Expand Down
8 changes: 5 additions & 3 deletions galaxy_importer/ansible_test/runners/openshift_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ def _get_ca_path():

@staticmethod
def _get_job_template():
'''
"""
path = resource_filename_compat("galaxy_importer", "ansible_test/job_template.yaml")
with open(path, "r") as f:
job_template = f.read()
'''
with resource_filename_compat("galaxy_importer", "ansible_test/job_template.yaml") as file_path:
"""
with resource_filename_compat(
"galaxy_importer", "ansible_test/job_template.yaml"
) as file_path:
with open(file_path, "r") as f:
job_template = f.read()
return job_template
Expand Down
10 changes: 8 additions & 2 deletions galaxy_importer/utils/resource_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

try:
from pkg_resources import resource_stream

USE_PKG_RESOURCES = True
except ImportError:
from importlib.resources import files

USE_PKG_RESOURCES = False

from contextlib import contextmanager
Expand All @@ -33,7 +35,7 @@ def resource_stream_compat(package, resource_name):
stream = resource_stream(package, resource_name)
else:
# Fallback to importlib.resources if pkg_resources is not available
stream = (files(package) / resource_name).open('rb')
stream = (files(package) / resource_name).open("rb")

try:
yield stream
Expand Down Expand Up @@ -65,7 +67,11 @@ def resource_filename_compat(package, resource_name):
resource_path = files(package) / resource_name
if resource_path.is_dir():
# Copy directory content to temp_dir if resource is a directory
shutil.copytree(resource_path, os.path.join(temp_dir, os.path.basename(resource_path)), dirs_exist_ok=True)
shutil.copytree(
resource_path,
os.path.join(temp_dir, os.path.basename(resource_path)),
dirs_exist_ok=True,
)
yield os.path.join(temp_dir, os.path.basename(resource_path))
else:
# Copy file to temp_dir if resource is a file
Expand Down

0 comments on commit d128e48

Please sign in to comment.