Skip to content

Commit bb5b0aa

Browse files
authored
[poetry plugin] enable pyproject-dir to be configurable (#1567)
## Summary We can enable the poetry project to exist in a sub-directory of the devbox-project by allowing a user to set `DEVBOX_PYPROJECT_DIR`. Note, this only works if there is a _single_ poetry project in the devbox-project. For multiple poetry projects in a monorepo, I think users may need to define distinct devbox-projects. Fixes #1563 ## How was it tested? In the added example, ran `devbox run run_test`. Previously, this would fail. Also verified the default directory is the project dir, by removing the DEVBOX_PYPROJECT_DIR env-var, and seeing this error message: ``` examples/development/python/poetry/poetry-pyproject-subdir/service> devbox run run_test Poetry could not find a pyproject.toml file in /Users/savil/code/jetpack/devbox/examples/development/python/poetry/poetry-pyproject-subdir or its parents Error: error running script "run_test" in Devbox: exit status 1 ```
1 parent c694277 commit bb5b0aa

File tree

9 files changed

+215
-2
lines changed

9 files changed

+215
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Poetry in a monorepo
2+
3+
This example demonstrates using a poetry project in a sub-folder (`services` in this case)
4+
by specifying the `DEVBOX_PYPROJECT_DIR` that the poetry plugin can use.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"packages": [
3+
"poetry@latest",
4+
"python3@latest"
5+
],
6+
"env": {
7+
"DEVBOX_PYPROJECT_DIR": "$PWD/service"
8+
},
9+
"shell": {
10+
"init_hook": [
11+
"echo 'Welcome to devbox!' > /dev/null"
12+
],
13+
"scripts": {
14+
"install-service":[
15+
"cd service",
16+
"poetry install"
17+
],
18+
"run_test": [
19+
"devbox run install-service",
20+
"cd service && poetry run pytest"
21+
]
22+
}
23+
}
24+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"lockfile_version": "1",
3+
"packages": {
4+
"poetry@latest": {
5+
"last_modified": "2023-10-15T14:24:03Z",
6+
"plugin_version": "0.0.3",
7+
"resolved": "github:NixOS/nixpkgs/12bdeb01ff9e2d3917e6a44037ed7df6e6c3df9d#poetry",
8+
"source": "devbox-search",
9+
"version": "1.6.1",
10+
"systems": {
11+
"aarch64-darwin": {
12+
"store_path": "/nix/store/i7q6kxa3ac7c57zalr4vwa04c1bll3xd-python3.10-poetry-1.6.1"
13+
},
14+
"aarch64-linux": {
15+
"store_path": "/nix/store/7va0dmf3m4iswxfwrynp76290lcffzm1-python3.10-poetry-1.6.1"
16+
},
17+
"x86_64-darwin": {
18+
"store_path": "/nix/store/ymnfx9pbc4y9zp5rg8zcbxq3c14rhz1d-python3.10-poetry-1.6.1"
19+
},
20+
"x86_64-linux": {
21+
"store_path": "/nix/store/s2sqjwgm0h2ak2zvkvvbiw9fz4vsr5il-python3.10-poetry-1.6.1"
22+
}
23+
}
24+
},
25+
"python3@latest": {
26+
"last_modified": "2023-10-06T07:35:11Z",
27+
"plugin_version": "0.0.1",
28+
"resolved": "github:NixOS/nixpkgs/a2eb207f45e4a14a1e3019d9e3863d1e208e2295#python3",
29+
"source": "devbox-search",
30+
"version": "3.10.12",
31+
"systems": {
32+
"aarch64-darwin": {
33+
"store_path": "/nix/store/g5cm6iik6p4k39cj9k7a6sg2p09hl7wf-python3-3.10.12"
34+
},
35+
"aarch64-linux": {
36+
"store_path": "/nix/store/idpjrasbr9n8kij11s5mphrw770sf13s-python3-3.10.12"
37+
},
38+
"x86_64-darwin": {
39+
"store_path": "/nix/store/aa3nnkfyif67k6861vd77g4cm4rgbqh8-python3-3.10.12"
40+
},
41+
"x86_64-linux": {
42+
"store_path": "/nix/store/pzf6dnxg8gf04xazzjdwarm7s03cbrgz-python3-3.10.12"
43+
}
44+
}
45+
}
46+
}
47+
}

examples/development/python/poetry/poetry-pyproject-subdir/frontend/.empty

Whitespace-only changes.

examples/development/python/poetry/poetry-pyproject-subdir/service/poetry.lock

Lines changed: 115 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 = "poetry-pyproject-subdir-service"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["Savil Srivastava <[email protected]>"]
6+
7+
[tool.poetry.dependencies]
8+
python = "^3.8"
9+
emoji = "^2.1.0"
10+
11+
[tool.poetry.dev-dependencies]
12+
pytest = "^7.2.2"
13+
14+
[build-system]
15+
requires = ["poetry-core>=1.0.0"]
16+
build-backend = "poetry.core.masonry.api"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
def test_always_passes():
3+
assert True
4+
5+
#def test_always_fails():
6+
# assert False

plugins/poetry.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "poetry",
33
"version": "0.0.3",
4-
"readme": "This plugin automatically configures poetry to use the version of python installed in your Devbox shell, instead of the Python version that it is bundled with. Your pyproject.toml must be in the same directory as your devbox.json.",
4+
"readme": "This plugin automatically configures poetry to use the version of python installed in your Devbox shell, instead of the Python version that it is bundled with. The pyproject.toml location can be configured by setting DEVBOX_PYPROJECT_DIR (defaults to the devbox.json's directory).",
55
"env": {
6+
"DEVBOX_DEFAULT_PYPROJECT_DIR": "{{ .DevboxProjectDir }}",
67
"POETRY_VIRTUALENVS_IN_PROJECT": "true",
78
"POETRY_VIRTUALENVS_CREATE": "true",
89
"POETRY_VIRTUALENVS_PATH": "{{.Virtenv}}/.virtualenvs"

plugins/poetry/initHook.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22

3-
poetry env use $(command -v python) --no-interaction
3+
poetry env use $(command -v python) --directory="${DEVBOX_PYPROJECT_DIR:-$DEVBOX_DEFAULT_PYPROJECT_DIR}" --no-interaction
44

0 commit comments

Comments
 (0)