Install & Compatibility
Where this runs
tested against v0.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 37.4MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 5.0s · import 0.000s · 38MB
40MB installed
● package 40MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
PackageIdentificationExtension
✓ from colcon_library_path.package_identification import PackageIdentificationExtension
✗ from colcon_library_path import PackageIdentificationExtension
This quickstart demonstrates the effect of `colcon-library-path` by programmatically (via `subprocess`) running a `colcon build` command with the `--add-build-paths` option. It then simulates sourcing the generated `setup.bash` file and prints the `COLCON_LIBRARY_PATH` environment variable, showing how the extension contributes library paths. Note that `colcon-library-path` is primarily a CLI extension for `colcon` and is not typically used for direct programmatic Python imports.
import subprocess
import os
import shutil
# --- Setup: Create a dummy colcon workspace and package ---
# This part simulates typical shell commands for setting up a colcon project.
workspace_path = "my_colcon_workspace"
os.makedirs(f"{workspace_path}/src/my_library", exist_ok=True)
with open(f"{workspace_path}/src/my_library/CMakeLists.txt", "w") as f:
f.write("project(my_library NONE)\n")
f.write("add_library(my_library SHARED my_library.cpp)\n")
with open(f"{workspace_path}/src/my_library/my_library.cpp", "w") as f:
f.write("// dummy C++ file\nint main() { return 0; }")
print(f"Created dummy package in {workspace_path}/src/my_library")
# --- Step 1: Run colcon build with --add-build-paths ---
# This activates the colcon-library-path extension.
try:
print("\nRunning colcon build with --add-build-paths...")
# Ensure colcon is in PATH, otherwise specify full path to colcon executable
result = subprocess.run(
['colcon', 'build', '--cmake-args', '-DBUILD_SHARED_LIBS=ON',
'--packages-select', 'my_library', '--add-build-paths'],
cwd=workspace_path,
check=True,
capture_output=True,
text=True
)
print("colcon build stdout:\n" + result.stdout)
if result.stderr:
print("colcon build stderr:\n" + result.stderr)
except FileNotFoundError:
print("Error: 'colcon' command not found. Please install colcon (pip install colcon-common-extensions).")
# Cleanup before exiting
shutil.rmtree(workspace_path)
exit(1)
except subprocess.CalledProcessError as e:
print(f"Error during colcon build:\n{e.stderr}")
# Cleanup before exiting
shutil.rmtree(workspace_path)
exit(1)
# --- Step 2: Source the generated setup file and check COLCON_LIBRARY_PATH ---
# This demonstrates the effect of colcon-library-path on the environment.
setup_file_path = os.path.join(workspace_path, "install", "setup.bash")
if os.path.exists(setup_file_path):
print(f"\nSourcing {setup_file_path} and checking COLCON_LIBRARY_PATH...")
# Simulate sourcing in a new shell to get the environment variable
command = f"source {setup_file_path} && echo $COLCON_LIBRARY_PATH"
result_env = subprocess.run(
['bash', '-c', command],
check=True,
capture_output=True,
text=True
)
colcon_lib_path = result_env.stdout.strip()
print(f"COLCON_LIBRARY_PATH after setup: {colcon_lib_path}")
if f"{workspace_path}/install/my_library/lib" in colcon_lib_path or \
f"{workspace_path}/build/my_library" in colcon_lib_path:
print("\u2705 colcon-library-path successfully contributed to COLCON_LIBRARY_PATH.")
else:
print("\u274c COLCON_LIBRARY_PATH does not contain expected library paths.")
else:
print(f"\u274c Error: {setup_file_path} not found. Build might have failed or not produced a setup file.")
# --- Cleanup ---
print(f"\nCleaning up workspace: {workspace_path}")
shutil.rmtree(workspace_path)
Upgrade
Version history
0.2.1latest on PyPI · released Jan 16, 2019
Audit
Dependencies
colcon-corerequiredThis package is a colcon extension and requires colcon-core to function.
colcon-package-informationrequiredRequired for package information processing within colcon.