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

Fix installation of templates for ros2pkg create #87

Merged
merged 10 commits into from
Apr 10, 2018

Conversation

dhood
Copy link
Member

@dhood dhood commented Apr 3, 2018

connects to #86
resolves #86

Previously (when not using symlink install), templates were being looked for in ~/ros2_ws/install_isolated/ros2pkg/lib/python3.5/site-packages/ros2pkg/.

I didn't see how to make data_files install to that location (and it might not make sense conceptually) so I'm installing to the share directory instead. Works with symlink or nonsymlink installs now.

@dhood dhood added the in review Waiting for review (Kanban column) label Apr 3, 2018
@dhood dhood self-assigned this Apr 3, 2018
dirk-thomas
dirk-thomas previously approved these changes Apr 4, 2018
Copy link
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

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

The patch looks good to me (I haven't tried to install and run it though).

Copy link
Member

@mikaelarguedas mikaelarguedas left a comment

Choose a reason for hiding this comment

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

tested with and without symlink install, totally works 👍

RESOURCE_PATH = os.path.join(os.path.dirname(__file__), '..', 'resource')
from ros2pkg.api import get_prefix_path

RESOURCE_PATH = os.path.join(get_prefix_path('ros2pkg'), 'share', 'ros2pkg', 'resource')
Copy link
Member

Choose a reason for hiding this comment

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

Is this an absolute path ?
If so, template_path line 71 can just get rid of __file__ as well and just use the resource path directly

Copy link
Member Author

@dhood dhood Apr 4, 2018

Choose a reason for hiding this comment

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

yeah I think __file__ maybe didn't belong regardless. will fix

Copy link
Member Author

Choose a reason for hiding this comment

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

@dhood
Copy link
Member Author

dhood commented Apr 4, 2018

CI for linters (thanks for testing manually): Build Status

ros2pkg/setup.py Outdated
('share/ros2pkg/resource/package_environment', [
'resource/package_environment/package.xml.em',
]),
],
install_requires=['ros2cli'],
zip_safe=False,
Copy link
Member

Choose a reason for hiding this comment

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

With __file__ completely removed, this package may very well be zip_safe now (just I hunch, I didn't actually check)

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure, it has to do with data files too from what I've read, but this page says: "And if the project uses pkg_resources for all its data file access, then C extensions and other data files shouldn’t be a problem at all." so perhaps after 3b38a29 it's fine but I am not sure how to test for sure.

Copy link
Member

Choose a reason for hiding this comment

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

For using pkg_resources though the package should declare a dependency on setuptools since it will be needed at runtime of the package.

Copy link
Member

Choose a reason for hiding this comment

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

zip_safe=True is fine if the code doesn't use __file__ or anything similar to directly read individual files.

@dirk-thomas dirk-thomas dismissed their stale review April 4, 2018 00:55

Re-review...

from ros2pkg.api import get_prefix_path

RESOURCE_PATH = os.path.abspath(
os.path.join(get_prefix_path('ros2pkg'), 'share', 'ros2pkg', 'resource'))
Copy link
Member

Choose a reason for hiding this comment

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

Looking at this again I don't think we should couple the resource lookup with the ament index. Instead use the pkg_resources API for this: like https://github.com/ament/ament_package/blob/28308125089b607f2797abee577371d7ee9a0934/ament_package/templates.py#L24

Copy link
Member Author

Choose a reason for hiding this comment

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

so install templates with package_data instead of data_files, is that right? I think that's the answer to the "how do I install to site-packges" question I was having, good to know that this exists (and that we don't have to specify each file manually!)

Will install to e.g. install_isolated/ros2pkg/lib/python3.5/site-packages/ros2pkg/resource
which is where it was being looked for previously
@@ -12,6 +12,8 @@
<depend>ros2cli</depend>

<exec_depend>ament_index_python</exec_depend>
<exec_depend>python3-empy</exec_depend>
<exec_depend>python3-setuptools</exec_depend>
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we declare (in the package.xml) dependency on setuptools for pure python packages (the same way we don't declare a dependency on cmake for ament_cmake packages).

Not sure about listing it in the install_requires section of the setup.py, it seems that some packages do and some don't. Maybe @dirk-thomas can give more details on that point

Copy link
Member

Choose a reason for hiding this comment

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

In a setup.py file I am not sure it makes sense. Because usually that very same file already imports setuptools at the beginning so it would fail already when the dependency is not present.

Once we declare these information in a setup.cfg instead I think it does make sense to list setuptools as a dependency.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am using the package now at: 3b38a29#diff-97bb991599247d807fe7cf4dad543f62R20
(and generally coping ament_package, for reference)

Copy link
Member

Choose a reason for hiding this comment

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

I based my comment on the content of this repository. the ros2cli package (dependency of this one) uses setuptools and pkg_resources in multiple locations and doesnt declare a dependency on it in either the package.xml or the python files that import the module.
Is the general rule that any package using pkg_resources should declare that dependency in their package.xml ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that would make sense.

Copy link
Member

Choose a reason for hiding this comment

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

I guess this should be python3-pkg-resources then

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm I wonder if we are using python3-setuptools at https://github.com/ament/ament_package/blob/28308125089b607f2797abee577371d7ee9a0934/package.xml#L11 because python3-pkg-resources is only valid via apt, not via pip? (from what I can see). Is that it @dirk-thomas ?

Copy link
Member

Choose a reason for hiding this comment

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

Keys used in package.xml are used to query the rosdep database. In general we try to make sure that the rosdep keys resolve to apt packages if such package exist and avoid pip rules as much as we can as we cannot embed these dependencies in our debs.

My guess is that is was an oversight when the dependency was added to ament_package to fix failing downstream packages. As setuptools depends on pkg_resources, the more generic dependency does fix the problem.

Copy link
Member

Choose a reason for hiding this comment

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

I would guess the dependency was even added in to the xml before the rosdep rules existed. Any the assumption was probably at that time there is only setuptools - as you said pkg-resources is not a PyPI package.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok: minimal, apt-favouring dependency of python3-pkg-resources used in 7c2aef8 👍

@dhood
Copy link
Member Author

dhood commented Apr 5, 2018

I put this back in review. github collapsed it but there's an unresolved question in #87 (comment) if anyone has input


RESOURCE_PATH = os.path.join(os.path.dirname(__file__), '..', 'resource')
RESOURCE_PATH = pkg_resources.resource_filename('ros2pkg', 'resource/')
Copy link
Member

Choose a reason for hiding this comment

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

Why the trailing slash here?

Copy link
Member Author

Choose a reason for hiding this comment

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

think this usage in general might be off now that I've read this: "Do not use os.path routines to manipulate resource paths, as they are not filesystem paths.". I was going for a minimal change but will replicate https://github.com/ament/ament_package/blob/28308125089b607f2797abee577371d7ee9a0934/ament_package/templates.py#L24 exactly

Copy link
Member Author

Choose a reason for hiding this comment

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

well aren't I learning a lot today..! resource_filename will return a filesystem path, I think that comment I referenced above is referring to the arguments being passed in, where we aren't using os.path routines anyway. Still, I added 99f0127. If I understood correctly, resource_filename will potentially extract files/directories if the package is installed zipped, and this way it will only extract the files when they're needed, as opposed to the whole resource directory being extracted (or we can swap back).

Prevents resource_filename from extracting whole directory if
installation is zipped
@dhood dhood force-pushed the fix_ros2pkg_create_install branch from 2aa5b12 to 99f0127 Compare April 5, 2018 19:11
@@ -65,8 +68,7 @@ def _create_folder(folder_name, base_directory, exist_ok=True):


def _create_template_file(template_file_name, output_directory, output_file_name, template_config):
template_path = os.path.abspath(
os.path.join(__file__, RESOURCE_PATH, template_file_name))
template_path = _get_template_path(template_file_name)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe move the implementation of _get_template_path here since it is a single function call and only being used in this one location?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, that would make sense f18f246

@dhood
Copy link
Member Author

dhood commented Apr 6, 2018

ci just for linters Build Status

@dhood dhood requested a review from dirk-thomas April 10, 2018 16:19
@dhood dhood merged commit ea3a6b6 into master Apr 10, 2018
@dhood dhood deleted the fix_ros2pkg_create_install branch April 10, 2018 17:18
@dhood dhood removed the in review Waiting for review (Kanban column) label Apr 10, 2018
esteve pushed a commit to esteve/ros2cli that referenced this pull request Dec 16, 2022
* have LaunchService.run() return non-0 when there are exceptions

* update launch_counters.py example for Windows

* fix bug that would cause mismatched asyncio loops in some futures

* signal.SIGKILL doesn’t exist on Windows, so emulate it in our Event

* remove left over debug statement

* fix issue that resulted in spurious asyncio errors in LaunchService test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ros2 pkg create: resource files not installed
3 participants