-
Notifications
You must be signed in to change notification settings - Fork 5
Add support for the poetry backend
#1601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nathanjmcdougall
merged 30 commits into
main
from
copilot/add-support-for-poetry-backend
Apr 1, 2026
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
72db384
Initial plan
Copilot cfcdb9a
Add poetry backend infrastructure and update all backend dispatch points
Copilot 61b2211
Add poetry backend tests and update dispatch test
Copilot 03ff9ad
Fix lint errors, type errors, and sync module tree docs
Copilot 330a98c
Address code review: fix poetry init cwd and author param handling
Copilot e6e5ec6
Add poetry as test dependency and achieve 100% test coverage on poetr…
Copilot 577c86c
Refactor: add BackendSubprocessFailedError and call_backend_subproces…
Copilot db2ae05
Merge branch 'main' into copilot/add-support-for-poetry-backend
nathanjmcdougall 1682f3e
Merge branch 'main' into copilot/add-support-for-poetry-backend
nathanjmcdougall 30ed70b
Fix static check failures: PLR0912 in use_requirements_txt, ty type e…
Copilot b209c45
Merge branch 'main' into copilot/add-support-for-poetry-backend
nathanjmcdougall 4a17032
Fix basedpyright error: handle BackendEnum.poetry in requirements_txt…
Copilot 33a50b8
Add poetry backend test coverage for all uncovered branches
Copilot 8e32839
Address PR review: shared _prepare_pyproject_write, remove backend pa…
Copilot 0382de0
Fix ruff lint errors: move imports to top level, fix SIM117 and EM101…
Copilot abc83d0
Merge branch 'main' into copilot/add-support-for-poetry-backend
nathanjmcdougall 9e46c39
Fix static checks: add docstrings to poetry deps, fix import-linter v…
Copilot 3824ea0
Merge branch 'main' into copilot/add-support-for-poetry-backend
nathanjmcdougall c94a28a
Address review: move --no-interaction, update docs, restructure tests…
Copilot a19e0af
Merge branch 'main' into copilot/add-support-for-poetry-backend
nathanjmcdougall 9a8bb50
Fix static checks: unused imports, doc sync, basedpyright warnings
Copilot 515278f
Merge branch 'main' into copilot/add-support-for-poetry-backend
nathanjmcdougall 1596a69
Merge branch 'main' into copilot/add-support-for-poetry-backend
nathanjmcdougall 7ada779
Run ruff format
nathanjmcdougall 3d30db2
Merge branch 'main' into copilot/add-support-for-poetry-backend
nathanjmcdougall b915d51
Fix import ordering in test_init.py
Copilot 95ce142
Fix ruff formatting in test_init.py
Copilot 95247f5
Support Poetry's custom dependency specification format
Copilot 5e4286d
docs: mention poetry.toml and [tool.poetry] as detection methods in b…
Copilot a271da7
Merge branch 'main' into copilot/add-support-for-poetry-backend
nathanjmcdougall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| """Check whether the Poetry CLI is available.""" | ||
|
|
||
| from usethis._backend.poetry.call import call_poetry_subprocess | ||
| from usethis._backend.poetry.errors import PoetrySubprocessFailedError | ||
|
|
||
|
|
||
| def is_poetry_available() -> bool: | ||
| """Check if the `poetry` command is available in the current environment.""" | ||
| try: | ||
| call_poetry_subprocess(["--version"], change_toml=False) | ||
| except PoetrySubprocessFailedError: | ||
| return False | ||
|
|
||
| return True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| """Subprocess wrappers for invoking Poetry commands.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from usethis._backend.poetry.errors import PoetrySubprocessFailedError | ||
| from usethis._config import usethis_config | ||
| from usethis._file.pyproject_toml.io_ import PyprojectTOMLManager | ||
| from usethis._file.pyproject_toml.write import prepare_pyproject_write | ||
| from usethis._subprocess import SubprocessFailedError, call_subprocess | ||
| from usethis._types.backend import BackendEnum | ||
| from usethis.errors import ForbiddenBackendError | ||
|
|
||
|
|
||
| def call_poetry_subprocess(args: list[str], *, change_toml: bool) -> str: | ||
| """Run a subprocess using the Poetry command-line tool. | ||
|
|
||
| Returns: | ||
| str: The output of the subprocess. | ||
|
|
||
| Raises: | ||
| PoetrySubprocessFailedError: If the subprocess fails. | ||
| ForbiddenBackendError: If the current backend is not poetry (or auto). | ||
| """ | ||
| if usethis_config.backend not in {BackendEnum.poetry, BackendEnum.auto}: | ||
| msg = f"The '{usethis_config.backend.value}' backend is enabled, but a Poetry subprocess was invoked." | ||
| raise ForbiddenBackendError(msg) | ||
|
|
||
| if change_toml: | ||
| prepare_pyproject_write() | ||
|
|
||
| new_args = ["poetry", "--no-interaction", *args] | ||
|
|
||
| if usethis_config.subprocess_verbose: | ||
| new_args = [*new_args[:1], "-vvv", *new_args[1:]] | ||
| elif args[:1] != ["--version"]: | ||
| new_args = [*new_args[:1], "--quiet", *new_args[1:]] | ||
|
|
||
| try: | ||
| output = call_subprocess(new_args, cwd=usethis_config.cpd()) | ||
| except SubprocessFailedError as err: | ||
| raise PoetrySubprocessFailedError(err) from None | ||
| except FileNotFoundError: | ||
| msg = "Poetry is not installed or not found on PATH." | ||
| raise PoetrySubprocessFailedError(msg) from None | ||
|
|
||
| if change_toml and PyprojectTOMLManager().is_locked(): | ||
| PyprojectTOMLManager().read_file() | ||
|
|
||
| return output |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.