Skip to content

Handle --frozen flag for Poetry backend via lockfile backup/restore#1773

Merged
nathanjmcdougall merged 7 commits into
mainfrom
copilot/test-poetry-backend-frozen
Apr 3, 2026
Merged

Handle --frozen flag for Poetry backend via lockfile backup/restore#1773
nathanjmcdougall merged 7 commits into
mainfrom
copilot/test-poetry-backend-frozen

Conversation

Copilot AI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Poetry's CLI has no --frozen equivalent. When frozen=True, poetry add/remove were running unmodified—resolving, locking, and installing despite the user requesting frozen mode.

Changes

  • call_poetry_subprocess: When frozen=True and the command is add/remove, the function now (1) inserts --lock to skip installation, and (2) uses a _frozen_poetry_lock context manager to back up poetry.lock to a temp directory before the subprocess and restore it afterwards. This ensures pyproject.toml is updated while the lockfile remains truly frozen—even on subprocess failure.
  • _frozen_poetry_lock context manager: Encapsulates the backup/restore lifecycle for poetry.lock. If the lockfile exists beforehand it is backed up and restored on exit; if it did not exist, any lockfile created during the block is removed. The temp directory is always cleaned up.
  • _noop_context: No-op context manager used as a fallback when frozen mode is not applicable.
  • Tests: 8 unit tests on call_poetry_subprocess (frozen add/remove, non-applicable commands, frozen=False baseline, lockfile restore on success, lockfile restore on failure, lockfile removal when it didn't previously exist, temp directory cleanup) + 2 integration tests on add_deps_to_group/remove_deps_from_group with Poetry backend under frozen mode. 100% coverage on the changed module.
# Poetry doesn't support a --frozen flag like uv does. To emulate frozen
# behaviour we: (1) pass --lock to skip installation, (2) back up
# poetry.lock before the subprocess and restore it afterwards so the
# lockfile is never modified.
frozen_applicable = usethis_config.frozen and args[:1] in (["add"], ["remove"])
if frozen_applicable:
    args = [args[0], "--lock", *args[1:]]

Copilot AI and others added 2 commits April 2, 2026 21:59
Copilot AI changed the title [WIP] Test the poetry backend under --frozen and document handling Handle --frozen flag for Poetry backend via --lock Apr 2, 2026
Copilot AI requested a review from nathanjmcdougall April 2, 2026 22:03
@nathanjmcdougall

Copy link
Copy Markdown
Collaborator

This skips installation but still resolves and updates poetry.lock—an acceptable compromise since Poetry cannot update pyproject.toml without resolving.

@copilot this isn't an acceptable compromise. We should create a dedicated wrapper logic around the poetry subprocess to revert any changes to poetry.lock when --frozen is selected - i.e. force it to be frozen. We should backup the poetry.lock file to a temp directory before subprocessing in such a case

Copilot AI and others added 2 commits April 3, 2026 19:33

Copilot AI commented Apr 3, 2026

Copy link
Copy Markdown
Contributor Author

This skips installation but still resolves and updates poetry.lock—an acceptable compromise since Poetry cannot update pyproject.toml without resolving.

@copilot this isn't an acceptable compro...

Reworked in 6d1bc2c. Now call_poetry_subprocess backs up poetry.lock to a temp directory before the subprocess and restores it in a finally block afterwards. The lockfile is reverted even on subprocess failure. Also added --lock to skip the unnecessary installation step. Tests cover: restore on success, restore on failure, removal of newly-created lockfile, no-op when not frozen, and temp directory cleanup.

Copilot AI changed the title Handle --frozen flag for Poetry backend via --lock Handle --frozen flag for Poetry backend via lockfile backup/restore Apr 3, 2026
@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review April 3, 2026 20:37
@codecov

codecov Bot commented Apr 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Apr 3, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 2 untouched benchmarks


Comparing copilot/test-poetry-backend-frozen (508b798) with main (d6c172a)

Open in CodSpeed

Comment thread src/usethis/_backend/poetry/call.py Outdated
Copilot AI and others added 2 commits April 3, 2026 21:01
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/a31b7036-cb6c-42d0-8076-7c495da36035

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
@nathanjmcdougall nathanjmcdougall merged commit b6feafa into main Apr 3, 2026
20 checks passed
@nathanjmcdougall nathanjmcdougall deleted the copilot/test-poetry-backend-frozen branch April 3, 2026 23:36
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.

Test the poetry backend under --frozen

2 participants