Skip to content

Add support for the poetry backend#1601

Merged
nathanjmcdougall merged 30 commits intomainfrom
copilot/add-support-for-poetry-backend
Apr 1, 2026
Merged

Add support for the poetry backend#1601
nathanjmcdougall merged 30 commits intomainfrom
copilot/add-support-for-poetry-backend

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 27, 2026

  • Add poetry to BackendEnum in _types/backend.py
  • Update inferred_backend type in _config.py
  • Create poetry backend infrastructure files
  • Update _backend/dispatch.py to return BackendEnum.poetry
  • Update all backend dispatch points (~30 locations across 13+ files)
  • Sync module tree documentation
  • Add poetry as a test dependency
  • Achieve 100% test coverage on new poetry backend code
  • Refactor duplicated pre-commit install functions into shared call_backend_subprocess / BackendSubprocessFailedError
  • Fix static check failures (PLR0912, ty type errors, basedpyright)
  • Improve test coverage to 95%+ on all changed files
  • Move duplicated _prepare_pyproject_write to shared _file/pyproject_toml/write.py
  • Remove backend parameter pass-throughs — internal functions use get_backend() from global config
  • Use call_uv_subprocess / call_poetry_subprocess directly in uninstall instead of generic dispatch
  • Fix poetry uninstall to handle missing pre-commit (try-first with temp add/remove fallback)
  • Fix poetry default groups — support optional = true configuration via [tool.poetry.group.GROUPNAME]
  • Make frozen-mode uninstall instructions backend-aware
  • Fix import-linter violation: refactor poetry uninstall to avoid _deps import from _integrations
  • Add docstrings to add_dep_to_group_via_poetry and remove_dep_from_group_via_poetry
  • Sync docs/functions.txt and AGENTS.md functions reference
  • Move --no-interaction before subcommand in call_poetry_subprocess() (Poetry global option ordering)
  • Frozen poetry uninstall instructs add/uninstall/remove pattern for pre-commit
  • Update docs/about/backends.md to document the poetry backend
  • Restructure poetry test classes into nested TestPoetry within existing test classes
  • Fix unused imports in _deps.py, sync doc references, fix basedpyright warnings in test_call.py
  • Fix poetry init to use bounded requires-python (>=3.X,<4.0) to prevent resolver failures
  • Poetry init now creates src/<pkg>/__init__.py, py.typed, and README.md matching uv's project structure
  • Support Poetry's custom dependency specification standard for reading deps
  • Detect poetry usage via poetry.toml presence (already in code/tests, updated docs)

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI and others added 4 commits March 27, 2026 10:48
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/baa09519-c675-414b-ae8d-5cb4103e962a

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/baa09519-c675-414b-ae8d-5cb4103e962a

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for the poetry backend Add support for the poetry backend Mar 27, 2026
Copilot AI requested a review from nathanjmcdougall March 27, 2026 11:08
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 95.83333% with 15 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/usethis/_integrations/pre_commit/core.py 90.47% 6 Missing ⚠️
src/usethis/_file/pyproject_toml/deps.py 90.24% 4 Missing ⚠️
src/usethis/_deps.py 97.05% 2 Missing ⚠️
src/usethis/_tool/impl/base/ruff.py 84.61% 2 Missing ⚠️
src/usethis/_tool/impl/base/requirements_txt.py 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 27, 2026

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing copilot/add-support-for-poetry-backend (a271da7) with main (cb84b07)

Open in CodSpeed

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

@copilot there is a lot of test coverage missing. please aim for 100% code coverage on the new code.

Please make sure to add poetry as a test dependency so that it can be used in the test suite.

Comment thread src/usethis/_integrations/pre_commit/core.py Outdated
…y backend

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/0eab9e13-33e4-4646-90c9-93dc238b1830

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 27, 2026

@copilot there is a lot of test coverage missing. please aim for 100% code coverage on the new code.

Please make sure to add poetry as a test dependency so that it can be used in th...

Added poetry as a test dependency and wrote comprehensive tests achieving 100% code coverage on all new poetry backend modules (available.py, call.py, deps.py, detect.py, errors.py, init.py). Tests cover all branches including error handling, verbose mode, subprocess failures, FileNotFoundError, and API compatibility parameters. See commit e6e5ec6.

…s to deduplicate pre-commit install functions

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/468e006f-e4cb-4f88-9126-9e0bf30067af

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

@copilot try testing the user experience again - this time be more rigorous to stay on the happy path

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/155a4a8e-7612-4058-b5d9-62e8201e77d2

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 1, 2026

@copilot try testing the user experience again - this time be more rigorous to stay on the happy path

Applied rigorous user testing following the usethis-cli-user-test skill procedure from fresh temp directories. Discovered and fixed a critical issue in b915d51:

Bug found: usethis init --backend=poetry failed at poetry add deptry because Poetry's poetry init generates unbounded requires-python = ">=3.10", which conflicts with its own resolver when packages depend on Python <4.0.

Fix: opinionated_poetry_init() and ensure_pyproject_toml_via_poetry() now pass --python ">=3.X,<4.0" to poetry init, producing a bounded constraint that the resolver can handle.

All happy-path commands verified in fresh projects:

  • usethis init --backend=poetry — all tools added successfully (exit 0)
  • usethis tool ruff --remove --backend=poetry — removes deps and config
  • usethis tool ruff --backend=poetry — re-adds with correct poetry run instructions
  • usethis tool pre-commit --backend=poetry — adds hooks, runs install
  • usethis tool pre-commit --remove --backend=poetry — uninstalls hooks
  • usethis tool pre-commit --remove --frozen --backend=poetry — shows 3-step add/uninstall/remove instructions
  • usethis tool ty --frozen --backend=poetry — frozen mode prints install instruction
  • usethis show backend — auto-detects "poetry"
  • usethis show name / usethis list — work correctly

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

@copilot I noticed during my testing that the usethis init --backend=poetry command will not create a src directory with the package name automatically. I would expect the same kind of directory to be generated automatically as what gets generated by uv

E.g. for a package named fawgaw that we get

src / fawgaw / __init__.py with the body

def hello() -> str:
    return "Hello from fawgaw!"

And src / fawgaw / py.typed (single blank line) as well. Compare with usethis init --backend=uv for reference.

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/6c00df21-6aba-4ba3-b75f-245867fdaaa5

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 1, 2026

@copilot I noticed during my testing that the usethis init --backend=poetry command will not create a src directory with the package name automatically. I would expect the same kind of directory t...

Fixed in 95ce142. project_init() now calls _create_project_structure() after opinionated_poetry_init(), which creates README.md, src/<pkg>/__init__.py (with the hello function), and src/<pkg>/py.typed — matching the same structure that uv init --lib generates. The duplicated logic from the none backend was extracted into the shared _create_project_structure() helper.

Verified via user testing in a fresh temp dir: usethis init --backend=poetry now produces the full project structure.

Copy link
Copy Markdown
Collaborator

@nathanjmcdougall nathanjmcdougall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot we've got a big gap at the moment - we're not supporting poetry's custom dependency specification standard

Read about it here:
https://python-poetry.org/docs/dependency-specification/

We need to support this for determining/interactive with deps & dev deps, etc.

Add reading from [tool.poetry.dependencies] and
[tool.poetry.group.*.dependencies] sections when the poetry backend
is active. Sync docs/functions.txt and AGENTS.md.

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/f5887a53-6698-4d40-b8b6-e38f81ac0dde

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 1, 2026

@copilot we've got a big gap at the moment - we're not supporting poetry's custom dependency specification standard

Read about it here:...

Fixed in 95247f5. Added support for reading Poetry's custom dependency specification from [tool.poetry.dependencies] and [tool.poetry.group.*.dependencies] sections.

When the poetry backend is active, get_project_deps() and get_dep_groups() now merge results from both standard (PEP 621/PEP 735) and Poetry-format sections. The parser handles:

  • Simple version strings: requests = "^2.28"
  • Dict specs with extras: requests = {version = "^2.28", extras = ["security"]}
  • Git/path/URL deps (name extracted from key)
  • python key excluded automatically

This means is_dep_in_any_group() and all dependency detection now works correctly for legacy Poetry projects.

@nathanjmcdougall
Copy link
Copy Markdown
Collaborator

@copilot also add support for detecting poetry usage via poetry.toml's presence

see

https://python-poetry.org/docs/main/configuration#installerbuild-config-settingspackage-name

…ackends.md

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/6ad57cf4-0b2b-4914-860c-5fd63fa07256

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 1, 2026

@copilot also add support for detecting poetry usage via poetry.toml's presence

see
...

Detection via poetry.toml was already implemented in is_poetry_used() (along with poetry.lock and [tool.poetry] in pyproject.toml), with a dedicated test in test_detect.py::TestIsPoetryUsed::test_poetry_toml. Updated the docs/about/backends.md documentation in 5e4286d to explicitly list all three detection methods.

@nathanjmcdougall nathanjmcdougall merged commit 76eba9d into main Apr 1, 2026
20 checks passed
@nathanjmcdougall nathanjmcdougall deleted the copilot/add-support-for-poetry-backend branch April 1, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for the poetry backend

3 participants