Skip to content

Commit 56a4ee3

Browse files
committed
chore: Remove redundant comments and fix formatting
- Apply ruff formatting fixes - Update example documentation with terraform-docs
1 parent c747cc7 commit 56a4ee3

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

examples/build-package/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Note that this example may create resources which cost money. Run `terraform des
5454
| <a name="module_package_src_poetry2"></a> [package\_src\_poetry2](#module\_package\_src\_poetry2) | ../../ | n/a |
5555
| <a name="module_package_with_commands_and_patterns"></a> [package\_with\_commands\_and\_patterns](#module\_package\_with\_commands\_and\_patterns) | ../../ | n/a |
5656
| <a name="module_package_with_docker"></a> [package\_with\_docker](#module\_package\_with\_docker) | ../../ | n/a |
57+
| <a name="module_package_with_docker_shell_commands"></a> [package\_with\_docker\_shell\_commands](#module\_package\_with\_docker\_shell\_commands) | ../../ | n/a |
5758
| <a name="module_package_with_npm_lock_in_docker"></a> [package\_with\_npm\_lock\_in\_docker](#module\_package\_with\_npm\_lock\_in\_docker) | ../../ | n/a |
5859
| <a name="module_package_with_npm_requirements_in_docker"></a> [package\_with\_npm\_requirements\_in\_docker](#module\_package\_with\_npm\_requirements\_in\_docker) | ../../ | n/a |
5960
| <a name="module_package_with_patterns"></a> [package\_with\_patterns](#module\_package\_with\_patterns) | ../../ | n/a |

package.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -920,11 +920,11 @@ def execute(self, build_plan, zip_stream, query):
920920
"DOCKER TAG ID: %s -> %s", docker_image, docker_image_tag_id
921921
)
922922
else:
923-
# Image not found locally, try to pull it
924-
log.info("Docker image not found locally, pulling: %s", docker_image)
923+
log.info(
924+
"Docker image not found locally, pulling: %s", docker_image
925+
)
925926
try:
926927
check_call(docker_pull_command(docker_image))
927-
# Get the image ID after pulling
928928
output = check_output(docker_image_id_command(docker_image))
929929
if output:
930930
docker_image_tag_id = output.decode().strip()
@@ -1022,7 +1022,6 @@ def execute(self, build_plan, zip_stream, query):
10221022
script = action[1]
10231023

10241024
if docker and docker_image_tag_id:
1025-
# Execute shell commands in Docker container
10261025
if log.isEnabledFor(DEBUG2):
10271026
log.debug("exec shell script in docker...")
10281027
for line in script.splitlines():
@@ -1033,22 +1032,22 @@ def execute(self, build_plan, zip_stream, query):
10331032
[
10341033
script,
10351034
"retcode=$?",
1036-
"pwd", # Output final working directory to stdout
1035+
"pwd",
10371036
"exit $retcode",
10381037
]
10391038
)
10401039

10411040
# Add chown to fix file ownership (like pip at line 1150-1154)
10421041
chown_mask = "{}:{}".format(os.getuid(), os.getgid())
10431042
full_script = "{} && {}".format(
1044-
enhanced_script, shlex_join(["chown", "-R", chown_mask, "."])
1043+
enhanced_script,
1044+
shlex_join(["chown", "-R", chown_mask, "."]),
10451045
)
10461046

10471047
shell_command = [full_script]
10481048

1049-
# Execute in Docker
10501049
docker_cmd = docker_run_command(
1051-
sh_work_dir, # build_root = current working directory
1050+
sh_work_dir,
10521051
shell_command,
10531052
query.runtime,
10541053
image=docker_image_tag_id,
@@ -1076,16 +1075,17 @@ def execute(self, build_plan, zip_stream, query):
10761075
)
10771076

10781077
# Extract final working directory from stdout
1079-
# The 'pwd' command output is in the stdout, but we need to parse it
1078+
# The 'pwd' command output is in stdout, but we need to parse it
10801079
# because there might be other output from the script
10811080
output_lines = result.stdout.strip().split("\n")
10821081
if output_lines:
1083-
# The last line should be the pwd output
10841082
final_pwd = output_lines[-1]
10851083
# Map container path back to host path
10861084
# Container path structure: /var/task = sh_work_dir (via volume mount)
10871085
if final_pwd.startswith("/var/task"):
1088-
relative_path = final_pwd[len("/var/task") :].lstrip("/")
1086+
relative_path = final_pwd[len("/var/task") :].lstrip(
1087+
"/"
1088+
)
10891089
sh_work_dir = (
10901090
os.path.join(sh_work_dir, relative_path)
10911091
if relative_path
@@ -1096,7 +1096,7 @@ def execute(self, build_plan, zip_stream, query):
10961096
log.debug("WORKDIR: %s", sh_work_dir)
10971097

10981098
else:
1099-
# Execute shell commands on host (existing behavior)
1099+
# Execute shell commands on host
11001100
with tempfile.NamedTemporaryFile(
11011101
mode="w+t", delete=True
11021102
) as temp_file:

tests/test_zip_source.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ def test_sh_with_docker_basic():
2424
bpm = BuildPlanManager(args=Mock())
2525

2626
# Mock subprocess functions
27-
with patch("package.check_output") as mock_check_output, \
28-
patch("package.subprocess.run") as mock_run:
29-
27+
with patch("package.check_output") as mock_check_output, patch(
28+
"package.subprocess.run"
29+
) as mock_run:
3030
# Mock docker image ID lookup
3131
mock_check_output.return_value = b"sha256:abc123"
3232

@@ -88,10 +88,9 @@ def capture_write_dirs(path, *args, **kwargs):
8888
subdir = os.path.join(tmpdir, "subdir")
8989
os.makedirs(subdir, exist_ok=True)
9090

91-
with patch("package.check_output") as mock_check_output, \
92-
patch("package.subprocess.run") as mock_run, \
93-
patch("os.getcwd", return_value=tmpdir):
94-
91+
with patch("package.check_output") as mock_check_output, patch(
92+
"package.subprocess.run"
93+
) as mock_run, patch("os.getcwd", return_value=tmpdir):
9594
mock_check_output.return_value = b"sha256:abc123"
9695

9796
# Mock docker execution returning changed working directory
@@ -163,9 +162,9 @@ def test_sh_docker_error_handling():
163162

164163
bpm = BuildPlanManager(args=Mock())
165164

166-
with patch("package.check_output") as mock_check_output, \
167-
patch("package.subprocess.run") as mock_run:
168-
165+
with patch("package.check_output") as mock_check_output, patch(
166+
"package.subprocess.run"
167+
) as mock_run:
169168
mock_check_output.return_value = b"sha256:abc123"
170169

171170
# Mock docker execution failure

0 commit comments

Comments
 (0)