Skip to content

Require requirements#680

Merged
amol- merged 3 commits intomainfrom
require_requirements
Mar 3, 2026
Merged

Require requirements#680
amol- merged 3 commits intomainfrom
require_requirements

Conversation

@jonkeane
Copy link
Collaborator

@jonkeane jonkeane commented Jun 9, 2025

Intent

Require a requirements file by default, do not provide one. This is partially an idea to see how others feel about it. I would argue that we actually should remove the pip freeze fallback entirely, honestly. Possibly replacing it with https://github.com/bndr/pipreqs (or we could pull in the go code that the publisher uses).

Resolves #538

Type of Change

  • Bug Fix
  • New Feature
  • Breaking Change

Approach

Mostly Claude, actually

Automated Tests

Changed

Checklist

Will do at some point:

  • I have updated CHANGELOG.md to cover notable changes.
  • I have updated all related GitHub issues to reflect their current state.

@jonkeane jonkeane requested review from amol- and tdstein June 9, 2025 16:00
@github-actions
Copy link

github-actions bot commented Jun 9, 2025

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-03-03 14:58 UTC

@jonkeane jonkeane force-pushed the require_requirements branch from 61d8d73 to cbd2cf4 Compare June 10, 2025 12:30
@github-actions
Copy link

github-actions bot commented Jun 10, 2025

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
5433 4164 77% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
rsconnect/environment.py 90% 🟢
rsconnect/subprocesses/inspect_environment.py 88% 🟢
TOTAL 89% 🟢

updated for commit: 7681d26 by action🐍

@tdstein
Copy link
Collaborator

tdstein commented Jun 10, 2025

I agree that making requirements.txt generation explicit instead of implicit is the correct direction.

pipreqs looks like a suitable replacement for pip freeze. Our workflow implicitly assumes that the virtual environment is isolated to the project. I don't think that is a reasonable assumption to make.

@jonkeane jonkeane mentioned this pull request Dec 18, 2025
5 tasks
@amol- amol- self-assigned this Dec 18, 2025
amol-
amol- previously requested changes Mar 2, 2026
@amol- amol- force-pushed the require_requirements branch from cbd2cf4 to 4d6b2ea Compare March 3, 2026 10:41
@amol- amol- marked this pull request as draft March 3, 2026 10:52
@amol- amol- dismissed their stale review March 3, 2026 10:53

I took over the branch

@amol- amol- marked this pull request as ready for review March 3, 2026 10:55
@amol-
Copy link
Collaborator

amol- commented Mar 3, 2026

@jonkeane mind reviewing the changes when you have a chance?

Copy link
Collaborator Author

@jonkeane jonkeane left a comment

Choose a reason for hiding this comment

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

I can't literally approve because I opened the PR, but this should be treated as an approval (thanks, github).

We don't have to here, but I do think we should still consider the following separately

Possibly replacing it with https://github.com/bndr/pipreqs (or we could pull in the go code that the publisher uses).

Comment on lines 76 to +86
if requirements_file is None:
result = pip_freeze()
elif os.path.basename(requirements_file) == "uv.lock":
result = uv_export(dirname, requirements_file)
else:
result = output_file(dirname, requirements_file, "pip") or pip_freeze()
result = output_file(dirname, requirements_file, "pip")
if result is None:
raise EnvironmentException(
"The requirements file '%s' was not found in '%s'. "
"Please create it or use --force-generate to use pip freeze." % (requirements_file, dirname)
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This might be due to being away from this block for so long, but it took me a second to realize/remember that requirements_file here is just the name of the file, so that first if will only be false when it's literally passed as None (i.e. when someone passes --force-generate), and not when that file doesn't exist (that's lower down in the else).

I think this is fine, and maybe this comment is enough details in the git record, but it did take me a second to figure out how the code change here was even accomplishing what we wanted it to!

Copy link
Collaborator

Choose a reason for hiding this comment

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

The logic is more or less:

- requirements_file was requested -> use it and error if it doesn't exist
- requirements_file was not requested -> generate a new one (ie `--force-generate`)

Happy to improve the comment in any way you feel it might make this more obvious.
Maybe I can just add an explicit comment within the if block stating that --force-generate causes requirements_file to be None

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

block stating that --force-generate causes requirements_file to be None

Yeah, that would have helped me when I was reading

Copy link
Collaborator

@tdstein tdstein left a comment

Choose a reason for hiding this comment

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

Is there a simple way to make this use uv pip freeze if it's available?

@amol-
Copy link
Collaborator

amol- commented Mar 3, 2026

Is there a simple way to make this use uv pip freeze if it's available?

I guess so, is there any specific improvement you think that would provide?

Environments without pip are very uncommon as in most cases venv performs ensurepip on standard python builds so the case where you have uv and not pip sounds very uncommon.

Also the inspect process explicitly runs in a target python environment, so there isn't the need for uv environment autodetection for example.

Co-authored-by: Taylor Steinberg <taylor@steinberg.xyz>
@amol-
Copy link
Collaborator

amol- commented Mar 3, 2026

We don't have to here, but I do think we should still consider the following separately

Possibly replacing it with https://github.com/bndr/pipreqs (or we could pull in the go code that the publisher uses).

pipreqs is more or less in minimal maintenance mode and looking for a maintainer. Not sure how much we could rely on it on long term. Also pipreqs does not support qmd files which we currently support and for .ipynb it depends on jupyter nbconvert to be installed.
And I wasn't fond of its approach of keeping a manual list of standard library modules and a manual mapping of package_name->distribution_name, that's why I had started posit-dev/picopip#3 but had to pause it due to other priorities. I'll get back to that experiment as soon as I pop other things from my stack

@amol- amol- merged commit 323223d into main Mar 3, 2026
23 checks passed
@amol- amol- deleted the require_requirements branch March 3, 2026 14:58
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.

Require requirements.txt file

3 participants