-
Notifications
You must be signed in to change notification settings - Fork 128
Add ament_lint_auto_py and ament_lint_common_py
#569
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
Open
InvincibleRMC
wants to merge
22
commits into
ament:rolling
Choose a base branch
from
InvincibleRMC:ament_lint_auto-for-python
base: rolling
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
24fbba0
init
InvincibleRMC 5feeaf8
Register linters
InvincibleRMC a200508
undo more accidentally changes
InvincibleRMC 0890137
remove changelog
InvincibleRMC 28d55ab
make runner stateful for AMENT_LINT_AUTO_FILE_EXCLUDE
InvincibleRMC e03c19f
Add docs about 3rd party linters
InvincibleRMC 53bf4f4
allow for ament_lint* metapackages
InvincibleRMC 8b28229
add pytest config options, and auto test detection
InvincibleRMC 6d44ffb
update logic around ament_lint_auto_py for linting
InvincibleRMC edfb5ba
add note about parity
InvincibleRMC 53f38cf
Update ament_lint_auto_py/ament_lint_auto_py/pytest_plugin.py
InvincibleRMC 307057d
Update ament_lint_auto_py/doc/index.rst
InvincibleRMC a7d6f04
Update ament_pep257/ament_pep257/main.py
InvincibleRMC 53cefad
Update ament_pycodestyle/ament_pycodestyle/main.py
InvincibleRMC 9d4b926
Update ament_pyflakes/ament_pyflakes/main.py
InvincibleRMC f7e74d5
Update ament_lint_auto_py/doc/index.rst
InvincibleRMC ec4052f
Update ament_lint_auto_py/doc/index.rst
InvincibleRMC f352eb4
Update ament_lint_auto_py/doc/index.rst
InvincibleRMC 8d4a55a
Update ament_lint_common_py/doc/index.rst
InvincibleRMC 99209d7
Update ament_xmllint/ament_xmllint/main.py
InvincibleRMC 44a3fba
Update ament_lint_auto_py/ament_lint_auto_py/pytest_plugin.py
InvincibleRMC 5aa6c76
Merge branch 'rolling' into ament_lint_auto-for-python
InvincibleRMC 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
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,3 @@ | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| Changelog for package ament_lint_auto_py | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Empty file.
Empty file.
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,120 @@ | ||
| # Copyright 2026 Open Source Robotics Foundation, Inc. | ||
| # | ||
| # 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 importlib.metadata import entry_points | ||
| from importlib.metadata import EntryPoint | ||
| from pathlib import Path | ||
| from typing import Literal | ||
|
|
||
| from ament_lint_auto_py.xml_helpers import find_package_xml | ||
| from ament_lint_auto_py.xml_helpers import get_depends_recursive | ||
| from ament_lint_auto_py.xml_helpers import package_has_ament_lint_auto_py | ||
| from pytest import Config | ||
| from pytest import Item | ||
| from pytest import Parser | ||
| from pytest import Session | ||
|
|
||
|
|
||
| def pytest_configure(config: Config) -> None: | ||
| config.addinivalue_line( | ||
| 'markers', 'ament_lint_auto_py: marks tests as running all linter checks' | ||
| ) | ||
|
|
||
|
|
||
| class AmentLintItem(Item): | ||
| def __init__( | ||
| self, | ||
| *, | ||
| entry_point: EntryPoint, | ||
| file_excludes: list[str], | ||
| **kwargs, | ||
| ) -> None: | ||
| super().__init__(**kwargs) | ||
| self.entry_point = entry_point | ||
| self.file_excludes = file_excludes | ||
|
|
||
| def runtest(self) -> None: | ||
| runner = self.entry_point.load() | ||
|
|
||
| args: list[str] = [] | ||
| if self.file_excludes: | ||
| args.append('--exclude') | ||
| args.extend(self.file_excludes) | ||
|
|
||
| rc = runner(args)() | ||
| if rc != 0: | ||
| raise AssertionError( | ||
| f'Linter[{runner.NAME}] failed with exit code {rc}' | ||
| ) | ||
|
|
||
| def reportinfo(self) -> tuple[Path, Literal[0], str]: | ||
| return self.path, 0, f'ament_lint: {self.name}' | ||
|
|
||
|
|
||
| def pytest_collection_modifyitems(session: Session, config: Config, items: list[Item]) -> None: | ||
| excluded = set(config.getini('ament_lint_auto_exclude')) | ||
| file_excludes = config.getini('ament_lint_auto_file_exclude') | ||
|
|
||
| pkg_xml = find_package_xml(config.rootpath) | ||
| if pkg_xml is None: | ||
| return # Not in a ROS package | ||
|
|
||
| if not package_has_ament_lint_auto_py(pkg_xml): | ||
| return # Package does not opt-in | ||
|
|
||
| effective_depends = get_depends_recursive(pkg_xml) | ||
| linters = entry_points(group='ament_lint') | ||
|
|
||
| for ep in linters: | ||
| runner = ep.load() | ||
|
|
||
| if runner.NAME not in effective_depends: | ||
| continue # skipping linter if not declared in depends of a package.xmk | ||
|
|
||
| if runner.NAME in excluded: | ||
| continue # skipping linter if declared in ament_lint_auto_exclude | ||
|
|
||
| # skip linters if no matching files exist | ||
| found_file = False | ||
| for pattern in runner.FILE_TYPES: | ||
| if any(Path('.').rglob(pattern)): | ||
|
InvincibleRMC marked this conversation as resolved.
Outdated
|
||
| found_file = True | ||
| break | ||
| if not found_file: | ||
| continue | ||
|
|
||
| items.append( | ||
| AmentLintItem.from_parent( | ||
| parent=session, | ||
| name=runner.NAME, | ||
| entry_point=ep, | ||
| file_excludes=file_excludes, | ||
| path=config.rootpath, | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| def pytest_addoption(parser: Parser): | ||
| parser.addini( | ||
| 'ament_lint_auto_exclude', | ||
| 'Linters to exclude from ament_lint_auto_py', | ||
| type='linelist', | ||
| default=[], | ||
| ) | ||
| parser.addini( | ||
| 'ament_lint_auto_file_exclude', | ||
| 'File globs to exclude from ament linters', | ||
| type='linelist', | ||
| default=[], | ||
| ) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.