From 03f441a4dbd58691533cc05af71b9481e3baace2 Mon Sep 17 00:00:00 2001 From: Paul Gesel Date: Mon, 22 May 2023 14:45:02 -0400 Subject: [PATCH 1/4] change install location --- README.md | 2 +- .../minimal_publisher.py | 2 +- .../setup_helper.py | 20 ++++++++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e8b194b..d9d67d6 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ int main(int argc, char * argv[]) ```python import rclpy from rclpy.node import Node -from turtlesim_parameters import turtlesim_parameters +from turtlesim_pkg.turtlesim_parameters import turtlesim_parameters def main(args=None): rclpy.init(args=args) diff --git a/examples/python/generate_parameter_module_example/minimal_publisher.py b/examples/python/generate_parameter_module_example/minimal_publisher.py index 1c4a367..150cc4d 100644 --- a/examples/python/generate_parameter_module_example/minimal_publisher.py +++ b/examples/python/generate_parameter_module_example/minimal_publisher.py @@ -30,7 +30,7 @@ import rclpy import rclpy.node -from admittance_parameters import admittance_controller +from generate_parameter_module_example.admittance_parameters import admittance_controller class MinimalParam(rclpy.node.Node): diff --git a/generate_parameter_library_py/generate_parameter_library_py/setup_helper.py b/generate_parameter_library_py/generate_parameter_library_py/setup_helper.py index 500ed66..89d637c 100644 --- a/generate_parameter_library_py/generate_parameter_library_py/setup_helper.py +++ b/generate_parameter_library_py/generate_parameter_library_py/setup_helper.py @@ -36,12 +36,26 @@ def generate_parameter_module(module_name, yaml_file, validation_module=""): # TODO there must be a better way to do this. I need to find the build directory so I can place the python # module there build_dir = None + install_dir = None for i, arg in enumerate(sys.argv): # Look for the `--build-directory` option in the command line arguments if arg == "--build-directory" or arg == "--build-base": - build_dir = sys.argv[i + 1] - tmp = os.path.split(build_dir) - build_dir = os.path.join(*tmp[:-1]) + build = sys.argv[i + 1] + + tmp = os.path.split(build) + tmp = os.path.split(tmp[0]) + pkg_name = tmp[1] + tmp = os.path.split(tmp[0]) + colcon_ws = tmp[0] + tmp = sys.version.split()[0] + tmp = tmp.split('.') + + py_version = f'python{tmp[0]}.{tmp[1]}' + install_dir = os.path.join(colcon_ws, 'install', pkg_name, 'lib', py_version, 'site-packages', pkg_name) + build_dir = os.path.join(colcon_ws, 'build', pkg_name, pkg_name) break + if build_dir: run(os.path.join(build_dir, module_name + ".py"), yaml_file, validation_module) + if build_dir: + run(os.path.join(install_dir, module_name + ".py"), yaml_file, validation_module) From cc2282e51e823ac0cabaa5902c876dceb86596e9 Mon Sep 17 00:00:00 2001 From: Paul Gesel Date: Mon, 22 May 2023 16:17:20 -0400 Subject: [PATCH 2/4] fix error in README --- examples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index d58b803..f26a602 100644 --- a/examples/README.md +++ b/examples/README.md @@ -15,7 +15,7 @@ ``` source install/setup.bash -ros2 run generate_parameter_library_example test_node --ros-args --params-file --params-file src/generate_parameter_library/examples/cpp/config/implementation.yaml +ros2 run generate_parameter_library_example test_node --ros-args --params-file src/generate_parameter_library/examples/cpp/config/implementation.yaml ``` ## Or run the Python node From f1abef21baf69a168f7e4d9abe20f766b9708e71 Mon Sep 17 00:00:00 2001 From: Paul Gesel Date: Mon, 22 May 2023 16:31:00 -0400 Subject: [PATCH 3/4] rename vars --- .../setup_helper.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/generate_parameter_library_py/generate_parameter_library_py/setup_helper.py b/generate_parameter_library_py/generate_parameter_library_py/setup_helper.py index 89d637c..f01c756 100644 --- a/generate_parameter_library_py/generate_parameter_library_py/setup_helper.py +++ b/generate_parameter_library_py/generate_parameter_library_py/setup_helper.py @@ -40,22 +40,23 @@ def generate_parameter_module(module_name, yaml_file, validation_module=""): for i, arg in enumerate(sys.argv): # Look for the `--build-directory` option in the command line arguments if arg == "--build-directory" or arg == "--build-base": - build = sys.argv[i + 1] + build_arg = sys.argv[i + 1] + + path_split = os.path.split(build_arg) + path_split = os.path.split(path_split[0]) + pkg_name = path_split[1] + path_split = os.path.split(path_split[0]) + colcon_ws = path_split[0] - tmp = os.path.split(build) - tmp = os.path.split(tmp[0]) - pkg_name = tmp[1] - tmp = os.path.split(tmp[0]) - colcon_ws = tmp[0] tmp = sys.version.split()[0] tmp = tmp.split('.') - py_version = f'python{tmp[0]}.{tmp[1]}' + install_dir = os.path.join(colcon_ws, 'install', pkg_name, 'lib', py_version, 'site-packages', pkg_name) build_dir = os.path.join(colcon_ws, 'build', pkg_name, pkg_name) break if build_dir: run(os.path.join(build_dir, module_name + ".py"), yaml_file, validation_module) - if build_dir: + if install_dir: run(os.path.join(install_dir, module_name + ".py"), yaml_file, validation_module) From a1cb766b600cda682be73a17e91a69c45112e56c Mon Sep 17 00:00:00 2001 From: Paul Gesel Date: Mon, 22 May 2023 16:37:41 -0400 Subject: [PATCH 4/4] run pre-commit --- .../minimal_publisher.py | 4 +++- .../setup_helper.py | 20 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/examples/python/generate_parameter_module_example/minimal_publisher.py b/examples/python/generate_parameter_module_example/minimal_publisher.py index 150cc4d..b2fb283 100644 --- a/examples/python/generate_parameter_module_example/minimal_publisher.py +++ b/examples/python/generate_parameter_module_example/minimal_publisher.py @@ -30,7 +30,9 @@ import rclpy import rclpy.node -from generate_parameter_module_example.admittance_parameters import admittance_controller +from generate_parameter_module_example.admittance_parameters import ( + admittance_controller, +) class MinimalParam(rclpy.node.Node): diff --git a/generate_parameter_library_py/generate_parameter_library_py/setup_helper.py b/generate_parameter_library_py/generate_parameter_library_py/setup_helper.py index f01c756..291fa0b 100644 --- a/generate_parameter_library_py/generate_parameter_library_py/setup_helper.py +++ b/generate_parameter_library_py/generate_parameter_library_py/setup_helper.py @@ -49,14 +49,24 @@ def generate_parameter_module(module_name, yaml_file, validation_module=""): colcon_ws = path_split[0] tmp = sys.version.split()[0] - tmp = tmp.split('.') - py_version = f'python{tmp[0]}.{tmp[1]}' + tmp = tmp.split(".") + py_version = f"python{tmp[0]}.{tmp[1]}" - install_dir = os.path.join(colcon_ws, 'install', pkg_name, 'lib', py_version, 'site-packages', pkg_name) - build_dir = os.path.join(colcon_ws, 'build', pkg_name, pkg_name) + install_dir = os.path.join( + colcon_ws, + "install", + pkg_name, + "lib", + py_version, + "site-packages", + pkg_name, + ) + build_dir = os.path.join(colcon_ws, "build", pkg_name, pkg_name) break if build_dir: run(os.path.join(build_dir, module_name + ".py"), yaml_file, validation_module) if install_dir: - run(os.path.join(install_dir, module_name + ".py"), yaml_file, validation_module) + run( + os.path.join(install_dir, module_name + ".py"), yaml_file, validation_module + )