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

Move linters configurations in pyproject.toml #1699

Merged
merged 4 commits into from
Dec 2, 2021

Conversation

MVrachev
Copy link
Collaborator

@MVrachev MVrachev commented Nov 30, 2021

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 our
code 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 and mypy inside pyproject.toml,
but I faced difficulties with black and isort.
I explained what problems I faced moving some of the arguments in those comments:

I decided to call black and isort without specifying the config file as they automatically find pyproject.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
:

  • The code follows the Code Style Guidelines
  • Tests have been added for the bug fix or new feature
  • Docs have been added for the bug fix or new feature

@MVrachev
Copy link
Collaborator Author

@lukpueh will appreciate a look from you as this is a TODO item added by you 9 months ago :D

@coveralls
Copy link

coveralls commented Nov 30, 2021

Pull Request Test Coverage Report for Build 1526231479

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 97.58%

Totals Coverage Status
Change from base Build 1520084662: 0.0%
Covered Lines: 4030
Relevant Lines: 4114

💛 - Coveralls

Copy link
Member

@lukpueh lukpueh left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @MVrachev. I very briefly took a stab at it before writing #1684, but got too annoyed with the configuration issues you described. So, I all the more appreciate that you followed through! 👍

pyproject.toml Outdated Show resolved Hide resolved
"tuf/exceptions.py"
]

[[tool.mypy.overrides]]
Copy link
Member

Choose a reason for hiding this comment

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

Why double brackets?

Copy link
Collaborator Author

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_]*$"
Copy link
Member

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"?

Copy link
Collaborator Author

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.

Copy link
Member

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

Copy link
Collaborator Author

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
Copy link
Member

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)

Copy link
Collaborator Author

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.

Copy link
Member

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

Copy link
Collaborator Author

@MVrachev MVrachev Dec 1, 2021

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.

docs/CONTRIBUTORS.rst Outdated Show resolved Hide resolved
This aims to add a single source of truth for pylint and mypy
configurations.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
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 <mvrachev@vmware.com>
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 <mvrachev@vmware.com>
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
@MVrachev
Copy link
Collaborator Author

MVrachev commented Dec 1, 2021

I had to force-push because I linked the black configuration documentation in the build section instead of the black section.
No other changes were made.

@MVrachev MVrachev mentioned this pull request Dec 1, 2021
3 tasks
Copy link
Member

@jku jku left a 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

Comment on lines +79 to +83
files = [
"tuf/api/",
"tuf/ngclient",
"tuf/exceptions.py"
]
Copy link
Member

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)

Copy link
Member

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.

@jku jku merged commit d991362 into theupdateframework:develop Dec 2, 2021
@MVrachev MVrachev deleted the move-configs branch December 10, 2021 12:00
@lukpueh lukpueh mentioned this pull request Dec 13, 2021
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.

Configure black and isort only once in pyproject.toml
4 participants