Skip to content

Add --no-sync flag to avoid syncing the virtual environment (declare only)#1766

Closed
Copilot wants to merge 8 commits into
mainfrom
copilot/add-no-sync-flag-to-poetry
Closed

Add --no-sync flag to avoid syncing the virtual environment (declare only)#1766
Copilot wants to merge 8 commits into
mainfrom
copilot/add-no-sync-flag-to-poetry

Conversation

Copilot AI commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Adds a --no-sync CLI flag that declares/undeclares dependencies in pyproject.toml without touching the virtual environment. Analogous to uv add --no-sync.

When active, an instruction message tells the user to manually install/uninstall:

$ usethis tool ruff --no-sync
✔ Adding dependency 'ruff' to the 'lint' group in 'pyproject.toml'.
☐ Install the dependency 'ruff'.

Config & CLI

  • NO_SYNC_DEFAULT, no_sync field on UsethisConfig, wired through set() context manager
  • no_sync_opt typer option added to all 11 interface files that already support --frozen
  • --frozen and --no-sync can be used simultaneously; --frozen naturally takes precedence since it is strictly stronger (prevents both lockfile updates and syncing)

Backend subprocess wrappers

  • uv: passes --no-sync to uv add/uv remove; when both --frozen and --no-sync are set, --frozen takes precedence via the elif chain
  • poetry: passes --lock to poetry add/poetry remove

Dependency messaging (_deps.py)

  • add_deps_to_group: prints install instruction when no_sync (same pattern as frozen)
  • remove_deps_from_group: prints uninstall instruction when no_sync

Tests

  • call_uv_subprocess: --no-sync added for add/remove, --frozen precedence over --no-sync verified
  • call_poetry_subprocess: --lock added for add/remove, not added for other commands
  • add_deps_to_group / remove_deps_from_group: output messages verified with no_sync=True
  • UsethisConfig: TestFrozenAndNoSync validates both flags can be set simultaneously, and success when only one is set

Copilot AI and others added 3 commits April 2, 2026 02:54
…e only)

Add a --no-sync CLI flag that declares/undeclares dependencies in
pyproject.toml without syncing the virtual environment. For uv, this
passes --no-sync to uv add/remove. For poetry, this passes --lock to
poetry add/remove. When active, an instruction message is shown telling
the user to manually install/uninstall.

Resolves #1807

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/7348ebb6-400f-4e8e-b5aa-c25ea2f852c2

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Tests for call_uv_subprocess, call_poetry_subprocess, add_deps_to_group,
and remove_deps_from_group with no_sync=True.

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/7348ebb6-400f-4e8e-b5aa-c25ea2f852c2

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Make frozen precedence over no_sync explicit in the elif condition.
Add test for remove command with frozen precedence.

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/7348ebb6-400f-4e8e-b5aa-c25ea2f852c2

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
Copilot AI changed the title [WIP] Add --no-sync flag to poetry for dependency declaration Add --no-sync flag to avoid syncing the virtual environment (declare only) Apr 2, 2026
Copilot AI requested a review from nathanjmcdougall April 2, 2026 03:05
@nathanjmcdougall nathanjmcdougall marked this pull request as ready for review April 2, 2026 21:41
@codecov

codecov Bot commented Apr 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/usethis/_deps.py 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Apr 2, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 5.37%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 1 untouched benchmark

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation test_help_flag 53 ms 56.1 ms -5.37%

Comparing copilot/add-no-sync-flag-to-poetry (0ac0fbc) with main (f84d89d)

Open in CodSpeed

Comment thread src/usethis/_backend/uv/call.py Outdated
}:
new_args = ["uv", args[0], "--frozen", *args[1:]]
elif (
not usethis_config.frozen

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot we should add handle the case of BOTH --frozen and --no-sync...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7a4549a. UsethisConfig.set() now raises UsethisError("Cannot use both --frozen and --no-sync at the same time.") when both flags are True. Tests added in TestFrozenAndNoSync (test_config.py) and test_frozen_and_no_sync_raises (test_call.py).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot sorry, I don't understand why this would raise? Why not just accept both args simultaneously?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right — both flags can coexist since --frozen is strictly stronger. Removed the mutual exclusivity check in 816d50c. Now both are accepted simultaneously and --frozen naturally takes precedence via the elif chain in call_uv_subprocess.

Instead of silently having --frozen take precedence, raise a
UsethisError when both flags are set simultaneously. These flags
are mutually exclusive since --frozen prevents both lockfile updates
and syncing, while --no-sync only prevents syncing.

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/bbee573e-012b-4649-8923-7e4e46490fcf

Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
…precedence)

Remove the mutual exclusivity check that raised UsethisError when both
flags were set. Instead, both flags are accepted and --frozen naturally
takes precedence via the elif chain in call_uv_subprocess.

Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/dd1c1911-7c23-496d-a175-2fac1a83d0e4

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

Copy link
Copy Markdown
Collaborator

Not planned

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 a --no-sync flag to avoid installing/uninstalling the dependency (declare only)

2 participants