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 a Flake8-to-Ruff configuration conversion tool #527

Merged
merged 2 commits into from
Oct 31, 2022

Conversation

charliermarsh
Copy link
Member

This PR adds a flake8_to_ruff command to generate a Ruff pyproject.toml section from an existing Flake8 configuration file (setup.cfg, tox.ini, or .flake8).

See: #414, #423.

@charliermarsh
Copy link
Member Author

This needs tests, and a strategy for actually distributing this tool. (It's just an example script in the repo right now.)

/// Parse a 'files-to-codes' mapping, mimicking Flake8's internal logic.
///
/// See: https://github.com/PyCQA/flake8/blob/7dfe99616fc2f07c0017df2ba5fa884158f3ea8a/src/flake8/utils.py#L45
pub fn parse_files_to_codes_mapping(value: String) -> Result<Vec<StrCheckCodePair>> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, this was shockingly complicated, I guess it stems from INI being such a limited format. (This is basically a 1-to-1 port of the code from Flake8 for parsing the per-file-ignores.)

@charliermarsh
Copy link
Member Author

@fsouza - Do you have any opinion on whether this should be distributed as...

  1. It's own PyPI package.
  2. A subcommand on ruff.
  3. A separate binary that's part of the same PyPI package (I don't know if this is possible).

@charliermarsh
Copy link
Member Author

(Merging for now, will expose in a separate PR.)

@charliermarsh charliermarsh merged commit 7e5e03f into main Oct 31, 2022
@charliermarsh charliermarsh deleted the charlie/flake8 branch October 31, 2022 15:34
@fsouza
Copy link
Contributor

fsouza commented Oct 31, 2022

@fsouza - Do you have any opinion on whether this should be distributed as...

1. It's own PyPI package.

2. A subcommand on `ruff`.

3. A separate binary that's part of the same PyPI package (I don't know if this is possible).

Oh that's an interesting one. I'm thinking a separate PyPI package since the common use case will likely be a one-off (or people like me that can't really force everyone in the company to migrate and have to wrap it in something like flake8-ruff-wrapper lol).

The reason I'm thinking that a separate PyPI package is better is because not everyone that uses ruff will use this tool? What do you think?

@charliermarsh
Copy link
Member Author

Yeah that makes sense. I do want to split ruff into subcommands, but even then it's probably not worth including this as a subcommand on ruff itself given that it's more of a compatibility tool.

Comment on lines +22 to +25
"line-length" | "line_length" => match value.clone().unwrap().parse::<usize>() {
Ok(line_length) => options.line_length = Some(line_length),
Err(e) => eprintln!("Unable to parse '{key}' property: {e}"),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this should be max-line-length/max_line_length instead?

https://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-max-line-length

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

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.

None yet

2 participants