Install & Compatibility
Where this runs
tested against v0.2.5 · 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 · 39.7MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 5.2s · import 0.000s · 41MB
43MB installed
● package 43MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
colcon_metadata
✓ colcon CLI commands (e.g., colcon build)
colcon-metadata is a colcon extension that registers entry points; it is not typically imported directly into user Python code. Its functionality is exposed via the `colcon` command-line interface.
This quickstart demonstrates `colcon-metadata` by creating a temporary `colcon` workspace with a Python package defined solely by a `colcon.pkg` file. It then attempts to run `colcon build` to show how `colcon`, with the `colcon-metadata` extension, can discover and process packages based on this metadata file. Ensure `colcon-core` is installed in your environment for the `colcon` command to be available.
import os
import subprocess
import shutil
# Define workspace and package paths
workspace_dir = "temp_colcon_metadata_workspace"
package_dir = os.path.join(workspace_dir, "my_python_package")
colcon_pkg_path = os.path.join(package_dir, "colcon.pkg")
# Clean up previous runs if any
if os.path.exists(workspace_dir):
shutil.rmtree(workspace_dir)
# Create directory structure
os.makedirs(package_dir, exist_ok=True)
# Create a dummy colcon.pkg file for metadata
colcon_pkg_content = """
type: python
name: my_python_package
version: 0.1.0
maintainers:
- Example User <user@example.com>
"""
with open(colcon_pkg_path, "w") as f:
f.write(colcon_pkg_content)
# Optional: Create a minimal setup.py and __init__.py for a buildable Python package
setup_py_content = """
from setuptools import setup
setup(
name='my_python_package',
version='0.1.0',
packages=['my_python_package'],
install_requires=[],
)
"""
os.makedirs(os.path.join(package_dir, "my_python_package"), exist_ok=True)
with open(os.path.join(package_dir, "setup.py"), "w") as f:
f.write(setup_py_content)
with open(os.path.join(package_dir, "my_python_package", "__init__.py"), "w") as f:
f.write("")
print(f"Created dummy package at: {package_dir}")
print(f"Created colcon.pkg at: {colcon_pkg_path}")
# Attempt to run 'colcon build' to demonstrate discovery
print("\nAttempting to run 'colcon build' in the workspace...")
try:
# Check if colcon is installed
subprocess.run(["colcon", "--version"], check=True, capture_output=True)
# Run colcon build for the specific package
result = subprocess.run(
["colcon", "build", "--packages-select", "my_python_package"],
cwd=workspace_dir,
check=True,
capture_output=True,
text=True
)
print("colcon build successful! Output:\n")
print(result.stdout)
if result.stderr:
print("colcon build stderr:\n", result.stderr)
except FileNotFoundError:
print("Error: 'colcon' command not found. Please install colcon-core: pip install colcon-core")
except subprocess.CalledProcessError as e:
print(f"colcon build failed: {e}")
print("stdout:\n", e.stdout)
print("stderr:\n", e.stderr)
finally:
# Clean up the workspace
if os.path.exists(workspace_dir):
print(f"\nCleaning up {workspace_dir}")
shutil.rmtree(workspace_dir)
colcon --version
Upgrade
Version history
0.2.5latest on PyPI · released Aug 10, 2020
Audit
Dependencies
colcon-corerequiredProvides the core `colcon` build system, which `colcon-metadata` extends. Essential for `colcon` commands.
colcon-package-informationrequiredUsed internally by `colcon-metadata` for package information handling.