feat: add write_uv_constraints command to manage uv constraint-dependencies#537
Conversation
556a634 to
ea86ede
Compare
c93a5ab to
0622dd8
Compare
0622dd8 to
5d82dca
Compare
Switches constraint management from the bespoke sync_constraints.py script (which downloaded common_constraints.txt from GitHub via HTTP) to the new `edx_lint write_uv_constraints` command added in openedx/edx-lint#537. The new approach: - Uses the constraints bundled inside the installed edx-lint package, so no network call is needed at upgrade time - Merges repo-specific constraints from constraints.txt (replaces the greenlet pin that was hardcoded inside sync_constraints.py) - Local pins can override global ones by package name, which is useful when testing against a specific version - Writes a DO NOT EDIT comment block on first run and preserves it on subsequent runs The requirements/common_constraints.txt download cache is removed since the bundled copy inside edx-lint is now the authoritative source. Requires edx-lint >= next release (openedx/edx-lint#537). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
openedx/openedx-aspects#359 shows what the implementation of this would look like. |
bmtcril
left a comment
There was a problem hiding this comment.
Thanks for taking this on, it was definitely the worst missing piece of the initial uv stab. I just have the one non-blocking concern that we probably can't do anything about.
| with open(args.local, encoding="utf-8") as f: | ||
| local_text = f.read() | ||
| local_constraints, local_directives = _parse_constraints(local_text) | ||
| # Warn about pip directives (-c, -r, etc.) that are silently ignored. |
There was a problem hiding this comment.
I do have some concerns about this, since it would be a divergence from what we expect to happen? I think that the overall direction is to move away from these files eventually anyway, right?
There was a problem hiding this comment.
Yea, in an ideal world, we could reference global and local constraints directly in the pyproject.toml. Another alternative that I was considering is instead of adding a file here. We could add a new tool directive section to pyproject.toml for edx_lint so that we could add local constraints there instead and it would combine the local list with the global list. I opted for the constraints.txt file because it's where people would look to add this but thinking through it again, the tool directive might be a better option, the comment in the pyproject.toml points to the edx-lint section in the same file and because it's not a constraints.txt file, but a new directive, people will be less surprised by it having different capabilities.
What do you think of this alternative approach? Worth pursing? If so I can update the PRs to do that instead before we land it.
There was a problem hiding this comment.
Ooh, I think I like that better. If we're biting the bullet on this fairly major update that seems like the more future-proof solution
…cies from edx-lint Adds a new `edx_lint write_uv_constraints` command that merges the bundled global constraints from `edx_lint/files/common_constraints.txt` with optional repo-specific constraints from a local file, then writes the result into `[tool.uv].constraint-dependencies` in a `pyproject.toml`. This supports repos migrating from pip-compile to uv: `uv lock` has no `--constraint` CLI flag, so constraints must live in `pyproject.toml`. The list is fully machine-managed and should not be edited by hand; a prominent comment block is written above the key on first use to say so. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
5d82dca to
668880c
Compare
Switches constraint management from the bespoke sync_constraints.py script (which downloaded common_constraints.txt from GitHub via HTTP) to the new `edx_lint write_uv_constraints` command added in openedx/edx-lint#537. The new approach: - Uses the constraints bundled inside the installed edx-lint package, so no network call is needed at upgrade time - Merges repo-specific constraints from constraints.txt (replaces the greenlet pin that was hardcoded inside sync_constraints.py) - Local pins can override global ones by package name, which is useful when testing against a specific version - Writes a DO NOT EDIT comment block on first run and preserves it on subsequent runs The requirements/common_constraints.txt download cache is removed since the bundled copy inside edx-lint is now the authoritative source. Requires edx-lint >= next release (openedx/edx-lint#537). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
Adds a new
edx_lint write_uv_constraintscommand to support repos migrating frompip-compiletouv.The problem:
uv lockhas no--constraintCLI flag — version constraints must live in[tool.uv].constraint-dependenciesinsidepyproject.toml. Without tooling, every repo would need to copy-paste edx-lint's global constraints and keep them in sync manually.The solution: A command that:
edx_lint/files/common_constraints.txtconstraints.txtnext topyproject.toml)[tool.uv].constraint-dependencies, preserving all otherpyproject.tomlformatting and content viatomlkitUsage:
The
constraint-dependencieslist is fully machine-managed. Humans should never edit it directly — global changes go inedx_lint/files/common_constraints.txt, repo-specific pins go in a localconstraints.txt.Changes
edx_lint/cmd/write_uv_constraints.py— new command moduleedx_lint/cmd/main.py— register command in dispatcher and help outputrequirements/base.in— addtomlkitas a direct dependency (was already present as a transitive dep ofpylint)test/test_cmd.py— 10 new tests covering all key behavioursrequirements/*.txt— regenerated viamake upgrade