Skip to content

Commit d33b722

Browse files
n8feltonpdecat
andauthored
feat: Allow defining direct path to pyproject.toml (#525)
Co-authored-by: Patrick Decat <[email protected]>
1 parent dcb087d commit d33b722

File tree

8 files changed

+99
-7
lines changed

8 files changed

+99
-7
lines changed

examples/build-package/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ Note that this example may create resources which cost money. Run `terraform des
4646
| <a name="module_package_dir_without_pip_install"></a> [package\_dir\_without\_pip\_install](#module\_package\_dir\_without\_pip\_install) | ../../ | n/a |
4747
| <a name="module_package_file"></a> [package\_file](#module\_package\_file) | ../../ | n/a |
4848
| <a name="module_package_file_with_pip_requirements"></a> [package\_file\_with\_pip\_requirements](#module\_package\_file\_with\_pip\_requirements) | ../../ | n/a |
49+
| <a name="module_package_src_poetry"></a> [package\_src\_poetry](#module\_package\_src\_poetry) | ../../ | n/a |
50+
| <a name="module_package_src_poetry2"></a> [package\_src\_poetry2](#module\_package\_src\_poetry2) | ../../ | n/a |
4951
| <a name="module_package_with_commands_and_patterns"></a> [package\_with\_commands\_and\_patterns](#module\_package\_with\_commands\_and\_patterns) | ../../ | n/a |
5052
| <a name="module_package_with_docker"></a> [package\_with\_docker](#module\_package\_with\_docker) | ../../ | n/a |
5153
| <a name="module_package_with_npm_requirements_in_docker"></a> [package\_with\_npm\_requirements\_in\_docker](#module\_package\_with\_npm\_requirements\_in\_docker) | ../../ | n/a |

examples/build-package/main.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,45 @@ module "package_dir_poetry" {
6363
artifacts_dir = "${path.root}/builds/package_dir_poetry/"
6464
}
6565

66+
# Create zip-archive of a src directory where "poetry export" & "pip install --no-deps" will also be executed (using docker)
67+
module "package_src_poetry" {
68+
source = "../../"
69+
70+
create_function = false
71+
72+
build_in_docker = true
73+
runtime = "python3.9"
74+
docker_image = "build-python3.9-poetry"
75+
docker_file = "${path.module}/../fixtures/python3.9-app-src-poetry/docker/Dockerfile"
76+
77+
source_path = [
78+
"${path.module}/../fixtures/python3.9-app-src-poetry/src",
79+
{
80+
path = "${path.module}/../fixtures/python3.9-app-src-poetry/pyproject.toml"
81+
poetry_install = true
82+
}
83+
]
84+
artifacts_dir = "${path.root}/builds/package_src_poetry/"
85+
}
86+
87+
# Create zip-archive of a src directory where "poetry export" & "pip install --no-deps" will also be executed (using docker)
88+
module "package_src_poetry2" {
89+
source = "../../"
90+
91+
create_function = false
92+
93+
build_in_docker = true
94+
runtime = "python3.9"
95+
docker_image = "build-python3.9-poetry"
96+
docker_file = "${path.module}/../fixtures/python3.9-app-src-poetry/docker/Dockerfile"
97+
98+
source_path = [
99+
"${path.module}/../fixtures/python3.9-app-src-poetry/src",
100+
"${path.module}/../fixtures/python3.9-app-src-poetry/pyproject.toml"
101+
]
102+
artifacts_dir = "${path.root}/builds/package_src_poetry2/"
103+
}
104+
66105
# Create zip-archive of a single directory where "poetry export" & "pip install --no-deps" will also be executed (not using docker)
67106
module "package_dir_poetry_no_docker" {
68107
source = "../../"

examples/fixtures/python3.9-app-src-poetry/README.md

Whitespace-only changes.

examples/fixtures/python3.9-app-src-poetry/poetry.lock

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tool.poetry]
2+
name = "python3-9-app-src-poetry"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["Your Name <[email protected]>"]
6+
readme = "README.md"
7+
packages = [{include = "python39_app_src_poetry", from = "src"}]
8+
9+
[tool.poetry.dependencies]
10+
python = "^3.9"
11+
colorful = "^0.5.5"
12+
13+
14+
[build-system]
15+
requires = ["poetry-core"]
16+
build-backend = "poetry.core.masonry.api"

examples/fixtures/python3.9-app-src-poetry/src/python39_app_src_poetry/__init__.py

Whitespace-only changes.

examples/fixtures/python3.9-app-src-poetry/tests/__init__.py

Whitespace-only changes.

package.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,11 @@ def poetry_install_step(path, prefix=None, required=False):
690690
else:
691691
step("poetry", runtime, path, prefix)
692692
hash(pyproject_file)
693-
poetry_lock_file = os.path.join(path, "poetry.lock")
693+
pyproject_path = os.path.dirname(pyproject_file)
694+
poetry_lock_file = os.path.join(pyproject_path, "poetry.lock")
694695
if os.path.isfile(poetry_lock_file):
695696
hash(poetry_lock_file)
696-
poetry_toml_file = os.path.join(path, "poetry.toml")
697+
poetry_toml_file = os.path.join(pyproject_path, "poetry.toml")
697698
if os.path.isfile(poetry_toml_file):
698699
hash(poetry_toml_file)
699700

@@ -1029,14 +1030,17 @@ def install_poetry_dependencies(query, path):
10291030
# 1. Emit files instead of temp_dir
10301031

10311032
# pyproject.toml is always required by poetry
1032-
pyproject_file = os.path.join(path, "pyproject.toml")
1033+
pyproject_file = path
1034+
if os.path.isdir(path):
1035+
pyproject_file = os.path.join(path, "pyproject.toml")
10331036
if not os.path.exists(pyproject_file):
10341037
yield
10351038
return
10361039

10371040
# poetry.lock & poetry.toml are optional
1038-
poetry_lock_file = os.path.join(path, "poetry.lock")
1039-
poetry_toml_file = os.path.join(path, "poetry.toml")
1041+
pyproject_path = os.path.dirname(pyproject_file)
1042+
poetry_lock_file = os.path.join(pyproject_path, "poetry.lock")
1043+
poetry_toml_file = os.path.join(pyproject_path, "poetry.toml")
10401044

10411045
runtime = query.runtime
10421046
artifacts_dir = query.artifacts_dir
@@ -1085,13 +1089,13 @@ def copy_file_to_target(file, temp_dir):
10851089
pyproject_target_file = copy_file_to_target(pyproject_file, temp_dir)
10861090

10871091
if os.path.isfile(poetry_lock_file):
1088-
log.info("Using poetry lock file: %s", poetry_lock_file)
1092+
log.info("Using poetry.lock file: %s", poetry_lock_file)
10891093
poetry_lock_target_file = copy_file_to_target(poetry_lock_file, temp_dir)
10901094
else:
10911095
poetry_lock_target_file = None
10921096

10931097
if os.path.isfile(poetry_toml_file):
1094-
log.info("Using poetry configuration file: %s", poetry_lock_file)
1098+
log.info("Using poetry.toml configuration file: %s", poetry_toml_file)
10951099
poetry_toml_target_file = copy_file_to_target(poetry_toml_file, temp_dir)
10961100
else:
10971101
poetry_toml_target_file = None

0 commit comments

Comments
 (0)