From 65ffea2cfd99a27b6be3fc3e48482cf0fb821f2f Mon Sep 17 00:00:00 2001 From: Richard Gilmore Date: Wed, 8 Jan 2025 01:05:06 +0000 Subject: [PATCH] feat: Allow temp dir for poetry docker builds (#638) Co-authored-by: Anton Babenko --- examples/build-package/main.tf | 1 + package.py | 20 +++++++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/build-package/main.tf b/examples/build-package/main.tf index 7119a5d5..2afce855 100644 --- a/examples/build-package/main.tf +++ b/examples/build-package/main.tf @@ -426,6 +426,7 @@ module "lambda_layer_poetry" { { path = "${path.module}/../fixtures/python-app-poetry" poetry_install = true + poetry_tmp_dir = "${path.cwd}/../fixtures" } ] hash_extra = "extra-hash-to-prevent-conflicts-with-module.package_dir" diff --git a/package.py b/package.py index a0944342..6e19846c 100644 --- a/package.py +++ b/package.py @@ -707,7 +707,7 @@ def pip_requirements_step(path, prefix=None, required=False, tmp_dir=None): hash(requirements) def poetry_install_step( - path, poetry_export_extra_args=[], prefix=None, required=False + path, poetry_export_extra_args=[], prefix=None, required=False, tmp_dir=None ): pyproject_file = path if os.path.isdir(path): @@ -718,7 +718,7 @@ def poetry_install_step( "poetry configuration not found: {}".format(pyproject_file) ) else: - step("poetry", runtime, path, poetry_export_extra_args, prefix) + step("poetry", runtime, path, poetry_export_extra_args, prefix, tmp_dir) hash(pyproject_file) pyproject_path = os.path.dirname(pyproject_file) poetry_lock_file = os.path.join(pyproject_path, "poetry.lock") @@ -849,6 +849,7 @@ def commands_step(path, commands): prefix=prefix, poetry_export_extra_args=poetry_export_extra_args, required=True, + tmp_dir=claim.get("poetry_tmp_dir"), ) if npm_requirements and runtime.startswith("nodejs"): @@ -949,15 +950,12 @@ def execute(self, build_plan, zip_stream, query): # XXX: timestamp=0 - what actually do with it? zs.write_dirs(rd, prefix=prefix, timestamp=0) elif cmd == "poetry": - ( - runtime, - path, - poetry_export_extra_args, - prefix, - ) = action[1:] + (runtime, path, poetry_export_extra_args, prefix, tmp_dir) = action[ + 1: + ] log.info("poetry_export_extra_args: %s", poetry_export_extra_args) with install_poetry_dependencies( - query, path, poetry_export_extra_args + query, path, poetry_export_extra_args, tmp_dir ) as rd: if rd: if pf: @@ -1177,7 +1175,7 @@ def install_pip_requirements(query, requirements_file, tmp_dir): @contextmanager -def install_poetry_dependencies(query, path, poetry_export_extra_args): +def install_poetry_dependencies(query, path, poetry_export_extra_args, tmp_dir): # TODO: # 1. Emit files instead of temp_dir @@ -1231,7 +1229,7 @@ def install_poetry_dependencies(query, path, poetry_export_extra_args): working_dir = os.getcwd() log.info("Installing python dependencies with poetry & pip: %s", poetry_lock_file) - with tempdir() as temp_dir: + with tempdir(tmp_dir) as temp_dir: def copy_file_to_target(file, temp_dir): filename = os.path.basename(file)