Skip to content

feat: select Python dependency sources consistently - #979

Open
tdstein wants to merge 5 commits into
mainfrom
symphony/posit-dev_rsconnect-python_975-1791be2534981672
Open

tdstein wants to merge 5 commits into
mainfrom
symphony/posit-dev_rsconnect-python_975-1791be2534981672

Conversation

@tdstein

@tdstein tdstein commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Every Python deploy and write-manifest command now picks its dependency source the same way:

resolve_requirements_file(directory)
  if --force-generate
    if --requirements-file  → error
    snapshot Content Python
  --requirements-file                      → use it
  [tool.posit.connect].requirements_file   → use it
  uv.lock                                  → validate + export offline (uv export --locked --offline)
  pyproject.toml with static [project].dependencies (empty list OK) → use it
  requirements.txt                         → use it
  otherwise                                → error

A selected source that's invalid fails the command. It never falls back to the next source.

Connect installs from a requirements-format package_file, so anything that isn't an unchanged requirements file is converted and written to requirements.txt, overwriting it with a warning:

write_environment_file
  if source is not an unchanged requirements file
    if requirements.txt exists
      warn: "Overwriting ./requirements.txt with requirements exported from uv.lock.
             The previous contents of this file will be lost. To deploy an existing
             requirements file unchanged, pass it with --requirements-file."
    write requirements.txt  # first line: "# Generated by rsconnect-python; overwritten on each manifest write."

warn_user now ends a pending Creating …... feedback line first, so warnings print on their own line.

Closes #975

Evidence

tests/test_dependency_selection.py runs every combination of requirements.txt × pyproject.toml × uv.lock, plus overrides, stale locks, and overwrite warnings:

  • Before: on main, these tests give 31 failed, 12 passed. For example, test_source_precedence[True-True-True] picks requirements.txt over uv.lock.
    After: all pass.

  • Overwrite warning:

    given requirements.txt = "user-owned"
    write-manifest api -g --overwrite
    → exit 0
    → output contains "Overwriting …/requirements.txt" and "previous contents of this file will be lost"
    → requirements.txt starts with "# Generated by rsconnect-python"
    
  • Full suite: 2,023 passed, 20 skipped. 8 failures in test_quickstart.py::test_quickstart_mode_file_set come from uv's cache (.cache/uv/…) landing in the sandboxed project directory; the requirements files match.

  • Ruff passes.

Merge Danger

Door: Two-way

The code reverts cleanly. But deployments made after this merges may already be running different pinned dependencies, and overwritten requirements.txt files are only recoverable from version control.

Blast Radius: Python deployments

  • A directory with both uv.lock and requirements.txt now deploys from uv.lock, and write-manifest overwrites requirements.txt with the export. Connect may install different package versions than before.
  • The same happens for a pyproject.toml with [project].dependencies next to a hand-written requirements.txt.
  • If requirements.txt is the configured source but rsconnect normalizes it (e.g. drops an rsconnect-python line), the file is rewritten with the normalized contents.
  • --force-generate together with --requirements-file is now an error. Previously the file was ignored with a warning.
  • A stale uv.lock fails the deploy and tells you to run uv lock. An unsupported lockfile (poetry.lock, Pipfile.lock, pdm.lock), a malformed requirements.txt, or an invalid [project].dependencies also fails.
  • A directory with no dependency source is now an error. Before, it failed later, when requirements.txt turned out to be missing.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
PR Preview Action v1.8.2

QR code for preview link

🚀 View preview at
https://posit-dev.github.io/rsconnect-python/pr-preview/pr-979/

Built to branch gh-pages at 2026-11-17 19:03 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

tdstein

This comment was marked as outdated.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
11389 10086 89% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
rsconnect/bundle.py 90% 🟢
rsconnect/environment.py 94% 🟢
rsconnect/log.py 76% 🟢
rsconnect/main.py 89% 🟢
rsconnect/pyproject.py 100% 🟢
rsconnect/subprocesses/inspect_environment.py 71% 🟢
TOTAL 87% 🟢

updated for commit: 827ac1b by action🐍

@tdstein tdstein changed the title Select Python dependency sources consistently feat: select Python dependency sources consistently Nov 16, 2026
@tdstein
tdstein requested review from amol- and joshyam-k November 16, 2026 18:26
Write generated requirements back to requirements.txt instead of
requirements-connect.txt, and warn before replacing an existing file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Evaluate Python dependency source precedence

1 participant