-
Notifications
You must be signed in to change notification settings - Fork 275
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
Move linters configurations in pyproject.toml #1699
Conversation
@lukpueh will appreciate a look from you as this is a TODO item added by you 9 months ago :D |
Pull Request Test Coverage Report for Build 1526231479
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"tuf/exceptions.py" | ||
] | ||
|
||
[[tool.mypy.overrides]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why double brackets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was suggested by the mypy
pyproject.toml configuration file documentation here.
I tried running it without one of the bracket pairs and got the error:
pyproject.toml: tool.mypy.overrides sections must be an array. Please make sure you are using double brackets like so: [[tool.mypy.overrides]]
inlinevar-rgx="^[a-z][a-z0-9_]*$" | ||
module-rgx="^(_?[a-z][a-z0-9_]*|__init__)$" | ||
no-docstring-rgx="(__.*__|main|test.*|.*test|.*Test)$" | ||
variable-rgx="^[a-z][a-z0-9_]*$" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are some regexes in triple-quotes and others not? """rgx"""
vs "rgx"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A good catch. I copied the regex content from tuf/api/pylintrc
and made the mistake of not reading it.
Fixing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But in tuf/api/pylintrc
there are no quotes at all in these lines. (I actually compared the lines in both files while reviewing and the only difference are the quotes.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaa, I think I wanted to split them multiline but decided against it.
No matter what was the reason it's fixed now.
pylint -j 0 tuf/api tuf/ngclient --rcfile=tuf/api/pylintrc | ||
black tuf/api tuf/ngclient | ||
isort --check --diff tuf/api tuf/ngclient | ||
pylint -j 0 tuf/api tuf/ngclient --rcfile=pyproject.toml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also format and lint the scripts in the newly added examples
directory. (see #1685)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add a separate pr for that as I noticed there are a couple of mypy warnings that must be addressed as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, we already have a ticket for that in #1697
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After we agree that this pr is good, I will submit a pr for #1697.
This aims to add a single source of truth for pylint and mypy configurations. Signed-off-by: Martin Vrachev <[email protected]>
2442cff
to
4b2f227
Compare
We are using 4 linters: black, isort, pylint and mypy. It's good if we use one file as a source for truth for all linter configurations. As a first step move black options in pyproject.toml. I tried multiple ways to use the include option, so we can just call black --config=pyproject.toml, but I was not successful. Then I found this comment psf/black#861 (comment) explaining that the path argument is mandatory. As a result, I will move all configuration options for black inside pyproject.toml without the actual directories that need to be linted. Signed-off-by: Martin Vrachev <[email protected]>
We are using 4 linters: black, isort, pylint and mypy. It's good if we use one file as a source for truth for all linter configurations. I tried multiple ways to use the src_path option, so we can just call isort without pointing out the target folders, but I was not successful. I tried running isort with "isort --settings-path=pyproject.toml" I got the error: "Error: arguments passed in without any paths or content." Additionally, I saw one project with source configuration https://github.com/Pylons/pyramid/blob/master/pyproject.toml, but they had to give explicit folders too https://github.com/Pylons/pyramid/blob/8061fce297cc7117d3e6e2b39e47512c7db2904f/tox.ini#L26 and https://github.com/Pylons/pyramid/blob/8061fce297cc7117d3e6e2b39e47512c7db2904f/tox.ini#L66 It was a similar situation with "check" and "diff". In the documentation it's said that for both check and diff are not supported in configuration files. See: - https://pycqa.github.io/isort/docs/configuration/options.html#check - https://pycqa.github.io/isort/docs/configuration/options.html#show-diff Additionally, in two issues it was confirmed that in integration tests we should use --check and --diff the way we did until now. As a result, I moved part of the configuration options for isort inside pyproject.toml without the actual directories that need to be linted and "check" and "diff" options. Signed-off-by: Martin Vrachev <[email protected]>
Signed-off-by: Martin Vrachev <[email protected]>
4b2f227
to
5c8a866
Compare
I had to force-push because I linked the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with one suggestion that could be future work
files = [ | ||
"tuf/api/", | ||
"tuf/ngclient", | ||
"tuf/exceptions.py" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these make sense here so you can just run mypy
... but I wonder if maintenance would be easier if we gave these on the command line in tox.ini like all other tools -- then we could define a lint_dirs
variable in there once and use it for all tools (mypy would need a exceptions.py added until we move the file to api/ but that's fine)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally a good idea! But let's hold off this future work until we've removed legacy code, shall we? Maybe we won't need a lint_dirs
then.
Pull Request Test Coverage Report for Build 1526231479Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Fixes #1684
Description of the changes being introduced by the pull request:
In pr #1626 a
pyproject.toml
was added, which can be used to configure code formatters all of ourcode formatters in one place only. It's good if we use one file as a source for truth for all linter
configurations.
I was able to move all linter configurations for
pylint
andmypy
insidepyproject.toml
,but I faced difficulties with
black
andisort
.I explained what problems I faced moving some of the arguments in those comments:
black
target folders: Configure black and isort only once in pyproject.toml #1684 (comment)isort
target folders: Configure black and isort only once in pyproject.toml #1684 (comment)isort
options--check
and--dff
: Configure black and isort only once in pyproject.toml #1684 (comment)I decided to call
black
andisort
without specifying the config file as they automatically findpyproject.toml
as it's at the root of the project.
It's not the same situation for
pylint
.Please verify and check that the pull request fulfills the following
requirements: