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 Python install #122

Merged
merged 4 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,37 @@ 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_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 = 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 install_dir:
run(
os.path.join(install_dir, module_name + ".py"), yaml_file, validation_module
)