Skip to content

Commit 0edb5d0

Browse files
committed
fix: auto-gen install fix for debian packaging
1 parent 062e8d0 commit 0edb5d0

File tree

1 file changed

+39
-36
lines changed

1 file changed

+39
-36
lines changed

generate_parameter_library_py/generate_parameter_library_py/setup_helper.py

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,49 +30,52 @@
3030
import sys
3131
import os
3232
from generate_parameter_library_py.generate_python_module import run
33+
from pathlib import Path
3334

3435

3536
def generate_parameter_module(
3637
module_name, yaml_file, validation_module='', install_base=None, merge_install=False
3738
):
38-
# TODO there must be a better way to do this. I need to find the build directory so I can place the python
39-
# module there
40-
build_dir = None
41-
install_dir = None
42-
for i, arg in enumerate(sys.argv):
43-
# Look for the `--build-directory` option in the command line arguments
44-
if arg == '--build-directory' or arg == '--build-base':
45-
build_arg = sys.argv[i + 1]
39+
# There's no nice way of auto-detecting if colcon was run with --merge-install or not
40+
# Have to manually specify for this function
41+
42+
# Get python version
43+
tmp = sys.version.split()[0]
44+
tmp = tmp.split('.')
45+
py_version = f'python{tmp[0]}.{tmp[1]}'
4646

47-
path_split = os.path.split(build_arg)
48-
path_split = os.path.split(path_split[0])
49-
pkg_name = path_split[1]
50-
path_split = os.path.split(path_split[0])
51-
colcon_ws = path_split[0]
47+
# Get pkg name and colcon_ws
48+
cwd = Path(os.getcwd())
49+
colcon_ws = str(cwd.parent.parent)
50+
pkg_name = cwd.stem
5251

53-
tmp = sys.version.split()[0]
54-
tmp = tmp.split('.')
55-
py_version = f'python{tmp[0]}.{tmp[1]}'
52+
# Get paths
53+
if not install_base:
54+
install_base = os.path.join(colcon_ws, 'install')
5655

57-
if not install_base:
58-
install_base = os.path.join(colcon_ws, 'install')
56+
install_base = (
57+
install_base if merge_install else os.path.join(install_base, pkg_name)
58+
)
59+
install_lib = None
60+
for i, arg in enumerate(sys.argv):
61+
if arg == '--install-lib':
62+
install_lib = sys.argv[i + 1]
63+
install_lib_split = install_lib.split('/')
64+
for i, val in enumerate(install_lib_split):
65+
if '$' in val:
66+
env_val = os.getenv(val)
67+
install_lib_split[i] = env_val if env_val else ''
5968

60-
install_base = (
61-
install_base if merge_install else os.path.join(install_base, pkg_name)
62-
)
63-
install_dir = os.path.join(
64-
install_base,
65-
'lib',
66-
py_version,
67-
'site-packages',
68-
pkg_name,
69-
)
70-
build_dir = os.path.join(colcon_ws, 'build', pkg_name, pkg_name)
71-
break
69+
# Get final install and build directories
70+
install_dir = os.path.join(
71+
install_base,
72+
'lib',
73+
py_version,
74+
'site-packages',
75+
pkg_name,
76+
)
77+
build_dir = os.path.join(colcon_ws, 'build', pkg_name, pkg_name)
7278

73-
if build_dir:
74-
run(os.path.join(build_dir, module_name + '.py'), yaml_file, validation_module)
75-
if install_dir:
76-
run(
77-
os.path.join(install_dir, module_name + '.py'), yaml_file, validation_module
78-
)
79+
# Auto-generate python script
80+
run(os.path.join(build_dir, module_name + '.py'), yaml_file, validation_module)
81+
run(os.path.join(install_dir, module_name + '.py'), yaml_file, validation_module)

0 commit comments

Comments
 (0)