Skip to content

Commit

Permalink
feat: Allow temp dir for poetry docker builds (#638)
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Babenko <[email protected]>
  • Loading branch information
gilandose and antonbabenko authored Jan 8, 2025
1 parent 9bbe65d commit 65ffea2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions examples/build-package/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 9 additions & 11 deletions package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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")
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 65ffea2

Please sign in to comment.