From dd29f4b2cbee1fd6daab7067dc45ca3255b25d95 Mon Sep 17 00:00:00 2001 From: Savil Srivastava <676452+savil@users.noreply.github.com> Date: Tue, 17 Oct 2023 14:11:55 -0700 Subject: [PATCH 1/4] [poetry plugin] enable pyproject-dir to be configurable --- internal/plugin/plugin.go | 1 + plugins/poetry.json | 3 ++- plugins/poetry/initHook.sh | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/plugin/plugin.go b/internal/plugin/plugin.go index 68b0503a005..c5672380971 100644 --- a/internal/plugin/plugin.go +++ b/internal/plugin/plugin.go @@ -235,6 +235,7 @@ func buildConfig(pkg Includable, projectDir, content string) (*config, error) { "DevboxDir": filepath.Join(projectDir, devboxDirName, name), "DevboxDirRoot": filepath.Join(projectDir, devboxDirName), "DevboxProfileDefault": filepath.Join(projectDir, nix.ProfilePath), + "ProjectDir": projectDir, "Virtenv": filepath.Join(projectDir, VirtenvPath, name), }); err != nil { return nil, errors.WithStack(err) diff --git a/plugins/poetry.json b/plugins/poetry.json index c45784c6e6b..3282a68b56a 100644 --- a/plugins/poetry.json +++ b/plugins/poetry.json @@ -1,8 +1,9 @@ { "name": "poetry", "version": "0.0.3", - "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.", + "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).", "env": { + "DEVBOX_DEFAULT_PYPROJECT_DIR": "{{ .ProjectDir }}", "POETRY_VIRTUALENVS_IN_PROJECT": "true", "POETRY_VIRTUALENVS_CREATE": "true", "POETRY_VIRTUALENVS_PATH": "{{.Virtenv}}/.virtualenvs" diff --git a/plugins/poetry/initHook.sh b/plugins/poetry/initHook.sh index b01c5be40f2..9cdd7933995 100644 --- a/plugins/poetry/initHook.sh +++ b/plugins/poetry/initHook.sh @@ -1,4 +1,4 @@ #!/bin/sh -poetry env use $(command -v python) --no-interaction +poetry env use $(command -v python) --directory="${DEVBOX_PYPROJECT_DIR:-$DEVBOX_DEFAULT_PYPROJECT_DIR}" --no-interaction From 7a5621f4f30d68fba099205d894d87eb8075c652 Mon Sep 17 00:00:00 2001 From: Savil Srivastava <676452+savil@users.noreply.github.com> Date: Tue, 17 Oct 2023 14:27:23 -0700 Subject: [PATCH 2/4] add example project to illustrate --- .../poetry/poetry-pyproject-subdir/README.md | 4 + .../poetry-pyproject-subdir/devbox.json | 23 ++++ .../poetry-pyproject-subdir/devbox.lock | 47 +++++++ .../poetry-pyproject-subdir/frontend/.empty | 0 .../service/poetry.lock | 115 ++++++++++++++++++ .../service/pyproject.toml | 16 +++ .../service/test_with_pytest.py | 6 + 7 files changed, 211 insertions(+) create mode 100644 examples/development/python/poetry/poetry-pyproject-subdir/README.md create mode 100644 examples/development/python/poetry/poetry-pyproject-subdir/devbox.json create mode 100644 examples/development/python/poetry/poetry-pyproject-subdir/devbox.lock create mode 100644 examples/development/python/poetry/poetry-pyproject-subdir/frontend/.empty create mode 100644 examples/development/python/poetry/poetry-pyproject-subdir/service/poetry.lock create mode 100644 examples/development/python/poetry/poetry-pyproject-subdir/service/pyproject.toml create mode 100644 examples/development/python/poetry/poetry-pyproject-subdir/service/test_with_pytest.py diff --git a/examples/development/python/poetry/poetry-pyproject-subdir/README.md b/examples/development/python/poetry/poetry-pyproject-subdir/README.md new file mode 100644 index 00000000000..17e37ac7545 --- /dev/null +++ b/examples/development/python/poetry/poetry-pyproject-subdir/README.md @@ -0,0 +1,4 @@ +## Poetry in a monorepo + +This example demonstrates using a poetry project in a sub-folder (`services` in this case) +by specifying the `DEVBOX_PYPROJECT_DIR` that the poetry plugin can use. diff --git a/examples/development/python/poetry/poetry-pyproject-subdir/devbox.json b/examples/development/python/poetry/poetry-pyproject-subdir/devbox.json new file mode 100644 index 00000000000..5ef003c7b5d --- /dev/null +++ b/examples/development/python/poetry/poetry-pyproject-subdir/devbox.json @@ -0,0 +1,23 @@ +{ + "packages": [ + "poetry@latest", + "python3@latest" + ], + "env": { + "DEVBOX_PYPROJECT_DIR": "$PWD/service" + }, + "shell": { + "init_hook": [ + "echo 'Welcome to devbox!' > /dev/null" + ], + "scripts": { + "install-service":[ + "cd service", + "poetry install" + ], + "run_test": [ + "cd service && poetry run pytest" + ] + } + } +} diff --git a/examples/development/python/poetry/poetry-pyproject-subdir/devbox.lock b/examples/development/python/poetry/poetry-pyproject-subdir/devbox.lock new file mode 100644 index 00000000000..4d937b172b7 --- /dev/null +++ b/examples/development/python/poetry/poetry-pyproject-subdir/devbox.lock @@ -0,0 +1,47 @@ +{ + "lockfile_version": "1", + "packages": { + "poetry@latest": { + "last_modified": "2023-10-15T14:24:03Z", + "plugin_version": "0.0.3", + "resolved": "github:NixOS/nixpkgs/12bdeb01ff9e2d3917e6a44037ed7df6e6c3df9d#poetry", + "source": "devbox-search", + "version": "1.6.1", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/i7q6kxa3ac7c57zalr4vwa04c1bll3xd-python3.10-poetry-1.6.1" + }, + "aarch64-linux": { + "store_path": "/nix/store/7va0dmf3m4iswxfwrynp76290lcffzm1-python3.10-poetry-1.6.1" + }, + "x86_64-darwin": { + "store_path": "/nix/store/ymnfx9pbc4y9zp5rg8zcbxq3c14rhz1d-python3.10-poetry-1.6.1" + }, + "x86_64-linux": { + "store_path": "/nix/store/s2sqjwgm0h2ak2zvkvvbiw9fz4vsr5il-python3.10-poetry-1.6.1" + } + } + }, + "python3@latest": { + "last_modified": "2023-10-06T07:35:11Z", + "plugin_version": "0.0.1", + "resolved": "github:NixOS/nixpkgs/a2eb207f45e4a14a1e3019d9e3863d1e208e2295#python3", + "source": "devbox-search", + "version": "3.10.12", + "systems": { + "aarch64-darwin": { + "store_path": "/nix/store/g5cm6iik6p4k39cj9k7a6sg2p09hl7wf-python3-3.10.12" + }, + "aarch64-linux": { + "store_path": "/nix/store/idpjrasbr9n8kij11s5mphrw770sf13s-python3-3.10.12" + }, + "x86_64-darwin": { + "store_path": "/nix/store/aa3nnkfyif67k6861vd77g4cm4rgbqh8-python3-3.10.12" + }, + "x86_64-linux": { + "store_path": "/nix/store/pzf6dnxg8gf04xazzjdwarm7s03cbrgz-python3-3.10.12" + } + } + } + } +} diff --git a/examples/development/python/poetry/poetry-pyproject-subdir/frontend/.empty b/examples/development/python/poetry/poetry-pyproject-subdir/frontend/.empty new file mode 100644 index 00000000000..e69de29bb2d diff --git a/examples/development/python/poetry/poetry-pyproject-subdir/service/poetry.lock b/examples/development/python/poetry/poetry-pyproject-subdir/service/poetry.lock new file mode 100644 index 00000000000..3db023c7b9d --- /dev/null +++ b/examples/development/python/poetry/poetry-pyproject-subdir/service/poetry.lock @@ -0,0 +1,115 @@ +# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. + +[[package]] +name = "colorama" +version = "0.4.6" +description = "Cross-platform colored terminal text." +optional = false +python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "emoji" +version = "2.8.0" +description = "Emoji for Python" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +files = [ + {file = "emoji-2.8.0-py2.py3-none-any.whl", hash = "sha256:a8468fd836b7ecb6d1eac054c9a591701ce0ccd6c6f7779ad71b66f76664df90"}, + {file = "emoji-2.8.0.tar.gz", hash = "sha256:8d8b5dec3c507444b58890e598fc895fcec022b3f5acb49497c6ccc5208b8b00"}, +] + +[package.extras] +dev = ["coverage", "coveralls", "pytest"] + +[[package]] +name = "exceptiongroup" +version = "1.1.3" +description = "Backport of PEP 654 (exception groups)" +optional = false +python-versions = ">=3.7" +files = [ + {file = "exceptiongroup-1.1.3-py3-none-any.whl", hash = "sha256:343280667a4585d195ca1cf9cef84a4e178c4b6cf2274caef9859782b567d5e3"}, + {file = "exceptiongroup-1.1.3.tar.gz", hash = "sha256:097acd85d473d75af5bb98e41b61ff7fe35efe6675e4f9370ec6ec5126d160e9"}, +] + +[package.extras] +test = ["pytest (>=6)"] + +[[package]] +name = "iniconfig" +version = "2.0.0" +description = "brain-dead simple config-ini parsing" +optional = false +python-versions = ">=3.7" +files = [ + {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, + {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, +] + +[[package]] +name = "packaging" +version = "23.2" +description = "Core utilities for Python packages" +optional = false +python-versions = ">=3.7" +files = [ + {file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"}, + {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, +] + +[[package]] +name = "pluggy" +version = "1.3.0" +description = "plugin and hook calling mechanisms for python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pluggy-1.3.0-py3-none-any.whl", hash = "sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7"}, + {file = "pluggy-1.3.0.tar.gz", hash = "sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12"}, +] + +[package.extras] +dev = ["pre-commit", "tox"] +testing = ["pytest", "pytest-benchmark"] + +[[package]] +name = "pytest" +version = "7.4.2" +description = "pytest: simple powerful testing with Python" +optional = false +python-versions = ">=3.7" +files = [ + {file = "pytest-7.4.2-py3-none-any.whl", hash = "sha256:1d881c6124e08ff0a1bb75ba3ec0bfd8b5354a01c194ddd5a0a870a48d99b002"}, + {file = "pytest-7.4.2.tar.gz", hash = "sha256:a766259cfab564a2ad52cb1aae1b881a75c3eb7e34ca3779697c23ed47c47069"}, +] + +[package.dependencies] +colorama = {version = "*", markers = "sys_platform == \"win32\""} +exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} +iniconfig = "*" +packaging = "*" +pluggy = ">=0.12,<2.0" +tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} + +[package.extras] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"] + +[[package]] +name = "tomli" +version = "2.0.1" +description = "A lil' TOML parser" +optional = false +python-versions = ">=3.7" +files = [ + {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, + {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, +] + +[metadata] +lock-version = "2.0" +python-versions = "^3.8" +content-hash = "4bd7c2b783a03ead5ba2b81e78a1d22dc6278fd61be0fbf1fdb8467439bd6fd8" diff --git a/examples/development/python/poetry/poetry-pyproject-subdir/service/pyproject.toml b/examples/development/python/poetry/poetry-pyproject-subdir/service/pyproject.toml new file mode 100644 index 00000000000..b579a942b2e --- /dev/null +++ b/examples/development/python/poetry/poetry-pyproject-subdir/service/pyproject.toml @@ -0,0 +1,16 @@ +[tool.poetry] +name = "poetry-demo" +version = "0.1.0" +description = "" +authors = ["John Lago <750845+Lagoja@users.noreply.github.com>"] + +[tool.poetry.dependencies] +python = "^3.8" +emoji = "^2.1.0" + +[tool.poetry.dev-dependencies] +pytest = "^7.2.2" + +[build-system] +requires = ["poetry-core>=1.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/examples/development/python/poetry/poetry-pyproject-subdir/service/test_with_pytest.py b/examples/development/python/poetry/poetry-pyproject-subdir/service/test_with_pytest.py new file mode 100644 index 00000000000..a199017a71e --- /dev/null +++ b/examples/development/python/poetry/poetry-pyproject-subdir/service/test_with_pytest.py @@ -0,0 +1,6 @@ + +def test_always_passes(): + assert True + +#def test_always_fails(): +# assert False From 0f6ec379938093d618a545c6e3eccf593f3ebc6c Mon Sep 17 00:00:00 2001 From: Savil Srivastava <676452+savil@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:01:22 -0700 Subject: [PATCH 3/4] use DevboxProjectDir --- internal/plugin/plugin.go | 1 - plugins/poetry.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/plugin/plugin.go b/internal/plugin/plugin.go index c5672380971..68b0503a005 100644 --- a/internal/plugin/plugin.go +++ b/internal/plugin/plugin.go @@ -235,7 +235,6 @@ func buildConfig(pkg Includable, projectDir, content string) (*config, error) { "DevboxDir": filepath.Join(projectDir, devboxDirName, name), "DevboxDirRoot": filepath.Join(projectDir, devboxDirName), "DevboxProfileDefault": filepath.Join(projectDir, nix.ProfilePath), - "ProjectDir": projectDir, "Virtenv": filepath.Join(projectDir, VirtenvPath, name), }); err != nil { return nil, errors.WithStack(err) diff --git a/plugins/poetry.json b/plugins/poetry.json index 3282a68b56a..7e658b8bbea 100644 --- a/plugins/poetry.json +++ b/plugins/poetry.json @@ -3,7 +3,7 @@ "version": "0.0.3", "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).", "env": { - "DEVBOX_DEFAULT_PYPROJECT_DIR": "{{ .ProjectDir }}", + "DEVBOX_DEFAULT_PYPROJECT_DIR": "{{ .DevboxProjectDir }}", "POETRY_VIRTUALENVS_IN_PROJECT": "true", "POETRY_VIRTUALENVS_CREATE": "true", "POETRY_VIRTUALENVS_PATH": "{{.Virtenv}}/.virtualenvs" From 0b06e21e100b390ee877e96bf8187915c3a5e37b Mon Sep 17 00:00:00 2001 From: Savil Srivastava <676452+savil@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:14:58 -0700 Subject: [PATCH 4/4] ensure poetry install is run prior to pytest --- .../python/poetry/poetry-pyproject-subdir/devbox.json | 1 + .../poetry/poetry-pyproject-subdir/service/pyproject.toml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/development/python/poetry/poetry-pyproject-subdir/devbox.json b/examples/development/python/poetry/poetry-pyproject-subdir/devbox.json index 5ef003c7b5d..18966fbe677 100644 --- a/examples/development/python/poetry/poetry-pyproject-subdir/devbox.json +++ b/examples/development/python/poetry/poetry-pyproject-subdir/devbox.json @@ -16,6 +16,7 @@ "poetry install" ], "run_test": [ + "devbox run install-service", "cd service && poetry run pytest" ] } diff --git a/examples/development/python/poetry/poetry-pyproject-subdir/service/pyproject.toml b/examples/development/python/poetry/poetry-pyproject-subdir/service/pyproject.toml index b579a942b2e..201494bbab3 100644 --- a/examples/development/python/poetry/poetry-pyproject-subdir/service/pyproject.toml +++ b/examples/development/python/poetry/poetry-pyproject-subdir/service/pyproject.toml @@ -1,8 +1,8 @@ [tool.poetry] -name = "poetry-demo" +name = "poetry-pyproject-subdir-service" version = "0.1.0" description = "" -authors = ["John Lago <750845+Lagoja@users.noreply.github.com>"] +authors = ["Savil Srivastava <676452+savil@users.noreply.github.com>"] [tool.poetry.dependencies] python = "^3.8"