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

Start linting the examples folder #1701

Merged
merged 2 commits into from
Dec 3, 2021

Conversation

MVrachev
Copy link
Collaborator

@MVrachev MVrachev commented Dec 1, 2021

Fixes #1697

Description of the changes being introduced by the pull request:

The examples folder currently contains a repository example and it's
good if we start linting its content and as a result add type
annotations.

I run all of the linters on the example folder instead of only using mypy
as I thought that will be better for the code included there.

Signed-off-by: Martin Vrachev [email protected]

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

@coveralls
Copy link

coveralls commented Dec 1, 2021

Pull Request Test Coverage Report for Build 1530507142

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.0004%) to 97.581%

Totals Coverage Status
Change from base Build 1530059117: 0.0004%
Covered Lines: 4031
Relevant Lines: 4115

💛 - Coveralls

pyproject.toml Outdated
Comment on lines 79 to 84
files = [
"tuf/api/",
"tuf/ngclient",
"tuf/exceptions.py"
"tuf/exceptions.py",
"examples/",
]
Copy link
Member

Choose a reason for hiding this comment

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

left a comment about this in the other bug: #1699 (comment) (we could remove these and just define the "linter dirs" in one place in tox.ini to make maintenance easier)

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 the PR, @MVrachev! From a quick glance it looks good to me! I'll take another look when it no longer has the draft status, which I think you can remove now that #1699 has been merged.

@@ -332,7 +333,7 @@ def _in(days):
del roles["targets"].signed.targets[target_path]

# Increase expiry (delegators should be less volatile)
roles["targets"].expires = _in(365)
roles["targets"].signed.expires = _in(365)
Copy link
Member

Choose a reason for hiding this comment

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

👀 Whoopsi, thanks for catching this! Did mypy detect it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it did.

@@ -117,7 +118,7 @@ def _in(days):
local_path = Path(__file__).resolve()
target_path = f"{local_path.parts[-2]}/{local_path.parts[-1]}"

target_file_info = TargetFile.from_file(target_path, local_path)
target_file_info = TargetFile.from_file(target_path, str(local_path))
Copy link
Member

Choose a reason for hiding this comment

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

Was this also flagged by mypy?

(Also it is odd, because I remember already casting this to str at some point because TargetFile.from_file raised an error with local_path being a Path object. But I can't find it in #1685. I wonder were it went... Anyways, good that you/mypy fixed it.)

Copy link
Collaborator Author

@MVrachev MVrachev Dec 2, 2021

Choose a reason for hiding this comment

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

Yes, mypy noticed that.
Yet another argument as to why we do need linting quickly as possible on new code.

roles = {}
keys = {}
roles: Dict[str, Metadata] = {}
keys: Dict[str, Dict[str, Any]] = {}
Copy link
Member

Choose a reason for hiding this comment

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

Quick question, what is the criterion for a variable name to get type annotated?

Copy link
Member

Choose a reason for hiding this comment

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

it's needed if mypy can't figure it out from the context (and mypy is not very advanced in this). So in this case roles = { "root": root_md } would have been fine but an empty container needs typing

Copy link
Collaborator Author

@MVrachev MVrachev Dec 2, 2021

Choose a reason for hiding this comment

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

I think it does need annotation when you use containers and personally, I think it's better to define annotations in these cases. It makes it so much easier to understand how the container should be used or is used later.

The examples folder currently contains a repository example and it's
good if we start linting its content and as a result add type
annotations.

Signed-off-by: Martin Vrachev <[email protected]>
Instead of providing a target directory for linting by each of the
tools use one variable which will be the source of truth about which
directories do we lint.

Signed-off-by: Martin Vrachev <[email protected]>
@MVrachev
Copy link
Collaborator Author

MVrachev commented Dec 2, 2021

I rebased on top of develop and created a commit adding a lint_dirs variable as proposed by Jussi.
@lukpueh is right that this list will be simplified after we drop the old code base, but still, it will be useful to have
a lint_dirs variable even if the list is simply ./

This pr is ready for review.

@MVrachev MVrachev marked this pull request as ready for review December 2, 2021 12:17
@MVrachev MVrachev requested a review from lukpueh December 2, 2021 12:18
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.

Works like a charm!

@lukpueh lukpueh merged commit a93f618 into theupdateframework:develop Dec 3, 2021
@MVrachev MVrachev deleted the lint-examples branch December 10, 2021 12:00
@lukpueh lukpueh mentioned this pull request Dec 13, 2021
@coveralls
Copy link

coveralls commented Dec 26, 2024

Pull Request Test Coverage Report for Build 1530507142

Warning: 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

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.0%) to 98.579%

Totals Coverage Status
Change from base Build 1530059117: 1.0%
Covered Lines: 3870
Relevant Lines: 3896

💛 - Coveralls

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.

examples: run mypy on repo example
4 participants