Skip to content

Commit

Permalink
Add support for exporting poetry.lock to requirements.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
carlcsaposs-canonical committed Sep 23, 2024
1 parent 28cbdec commit 18cc055
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
27 changes: 24 additions & 3 deletions charmcraftcache/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,30 @@ def pack(context: typer.Context, verbose: Verbose = False):
"requirements.txt not found. `cd` into the directory with charmcraft.yaml"
)
else:
raise FileNotFoundError(
"requirements.txt not found. Are you using a pack wrapper (e.g. `tox run -e build-dev`)? If so, call charmcraftcache via the wrapper."
)
# Convert subset of poetry.lock to requirements.txt
try:
subprocess.run(
[
"poetry",
"export",
"--only",
"main,charm-libs",
"--output",
"requirements.txt",
],
check=True,
)
except FileNotFoundError:
# poetry not installed
raise FileNotFoundError(
"requirements.txt not found and poetry not installed. Are you using poetry.lock? If so, install poetry"
)
# TODO: add handling if poetry installed but poetry-plugin-export not installed
# (only applicable once https://github.com/python-poetry/poetry/pull/5980 merged)
except subprocess.CalledProcessError:
raise FileNotFoundError(
"requirements.txt not found. Failed to create requirements.txt from poetry.lock"
)
report_file = cache_directory / "report.json"
subprocess.run(
[
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "charmcraftcache"
version = "0.3.8"
version = "0.4.0"
description = "Fast first-time builds for charmcraft"
authors = ["Carl Csaposs <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 18cc055

Please sign in to comment.