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

feat: add ruff format command #16

Merged
merged 1 commit into from
Oct 25, 2023
Merged

feat: add ruff format command #16

merged 1 commit into from
Oct 25, 2023

Conversation

kwigley
Copy link
Contributor

@kwigley kwigley commented Oct 25, 2023

No description provided.

Copy link
Owner

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

It seems some options are not valid, like no_cache. They don't appear in the help message, and Ruff does not recognize them.

% ruff format --help
Run the Ruff formatter on the given files or directories

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

Arguments:
  [FILES]...  List of files or directories to format

Options:
      --check            Avoid writing any formatted files back; instead, exit with a non-zero status code if any files would have been modified, and zero otherwise
      --config <CONFIG>  Path to the `pyproject.toml` or `ruff.toml` file to use for configuration
  -h, --help             Print help

File selection:
      --respect-gitignore  Respect file exclusions via `.gitignore` and other standard ignore files. Use `--no-respect-gitignore` to disable
      --force-exclude      Enforce exclusions, even for paths passed to Ruff directly on the command-line. Use `--no-force-exclude` to disable

Miscellaneous:
      --isolated                         Ignore all configuration files
      --stdin-filename <STDIN_FILENAME>  The name of the file when passing it through stdin

Log levels:
  -v, --verbose  Enable verbose logging
  -q, --quiet    Print diagnostics, but nothing else
  -s, --silent   Disable all logging (but still exit with status code "1" upon detecting diagnostics)
% ruff format --no-cache
error: unexpected argument '--no-cache' found

  tip: to pass '--no-cache' as a value, use '-- --no-cache'

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

For more information, try '--help'.

Could you remove the unsupported options?


Could you also revert all the unrelated style changes? You probably have your editor configured to auto-format code with a line length of 80. Try to disable that in the project before amending your commit.

@kwigley
Copy link
Contributor Author

kwigley commented Oct 25, 2023

hmm, what you're seeing is likely due to version differences in ruff. When using the latest version (0.1.2), it supports the no-cache arg. Should I update to handle a specific version of the tool, support the common args for various versions, or add bunch logic to handle different ruff versions?

ruff format -h # v0.1.2
Run the Ruff formatter on the given files or directories

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

Arguments:
  [FILES]...  List of files or directories to format

Options:
      --check
          Avoid writing any formatted files back; instead, exit with a non-zero status code if any files would have been modified, and zero otherwise
      --diff
          Avoid writing any formatted files back; instead, exit with a non-zero status code and the difference between the current file and how the formatted file would look like
      --config <CONFIG>
          Path to the `pyproject.toml` or `ruff.toml` file to use for configuration
      --target-version <TARGET_VERSION>
          The minimum Python version that should be supported [possible values: py37, py38, py39, py310, py311, py312]
      --preview
          Enable preview mode; enables unstable formatting. Use `--no-preview` to disable
  -h, --help
          Print help

Miscellaneous:
  -n, --no-cache                         Disable cache reads
      --cache-dir <CACHE_DIR>            Path to the cache directory [env: RUFF_CACHE_DIR=]
      --isolated                         Ignore all configuration files
      --stdin-filename <STDIN_FILENAME>  The name of the file when passing it through stdin

File selection:
      --respect-gitignore       Respect file exclusions via `.gitignore` and other standard ignore files. Use `--no-respect-gitignore` to disable
      --exclude <FILE_PATTERN>  List of paths, used to omit files and/or directories from analysis
      --force-exclude           Enforce exclusions, even for paths passed to Ruff directly on the command-line. Use `--no-force-exclude` to disable

Log levels:
  -v, --verbose  Enable verbose logging
  -q, --quiet    Print diagnostics, but nothing else
  -s, --silent   Disable all logging (but still exit with status code "1" upon detecting diagnostics)

also, my bad on the formatting! will fix

Copy link
Owner

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

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

hmm, what you're seeing is likely due to version differences in ruff. When using the latest version (0.1.2), it supports the no-cache arg. Should I update to handle a specific version of the tool, support the common args for various versions, or add bunch logic to handle different ruff versions?

Ah, you're right, my bad! I had installed ruff in the current venv but did not think of running hash -r, so typing ruff actually called my pipx version. It's weird though because my pipx version says:

% ruff format
warning: `ruff format` is a work-in-progress, subject to change at any time, and intended only for experimentation.
ruff failed
  Cause: Expected at least one path to search for Python files

Not sure how I got a mix of the previous and new version 🤯

Anyway, good to go now, thanks a lot!

@pawamoy
Copy link
Owner

pawamoy commented Oct 25, 2023

OK, quality and Windows failures unrelated, merging 🙂

@pawamoy pawamoy merged commit d462425 into pawamoy:main Oct 25, 2023
10 of 16 checks passed
@kwigley kwigley deleted the add-ruff-format branch October 25, 2023 16:46
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