-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add top-level executable for rosdistro-reviewer
- Loading branch information
Showing
7 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,9 @@ | ||
# Copyright 2024 Open Source Robotics Foundation, Inc. | ||
# Licensed under the Apache License, Version 2.0 | ||
|
||
import sys | ||
|
||
from rosdistro_reviewer.command import main | ||
|
||
|
||
sys.exit(main()) |
This file contains 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,34 @@ | ||
# Copyright 2024 Open Source Robotics Foundation, Inc. | ||
# Licensed under the Apache License, Version 2.0 | ||
|
||
from typing import Any | ||
|
||
from colcon_core.command \ | ||
import LOG_LEVEL_ENVIRONMENT_VARIABLE \ | ||
as COLCON_LOG_LEVEL_ENVIRONMENT_VARIABLE | ||
from colcon_core.command import main as colcon_main | ||
from colcon_core.environment_variable import EnvironmentVariable | ||
from rosdistro_reviewer.verb.review import ReviewVerb | ||
|
||
"""Environment variable to set the log level""" | ||
LOG_LEVEL_ENVIRONMENT_VARIABLE = EnvironmentVariable( | ||
'ROSDISTRO_REVIEWER_LOG_LEVEL', | ||
COLCON_LOG_LEVEL_ENVIRONMENT_VARIABLE.description) | ||
|
||
"""Environment variable to set the configuration directory""" | ||
HOME_ENVIRONMENT_VARIABLE = EnvironmentVariable( | ||
'ROSDISTRO_REVIEWER_HOME', | ||
'Set the configuration directory (default: ~/.rosdistro_reviewer)') | ||
|
||
|
||
def main(*args: str, **kwargs: str) -> Any: | ||
"""Execute the main logic of the command.""" | ||
colcon_kwargs = { | ||
'command_name': 'rosdistro-reviewer', | ||
'verb_group_name': 'rosdistro_reviewer.verb', | ||
'environment_variable_group_name': | ||
'rosdistro_reviewer.environment_variable', | ||
'default_verb': ReviewVerb, | ||
**kwargs, | ||
} | ||
return colcon_main(*args, **colcon_kwargs) |
Empty file.
This file contains 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,42 @@ | ||
# Copyright 2024 Open Source Robotics Foundation, Inc. | ||
# Licensed under the Apache License, Version 2.0 | ||
|
||
import logging | ||
from pathlib import Path | ||
|
||
from colcon_core.logging import colcon_logger | ||
from colcon_core.logging import get_effective_console_level | ||
from colcon_core.plugin_system import satisfies_version | ||
from colcon_core.verb import VerbExtensionPoint | ||
from rosdistro_reviewer.element_analyzer import analyze | ||
|
||
|
||
class ReviewVerb(VerbExtensionPoint): | ||
"""Generate a review for rosdistro changes.""" | ||
|
||
def __init__(self): # noqa: D107 | ||
super().__init__() | ||
satisfies_version(VerbExtensionPoint.EXTENSION_POINT_VERSION, '^1.0') | ||
log_level = get_effective_console_level(colcon_logger) | ||
logging.getLogger('git').setLevel(log_level) | ||
|
||
def add_arguments(self, *, parser): # noqa: D102 | ||
parser.add_argument( | ||
'--target-ref', default=None, metavar='COMMITTISH', | ||
help='Git commit-ish to use as the base for determining what ' | ||
'changes should be reviewed (default: commit prior to ' | ||
'--head-ref)') | ||
parser.add_argument( | ||
'--head-ref', default=None, metavar='COMMITTISH', | ||
help='Git commit-ish which contains changes that should be ' | ||
'reviewed (default: uncommitted changes)') | ||
|
||
def main(self, *, context): # noqa: D102 | ||
review = analyze( | ||
Path.cwd(), | ||
target_ref=context.args.target_ref, | ||
head_ref=context.args.head_ref) | ||
if review: | ||
root = Path.cwd() if context.args.head_ref is None else None | ||
print('\n' + review.to_text(root=root) + '\n') | ||
return 0 |
This file contains 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 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 |
---|---|---|
|
@@ -26,9 +26,11 @@ returncode | |
rosdistro | ||
rstrip | ||
rtype | ||
runpy | ||
scspell | ||
setuptools | ||
thomas | ||
unidiff | ||
unittest | ||
waldo | ||
yaml |
This file contains 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,28 @@ | ||
# Copyright 2024 Open Source Robotics Foundation, Inc. | ||
# Licensed under the Apache License, Version 2.0 | ||
|
||
from runpy import run_module | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
|
||
@patch( | ||
'colcon_core.argument_parser.get_argument_parser_extensions', | ||
return_value={}, | ||
) | ||
def test_main(get_argument_parser_extensions): | ||
with patch('sys.argv', ['__main__', '--help']): | ||
with pytest.raises(SystemExit) as e: | ||
run_module('rosdistro_reviewer') | ||
assert e.value.code == 0 | ||
|
||
with patch( | ||
'rosdistro_reviewer.verb.review.ReviewVerb.main', | ||
return_value=42, | ||
) as verb_main: | ||
with patch('sys.argv', ['__main__', '--log-base', '/dev/null']): | ||
with pytest.raises(SystemExit) as e: | ||
run_module('rosdistro_reviewer') | ||
assert e.value.code == 42 | ||
verb_main.assert_called_once() |