Skip to content

feat: add write_uv_constraints command to manage uv constraint-dependencies#537

Merged
feanil merged 2 commits into
masterfrom
feanil/sync_uv_constraints
Apr 27, 2026
Merged

feat: add write_uv_constraints command to manage uv constraint-dependencies#537
feanil merged 2 commits into
masterfrom
feanil/sync_uv_constraints

Conversation

@feanil

@feanil feanil commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a new edx_lint write_uv_constraints command to support repos migrating from pip-compile to uv.

The problem: uv lock has no --constraint CLI flag — version constraints must live in [tool.uv].constraint-dependencies inside pyproject.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:

  • Reads the bundled global constraints from edx_lint/files/common_constraints.txt
  • Optionally merges in repo-specific constraints from a local file (typically constraints.txt next to pyproject.toml)
  • Writes the merged list into [tool.uv].constraint-dependencies, preserving all other pyproject.toml formatting and content via tomlkit
  • Adds a prominent "DO NOT EDIT" comment above the key on first write
  • Is idempotent: running it twice produces the same result

Usage:

# Global constraints only
edx_lint write_uv_constraints

# Merge with repo-specific constraints
edx_lint write_uv_constraints pyproject.toml --local constraints.txt

The constraint-dependencies list is fully machine-managed. Humans should never edit it directly — global changes go in edx_lint/files/common_constraints.txt, repo-specific pins go in a local constraints.txt.

Changes

  • edx_lint/cmd/write_uv_constraints.py — new command module
  • edx_lint/cmd/main.py — register command in dispatcher and help output
  • requirements/base.in — add tomlkit as a direct dependency (was already present as a transitive dep of pylint)
  • test/test_cmd.py — 10 new tests covering all key behaviours
  • requirements/*.txt — regenerated via make upgrade

@feanil feanil force-pushed the feanil/sync_uv_constraints branch from 556a634 to ea86ede Compare April 23, 2026 16:24
Comment thread edx_lint/cmd/write_uv_constraints.py Outdated
Comment thread edx_lint/cmd/write_uv_constraints.py Outdated
@feanil feanil force-pushed the feanil/sync_uv_constraints branch 2 times, most recently from c93a5ab to 0622dd8 Compare April 23, 2026 16:44
@feanil feanil marked this pull request as ready for review April 23, 2026 16:53
@feanil feanil requested a review from bmtcril April 23, 2026 16:53
@feanil feanil force-pushed the feanil/sync_uv_constraints branch from 0622dd8 to 5d82dca Compare April 23, 2026 17:24
feanil added a commit to openedx/openedx-aspects that referenced this pull request Apr 23, 2026
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>
@feanil

feanil commented Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

openedx/openedx-aspects#359 shows what the implementation of this would look like.

@bmtcril bmtcril left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread edx_lint/cmd/write_uv_constraints.py Outdated
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

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.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

feanil and others added 2 commits April 27, 2026 09:55
…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>
@feanil feanil force-pushed the feanil/sync_uv_constraints branch from 5d82dca to 668880c Compare April 27, 2026 13:57
feanil added a commit to openedx/openedx-aspects that referenced this pull request Apr 27, 2026
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>
@feanil feanil merged commit c16ca9c into master Apr 27, 2026
5 checks passed
@feanil feanil deleted the feanil/sync_uv_constraints branch April 27, 2026 14:04
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.

2 participants