-
Notifications
You must be signed in to change notification settings - Fork 357
Add ament_mypy support and strict typing to lifecycle_py #779
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a66af7c
Add ament_mypy support and strict typing to lifecycle_py
andrearichichi 503136e
Refactor test functions for improved readability and update copyright…
andrearichichi c59970a
Align ament_mypy test arguments with strict local checks
andrearichichi a38c2c3
Align ament_mypy test arguments with strict local checks
andrearichichi bd7d719
Align ament_mypy test arguments with strict local checks
andrearichichi fae4a29
Align ament_mypy test arguments with strict local checks
andrearichichi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Copyright 2019 Canonical, Ltd. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from ament_mypy.main import main | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.mypy | ||
| @pytest.mark.linter | ||
| def test_mypy() -> None: | ||
| def is_package_root(candidate: Path) -> bool: | ||
| return ( | ||
| (candidate / 'package.xml').is_file() | ||
| and (candidate / 'setup.py').is_file() | ||
| and (candidate / 'lifecycle_py').is_dir() | ||
| and (candidate / 'launch').is_dir() | ||
| and (candidate / 'test').is_dir() | ||
| ) | ||
|
|
||
| def find_package_root() -> Path: | ||
| here = Path(__file__).resolve() | ||
| cwd = Path.cwd().resolve() | ||
|
|
||
| candidates = [ | ||
| here.parent.parent, | ||
| cwd, | ||
| cwd / 'lifecycle_py', | ||
| ] | ||
|
|
||
| for candidate in candidates: | ||
| if is_package_root(candidate): | ||
| return candidate | ||
|
|
||
| # As a last resort, walk parents of __file__ and cwd. | ||
| for candidate in [*here.parents, *cwd.parents]: | ||
| if is_package_root(candidate): | ||
| return candidate | ||
|
|
||
| # Keep mypy scoped if no package root is detected. | ||
| return here.parent.parent | ||
|
|
||
| package_root = find_package_root() | ||
| paths_to_check = [ | ||
| str(package_root / 'lifecycle_py'), | ||
| str(package_root / 'launch'), | ||
| str(package_root / 'test'), | ||
| str(package_root / 'setup.py'), | ||
| ] | ||
|
|
||
| rc = main(argv=paths_to_check) | ||
| assert rc == 0, 'Found code style errors / warnings' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this is fragile? if the package directory structure ever changes, or if a subdirectory is renamed, this test will silently skip files or fail for structural reasons rather than type errors. this should be replaced with the standard minimal form. IMO, if main(argv=[]) doesn't discover the right files in the ament test harness, that's an ament_mypy bug, not something to work around in every consumer package.