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

feat (pkg): don't allow hyphen in python pkg name #717

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from

Conversation

krsche
Copy link

@krsche krsche commented May 25, 2022

fixes #715

As @clalancette suggested to block creation of python pkgs with hyphens in the name I didn't implement a warning, but block them by returning early. Similar to what was being done for pkgs names test.

I didn't test this change locally as I didn't find instructions on how to install from source and it's such a minor change. Are there any instructions for installing from source / executing?

Should I add a unit test somewhere?

Signed-off-by: Fabian Kirschner <fabian.kirschner@gmail.com>
Copy link
Member

@aprotyas aprotyas left a comment

Choose a reason for hiding this comment

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

Are there any instructions for installing from source / executing?

For this specific repository? There aren't any repo-specific steps for ros2cli, but you'd have to follow the regular workflow of creating a workspace to act as an overlay on top of your default ROS workspace: https://docs.ros.org/en/rolling/Tutorials/Workspace/Creating-A-Workspace.html, after which you can build/source/test your workspace with code from your fork of ros2cli.

Should I add a unit test somewhere?

Yes please. Unit tests for the ros2 pkg CLI are here: https://github.com/ros2/ros2cli/blob/master/ros2pkg/test/test_cli.py

'choose a different package name.'
if '-' in args.package_name:
# Python packages shouldn't include hyphens in their name, refer to PEP-8.
# Running a via script 'ros2 run' with hyphens in the executable or package name
Copy link
Member

Choose a reason for hiding this comment

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

There is a linter warning in CI: Can you remove this trailing whitespace?

Suggested change
# Running a via script 'ros2 run' with hyphens in the executable or package name
# Running a via script 'ros2 run' with hyphens in the executable or package name

# directory the tests for the package go in.
return "Aborted since 'ament_python' packages can't be named 'test'. Please " + \
'choose a different package name.'
if '-' in args.package_name:
Copy link
Member

Choose a reason for hiding this comment

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

This is one case, but node names with hyphens are also problematic.

ros2 pkg create test_pkg --build-type ament_python --node-name test-node # breaks

Can you address this case too?

Copy link
Author

Choose a reason for hiding this comment

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

Very good catch, I forgot about that 😅

# Running a via script 'ros2 run' with hyphens in the executable or package name
# results in errors.
return "Aborted since 'ament_python' packages can't include hyphens ('-') in " + \
"their name (refer to PEP-8). Please choose a different package name."
Copy link
Member

Choose a reason for hiding this comment

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

(refer to PEP-8)

Nit: PEP-8 package and module names doesn't explicitly recommend against using hyphens, and no reasoning for this case is provided there either, so I don't know if this is helpful.

@krsche
Copy link
Author

krsche commented May 25, 2022

Thanks for your review, I'll address your points tomorrow.

Regarding the pep-8 reference - I thought of that while writing as well.. It's more complicated though because technically calling my_module = __import__('my-module') should work while import my-module doesn't. But I've never seen that explicit __import__(...) call anywhere so I'd still say forbid it.
Also it probably would require quite some adjustment in the cli to make it work with ros2 run...

Should I just remove the pep-8 reference then?

@aprotyas
Copy link
Member

Also it probably would require quite some adjustment in the cli to make it work with ros2 run...

True, and I don't think it's worth the time trying to make that pathological case work.

Should I just remove the pep-8 reference then?

👍

@krsche
Copy link
Author

krsche commented May 26, 2022

Ok, will do. I won't get to it until next week though

@clalancette clalancette added the more-information-needed Further information is required label Jun 9, 2022
@audrow audrow changed the base branch from master to rolling June 28, 2022 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-information-needed Further information is required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pkg create --build-type ament_python should warn about hyphens in pkg-name
3 participants