Skip to content

feat: Allow temp dir for poetry docker builds #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.root}/builds/"
}
]
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 @@ -847,6 +847,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 @@ -947,15 +948,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 @@ -1175,7 +1173,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 @@ -1229,7 +1227,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