Skip to content

Commit

Permalink
feat: Export poetry dependencies and install them with pip --no-deps
Browse files Browse the repository at this point in the history
  • Loading branch information
pdecat committed May 17, 2022
1 parent 6305c37 commit 60794b4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions package.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ def install_poetry_dependencies(query, path):

working_dir = os.getcwd()

log.info("Installing python dependencies with poetry: %s", poetry_lock_file)
log.info("Installing python dependencies with poetry & pip: %s", poetry_lock_file)
with tempdir() as temp_dir:
def copy_file_to_target(file, temp_dir):
filename = os.path.basename(file)
Expand All @@ -1066,6 +1066,7 @@ def copy_file_to_target(file, temp_dir):
pyproject_target_file = copy_file_to_target(pyproject_file, temp_dir)

poetry_exec = "poetry"
python_exec = runtime
subproc_env = None

if not docker:
Expand All @@ -1075,12 +1076,13 @@ def copy_file_to_target(file, temp_dir):
# Install dependencies into the temporary directory.
with cd(temp_dir):
# NOTE: poetry must be available, which is the case with lambci/lambda:build-python* docker images
# FIXME: poetry install does not currently allow to specify the target directory so we extract
# installed packages from .venv/lib/python*/site-packages
# FIXME: poetry install does not currently allow to specify the target directory so we export the
# requirements then install them with pip --no-deps to avoid using pip dependency resolver
poetry_commands = [
shlex_join([ poetry_exec, "config", "--no-interaction", "virtualenvs.create", "true" ]),
shlex_join([ poetry_exec, "config", "--no-interaction", "virtualenvs.in-project", "true" ]),
shlex_join([ poetry_exec, "install", "--no-interaction" ]),
shlex_join([ poetry_exec, "export", "-f", "requirements.txt", "--output", "requirements.txt" ]),
shlex_join([ python_exec, '-m', 'pip', 'install', '--no-compile', '--no-deps', '--prefix=', '--target=.','--requirement=requirements.txt']),
]
if docker:
with_ssh_agent = docker.with_ssh_agent
Expand Down Expand Up @@ -1115,11 +1117,10 @@ def copy_file_to_target(file, temp_dir):
for poetry_command in poetry_commands:
check_call(poetry_command, env=subproc_env)

# FIXME: not really needed as only the content of a subdirectory is exposed
os.remove(poetry_lock_target_file)
os.remove(pyproject_target_file)

yield os.path.join(temp_dir, ".venv/lib/", runtime, "site-packages")
yield temp_dir


@contextmanager
Expand Down

0 comments on commit 60794b4

Please sign in to comment.