From b1a3abd7100b277ef77655632b3ea4ccad8eb8af Mon Sep 17 00:00:00 2001 From: imcelroy Date: Wed, 8 Jan 2025 11:22:13 +0100 Subject: [PATCH] fix: install generated parameter module into source directory --- example_python/setup.py | 6 +++++- .../generate_parameter_library_py/setup_helper.py | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/example_python/setup.py b/example_python/setup.py index c757ec8..966c0f6 100644 --- a/example_python/setup.py +++ b/example_python/setup.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import sys +import os from setuptools import setup @@ -8,12 +9,15 @@ if len(sys.argv) >= 2 and sys.argv[1] != 'clean': from generate_parameter_library_py.setup_helper import generate_parameter_module + current_dir = os.path.dirname(os.path.abspath(__file__)) + src_dir = os.path.abspath(os.path.join(current_dir, package_name)) + # set module_name and yaml file module_name = 'admittance_parameters' yaml_file = 'generate_parameter_module_example/parameters.yaml' validation_module = 'generate_parameter_module_example.custom_validation' generate_parameter_module( - module_name, yaml_file, validation_module=validation_module + module_name, yaml_file, validation_module=validation_module, src_dir=src_dir ) setup( 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 4149223..d619c40 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 @@ -32,7 +32,7 @@ from generate_parameter_library_py.generate_python_module import run -def generate_parameter_module(module_name, yaml_file, validation_module=''): +def generate_parameter_module(module_name, yaml_file, validation_module='', src_dir=None): # 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 @@ -60,11 +60,13 @@ def generate_parameter_module(module_name, yaml_file, validation_module=''): 'site-packages', pkg_name, ) - build_dir = os.path.join(colcon_ws, 'build', pkg_name, pkg_name) + build_dir = os.path.join(colcon_ws, 'build', pkg_name, 'build', 'lib', pkg_name) break if build_dir: run(os.path.join(build_dir, module_name + '.py'), yaml_file, validation_module) + if src_dir: + run(os.path.join(src_dir, module_name + '.py'), yaml_file, validation_module) if install_dir: run( os.path.join(install_dir, module_name + '.py'), yaml_file, validation_module