-
Notifications
You must be signed in to change notification settings - Fork 159
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
Conversation
There was a problem hiding this 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).
There was a problem hiding this 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 👍
ros2pkg/ros2pkg/api/create.py
Outdated
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') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ros2pkg/setup.py
Outdated
('share/ros2pkg/resource/package_environment', [ | ||
'resource/package_environment/package.xml.em', | ||
]), | ||
], | ||
install_requires=['ros2cli'], | ||
zip_safe=False, |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
ros2pkg/ros2pkg/api/create.py
Outdated
from ros2pkg.api import get_prefix_path | ||
|
||
RESOURCE_PATH = os.path.abspath( | ||
os.path.join(get_prefix_path('ros2pkg'), 'share', 'ros2pkg', 'resource')) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!)
This reverts commit 90556f6.
Will install to e.g. install_isolated/ros2pkg/lib/python3.5/site-packages/ros2pkg/resource which is where it was being looked for previously
ros2pkg/package.xml
Outdated
@@ -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> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
I put this back in review. github collapsed it but there's an unresolved question in #87 (comment) if anyone has input |
ros2pkg/ros2pkg/api/create.py
Outdated
|
||
RESOURCE_PATH = os.path.join(os.path.dirname(__file__), '..', 'resource') | ||
RESOURCE_PATH = pkg_resources.resource_filename('ros2pkg', 'resource/') |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
2aa5b12
to
99f0127
Compare
ros2pkg/ros2pkg/api/create.py
Outdated
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
* 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
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 theshare
directory instead. Works with symlink or nonsymlink installs now.