Skip to content
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

Add --target-version pyXX option to CLI #2857

Closed
kdeldycke opened this issue Feb 13, 2023 · 7 comments · Fixed by #2859
Closed

Add --target-version pyXX option to CLI #2857

kdeldycke opened this issue Feb 13, 2023 · 7 comments · Fixed by #2859

Comments

@kdeldycke
Copy link

kdeldycke commented Feb 13, 2023

This is a feature request to add a --target-version pyXX to ruff.

The idea is to mimick Black by allowing any subset of the following values:

  • --target-version py37
  • --target-version py38
  • --target-version py39
  • --target-version py310
  • --target-version py311
  • ...

With the idea that you should include all Python versions that you want your code to run under (as Black does).

This exact format is also what blacken-docs CLI supports.

On a practical level, this will help me a lot as I already generates these flags in my build pipeline for Black and blacken-docs. These are generated dynamically by inspecting the pyproject.toml of my projects.

@kdeldycke
Copy link
Author

For the record, this is adjacent to: #2039 and #2519

@charliermarsh
Copy link
Member

Hey thanks for filing! This exact API actually is available on the CLI, I just hid it by accident in a prior commit 🤦

@kdeldycke
Copy link
Author

Oh wow that's perfect! And incredibly fast!

I can test #2859 as soon as a release is publish.

@charliermarsh
Copy link
Member

It should actually work even with existing versions (ruff check /path/to/file.py --target-version py311), it just won't show up in --help. If you see otherwise, let me know!

@kdeldycke
Copy link
Author

kdeldycke commented Feb 13, 2023

Works indeed!

$ ruff --version
ruff 0.0.245

$ ruff check --fix-only --exit-zero --diff --target-version 311 ./.github/metadata.py
error: invalid value '311' for '--target-version <TARGET_VERSION>': Unknown version: 311 (try: "py37")

For more information, try '--help'.

$ ruff check --fix-only --exit-zero --diff --target-version py311 ./.github/metadata.py

No rush then to publish a new version of ruff.

Feel free to close this issue! :)

And thanks a lot for ruff, I played with it today and was able to get rid of iSort, Pyupgrade, Pylint, Pycln and Pydocstyle!

@charliermarsh
Copy link
Member

Amazing, thanks for giving Ruff a try :)

@kdeldycke
Copy link
Author

Just FYI, it doesn't supports multiple value yet, but that's a detail:

❯ ruff check --fix-only --exit-zero --target-version py38 --target-version py311 ./.github/metadata.py
error: the argument '--target-version <TARGET_VERSION>' cannot be used multiple times

Usage: ruff check [OPTIONS] [FILES]...

For more information, try '--help'.

kdeldycke added a commit to kdeldycke/workflows that referenced this issue Feb 14, 2023
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 a pull request may close this issue.

2 participants