Skip to content

Use uv run for lintrunner Python deps #159735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ezyang
Copy link
Contributor

@ezyang ezyang commented Aug 3, 2025

I asked Codex to whip up the proof of concept. The idea is to make use of uv's anonymous venvs instead of forcing everything to be installed in the current venv, which is helpful when you are working on multiple projects which have different pins for various formatting tools (hi autoparallel). If people like the idea I'll clean it up and land it.

Summary

  • use uv run in lintrunner config to invoke Python linters without a prior lintrunner init
  • declare per-script dependencies via inline metadata so uv installs them on demand
  • clean up ShellCheck adapter message now that lintrunner init is not required
  • mention uv run in fallback messages when lintrunner or shellcheck are missing

Testing

  • lintrunner tools/linter/adapters/no_workflows_on_fork.py tools/linter/adapters/workflow_consistency_linter.py (fails: Failed to fetch https://pypi.org/simple/ruff/)

https://chatgpt.com/codex/tasks/task_e_688f81faeae48323a3aa0c7ac1cd452c

@ezyang ezyang added the codex label Aug 3, 2025 — with ChatGPT Connector
Copy link

pytorch-bot bot commented Aug 3, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/159735

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures, 1 Unrelated Failure

As of commit 8d6f51f with merge base 9a680e1 (image):

NEW FAILURES - The following jobs have failed:

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added the topic: not user facing topic category label Aug 3, 2025
@ezyang ezyang requested a review from malfet August 3, 2025 20:24
@@ -1,3 +1,9 @@
# /// script
# dependencies = [
# "cmakelint==1.4.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't audited Codex didn't mess up putting in the deps, if we agree the approach is good I will audit these

@@ -24,7 +31,7 @@
from pathlib import Path
from typing import Any, Callable, NamedTuple, Optional

from yaml import load
import yaml # type: ignore[import-untyped]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll revert these changes if we agree to do it this way

@albanD
Copy link
Collaborator

albanD commented Aug 4, 2025

@ZainRizvi merged https://github.com/pytorch/pytorch/blob/main/scripts/run_lintrunner.py to do this via github hooks by having lintrunner as a tool rather than changing each one.
No strong opinion here.

@ezyang ezyang requested a review from ZainRizvi August 5, 2025 14:13
@ezyang
Copy link
Contributor Author

ezyang commented Aug 5, 2025

@ZainRizvi I read through #158389 and I don't really understand the approach. It seems you are installing the lintrunner deps into the venv that uv allocates for the tool itself. But this is wrong: what if I want to use lintrunner on a different repo? You need a separate venv PER project, not just one attached to lintrunner itself!

@ZainRizvi
Copy link
Contributor

ZainRizvi commented Aug 11, 2025

@ZainRizvi I read through #158389 and I don't really understand the approach. It seems you are installing the lintrunner deps into the venv that uv allocates for the tool itself. But this is wrong: what if I want to use lintrunner on a different repo? You need a separate venv PER project, not just one attached to lintrunner itself!

@ezyang that's not what the #158389 did. The pre-commit pip package creates a separate venv to use for the hook for each repo. That's the env the lintrunner deps are being installed into, not into a universal lintrunner environment. Every repo would get it's own venv. (#160048 does that more clearly)

That said, the goal of that PR was to setup reliable pre-push hooks, and getting a consistent lintrunner environment was incidental. If this PR works out we can easily update the pre-push hooks script to take advantage of this new setup instead.

Copy link
Contributor

@ZainRizvi ZainRizvi left a comment

Choose a reason for hiding this comment

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

I really like the auto-updating aspect of this so that there's no dependency on the currently active venv.

It would be even better if the uv also fixes the python version everything gets run using (today CI runs lintrunner using python 3.9, that would be the best one to match)

Some linter failures only manifest in specific python versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants