rye icon indicating copy to clipboard operation
rye copied to clipboard

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

Open linjer opened this issue 1 year ago • 4 comments

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.

linjer avatar Apr 23 '24 11:04 linjer

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

asmith26 avatar Jun 06 '24 16:06 asmith26

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:

  • rye lint: runs Ruff
  • rye run lint: runs the above scripts

jamesbraza avatar Jul 20 '24 23:07 jamesbraza

@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.

linjer avatar Jul 23 '24 17:07 linjer

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

jamesbraza avatar Jul 23 '24 17:07 jamesbraza