-
Notifications
You must be signed in to change notification settings - Fork 143
rosidl_cli: Add type description support #857
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
Merged
fujitatomoya
merged 6 commits into
ros2:rolling
from
frneer:frn/rolling/cli_type_description_support
May 11, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a2e4e32
Add type description support to rosidl_cli
frneer 1952bfe
Fix typing annotation
frneer 6d2a6b5
Please flake8, mypy
hidmic 12fabce
Please flake8 take 2
hidmic 71d0c28
Merge branch 'rolling' into frn/rolling/cli_type_description_support
mergify[bot] 5b002ef
Merge branch 'rolling' into frn/rolling/cli_type_description_support
christophebedard 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Copyright 2021 Open Source Robotics Foundation, Inc. | ||
fujitatomoya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # | ||
| # 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. | ||
|
|
||
| import pathlib | ||
|
|
||
| from rosidl_cli.command import Command | ||
|
|
||
| from .api import generate_type_hashes | ||
|
|
||
|
|
||
| class HashCommand(Command): | ||
| """Generate type description hashes from interface definition files.""" | ||
|
|
||
| name = 'hash' | ||
|
|
||
| def add_arguments(self, parser): | ||
| parser.add_argument( | ||
| '-o', '--output-path', metavar='PATH', | ||
| type=pathlib.Path, default=None, | ||
| help=('Path to directory to hold generated ' | ||
| "source code files. Defaults to '.'.")) | ||
| parser.add_argument( | ||
| '-I', '--include-path', type=pathlib.Path, metavar='PATH', | ||
| dest='include_paths', action='append', default=[], | ||
| help='Paths to include dependency interface definition files from.') | ||
| parser.add_argument( | ||
| 'package_name', help='Name of the package to generate code for') | ||
| parser.add_argument( | ||
| 'interface_files', metavar='interface_file', nargs='+', | ||
| help=('Relative path to an interface definition file. ' | ||
| "If prefixed by another path followed by a colon ':', " | ||
| 'path resolution is performed against such path.')) | ||
|
|
||
| def main(self, *, args): | ||
| generate_type_hashes( | ||
| package_name=args.package_name, | ||
| interface_files=args.interface_files, | ||
| include_paths=args.include_paths, | ||
| output_path=args.output_path, | ||
| ) | ||
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,68 @@ | ||
| # Copyright 2021 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. | ||
|
|
||
| import pathlib | ||
|
|
||
| from .extensions import load_hash_extensions | ||
|
|
||
|
|
||
| def generate_type_hashes( | ||
| *, | ||
| package_name, | ||
| interface_files, | ||
| include_paths=None, | ||
| output_path=None, | ||
| ): | ||
| """ | ||
| Generate type hashes from interface definition files. | ||
|
|
||
| To do so, this function leverages type description hash generation support | ||
| as provided by third-party package extensions. | ||
|
|
||
| Each path to an interface definition file is a relative path optionally | ||
| prefixed by another path followed by a colon ':', against which the first | ||
| relative path is to be resolved. | ||
|
|
||
| The directory structure that these relative paths exhibit will be replicated | ||
| on output (as opposed to the prefix path, which will be ignored). | ||
|
|
||
| :param package_name: name of the package to generate hashes for | ||
| :param interface_files: list of paths to interface definition files | ||
| :param include_paths: optional list of paths to include dependency | ||
| interface definition files from | ||
| :param output_path: optional path to directory to hold generated | ||
| source code files, defaults to the current working directory | ||
| :returns: list of lists of paths to generated hashed json files, | ||
| one group per type or type support extension invoked | ||
| """ | ||
| extensions = [] | ||
| extensions.extend(load_hash_extensions()) | ||
|
|
||
| if include_paths is None: | ||
| include_paths = [] | ||
| if output_path is None: | ||
| output_path = pathlib.Path.cwd() | ||
| else: | ||
| pathlib.Path.mkdir(output_path, parents=True, exist_ok=True) | ||
|
|
||
| generated_hashes = [] | ||
| for extension in extensions: | ||
| generated_hashes.extend(extension.generate_type_hashes( | ||
| package_name, | ||
| interface_files, | ||
| include_paths, | ||
| output_path=output_path, | ||
| )) | ||
|
|
||
| return generated_hashes |
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,55 @@ | ||
| # Copyright 2021 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 rosidl_cli.extensions import Extension | ||
| from rosidl_cli.extensions import load_extensions | ||
|
|
||
|
|
||
| class HashCommandExtension(Extension): | ||
| """ | ||
| The extension point for source code generation. | ||
|
|
||
| The following methods must be defined: | ||
| * `generate_type_hashes` | ||
| """ | ||
|
|
||
| def generate_type_hashes( | ||
| self, | ||
| package_name, | ||
| interface_files, | ||
| include_paths, | ||
| output_path, | ||
| ): | ||
| """ | ||
| Generate type hashes from interface definition files. | ||
|
|
||
| Paths to interface definition files are relative paths optionally | ||
| prefixed by an absolute path followed by a colon ':', in which case | ||
| path resolution is to be performed against that absolute path. | ||
|
|
||
| :param package_name: name of the package to generate source code for | ||
| :param interface_files: list of paths to interface definition files | ||
| :param include_paths: list of paths to include dependency interface | ||
| definition files from. | ||
| :param output_path: path to directory to hold generated source code files | ||
| :returns: list of paths to generated source files | ||
| """ | ||
| raise NotImplementedError() | ||
|
|
||
|
|
||
| def load_hash_extensions(**kwargs): | ||
| """Load extensions for type hash generation.""" | ||
| return load_extensions( | ||
| 'rosidl_cli.command.hash.extensions', **kwargs | ||
| ) |
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.