Skip to content

Commit

Permalink
Poetry plugin (jetify-com#1343)
Browse files Browse the repository at this point in the history
## Summary

Builtin plugin for Poetry that configures it to use the installed
version of python, instead of the one that Poetry is built with

This also sets some environment variables that create the poetry
virtualenv inside the project

## How was it tested?

Tested using the example project, also in this PR. Run `poetry env info`
to confirm it's using the right version of Poetry
  • Loading branch information
Lagoja authored Aug 3, 2023
1 parent 02e522e commit eba7998
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion examples/cloud_development/temporal/devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"shell": {
"init_hook": [
"echo 'Setting flags to allow Python C extension compilation'",
"export NIX_CFLAGS_COMPILE=\"$NIX_CFLAGS_COMPILE $(cat $(dirname $(which clang))/../nix-support/libcxx-cxxflags)\"",
"export NIX_CFLAGS_COMPILE=\"$NIX_CFLAGS_COMPILE $(cat $(dirname $(command -v clang))/../nix-support/libcxx-cxxflags)\"",
"echo 'Setting up virtual environment'",
"source $VENV_DIR/bin/activate"
],
Expand Down
2 changes: 1 addition & 1 deletion examples/development/python/poetry/poetry-demo/devbox.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages": [
"python@3.10",
"python@3.8",
"poetry@1.4"
],
"shell": {
Expand Down
22 changes: 13 additions & 9 deletions examples/development/python/poetry/poetry-demo/devbox.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
{
"lockfile_version": "1",
"packages": {
"poetry": {
"last_modified": "",
"resolved": "github:NixOS/nixpkgs/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62#poetry",
"version": ""
"poetry@1.4": {
"last_modified": "2023-05-19T19:44:39Z",
"plugin_version": "0.0.1",
"resolved": "github:NixOS/nixpkgs/4a22f6f0a4b4354778f786425babce9a56f6b5d8#poetry",
"source": "devbox-search",
"version": "1.4.2"
},
"python310": {
"last_modified": "",
"resolved": "github:NixOS/nixpkgs/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62#python310",
"version": ""
"python@3.8": {
"last_modified": "2023-06-30T04:44:22Z",
"plugin_version": "0.0.1",
"resolved": "github:NixOS/nixpkgs/3c614fbc76fc152f3e1bc4b2263da6d90adf80fb#python38",
"source": "devbox-search",
"version": "3.8.17"
}
}
}
}
58 changes: 19 additions & 39 deletions examples/development/python/poetry/poetry-demo/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = ""
authors = ["John Lago <750845+Lagoja@users.noreply.github.com>"]

[tool.poetry.dependencies]
python = "^3.10"
python = "^3.8"
emoji = "^2.1.0"

[tool.poetry.dev-dependencies]
Expand Down
1 change: 1 addition & 0 deletions plugins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var builtInMap = map[*regexp.Regexp]string{
regexp.MustCompile(`^mysql?[0-9]*$`): "mysql",
regexp.MustCompile(`^php[0-9]*$`): "php",
regexp.MustCompile(`^python3[0-9]*Packages.pip$`): "pip",
regexp.MustCompile(`^(\w*\.)?poetry$`): "poetry",
regexp.MustCompile(`^postgresql(_[0-9]+)?$`): "postgresql",
regexp.MustCompile(`^python[0-9]*(Full|Minimal|-full|-minimal)?$`): "python",
regexp.MustCompile(`^redis$`): "redis",
Expand Down
15 changes: 15 additions & 0 deletions plugins/poetry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "poetry",
"version": "0.0.1",
"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.",
"env": {
"POETRY_VIRTUALENVS_IN_PROJECT": "true",
"POETRY_VIRTUALENVS_CREATE": "true",
"POETRY_VIRTUALENVS_PATH": "{{.Virtenv}}/.virtualenvs"
},
"shell": {
"init_hook": [
"poetry env use $(command -v python) --quiet --no-interaction"
]
}
}

0 comments on commit eba7998

Please sign in to comment.