astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
13.79k stars 468 forks source link

Ability to easily chain built-in rye commands, e.g., `rye lint` #1036

Open linjer opened 6 months ago

linjer commented 6 months ago

Currently interested in chaining or extending the rye lint command to also perform typechecking. For example:

[tool.rye.scripts]
typecheck = "mypy mymodule"
check = { chain = ["rye lint", "typecheck"] }
linter = "lint"  # also fails

This seems to fail because rye is not available in the environment. I also could not find any documentation on if I could customize the lint command.

Suggestion

Make rye native commands accessible to scripts.

asmith26 commented 4 months ago

I would also find this helpful. An initial work around:

  1. Install ruff rye add --dev ruff
  2. Add to pyproject.toml
    [tool.rye.scripts]
    check-lint = "ruff check"

Related https://github.com/astral-sh/rye/discussions/1142

jamesbraza commented 3 months ago

Does chain do what you need? https://rye.astral.sh/guide/pyproject/#chain

# pyproject.toml

[tool.rye.scripts]
lint = { chain = ["lint:black", "lint:flake8"] }
"lint:black" = "black --check src"
"lint:flake8" = "flake8 src"

Then:

linjer commented 3 months ago

@jamesbraza I want to keep the rye lint command that runs ruff, but also run mypy, and allow people to continue using rye lint in their workflows.

Are you suggesting a workaround where I redefine what rye lint does in a new command (e.g., lint:ruff) that can be chained? This is how I understood asmith26's suggestion.

jamesbraza commented 3 months ago

Oh @linjer thanks for following up. Yeah your ideal was basically overriding rye lint such that rye lint runs Ruff, mypy, and possibly other tools. I like your request, it makes sense.

You're correct that my comment didn't resolve that directly, it instead adds an additional script called lint (invoked via rye run lint) that calls other tools