catkin-pkg: Catkin Package Library

1.1.0 · active · verified Sun Apr 12

catkin-pkg is a standalone Python library designed to support the Catkin build system, primarily used in the Robot Operating System (ROS) ecosystem. It provides functionalities for finding, introspecting, and managing Catkin packages within the file system, including parsing `package.xml` manifest files. The current version is 1.1.0, and it maintains an active development status with periodic releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `catkin_pkg` to find and introspect Catkin packages within a directory. It creates a temporary directory simulating a Catkin workspace, adds two dummy packages with `package.xml` files, and then uses `find_packages` to locate and parse them, printing out key metadata for each.

import os
import tempfile
import shutil
from pathlib import Path
from catkin_pkg.packages import find_packages

# Create a dummy catkin workspace for demonstration
temp_dir = Path(tempfile.mkdtemp())
workspace_path = temp_dir / "my_catkin_ws"
src_path = workspace_path / "src"
src_path.mkdir(parents=True, exist_ok=True)

# Create a dummy package A
pkg_a_path = src_path / "package_a"
pkg_a_path.mkdir(exist_ok=True)
(pkg_a_path / "package.xml").write_text("""<?xml version=\"1.0\"?>\n<package format=\"2\">\n  <name>package_a</name>\n  <version>0.1.0</version>\n  <description>A dummy package A</description>\n  <maintainer email=\"user@example.com\">User Name</maintainer>\n  <license>MIT</license>\n  <buildtool_depend>catkin</buildtool_depend>\n  <depend>python3-catkin-pkg</depend>\n</package>""")

# Create a dummy package B depending on A
pkg_b_path = src_path / "package_b"
pkg_b_path.mkdir(exist_ok=True)
(pkg_b_path / "package.xml").write_text("""<?xml version=\"1.0\"?>\n<package format=\"2\">\n  <name>package_b</name>\n  <version>0.1.0</version>\n  <description>A dummy package B</description>\n  <maintainer email=\"user@example.com\">User Name</maintainer>\n  <license>MIT</license>\n  <buildtool_depend>catkin</buildtool_depend>\n  <depend>package_a</depend>\n</package>""")

# Find and parse packages
print(f"Searching for packages in: {src_path}")
found_packages = find_packages(str(src_path))

print(f"Found {len(found_packages)} packages:")
for path, pkg in found_packages.items():
    print(f"- Path: {path}")
    print(f"  Name: {pkg.name}")
    print(f"  Version: {pkg.version}")
    print(f"  Description: {pkg.description}")
    print(f"  Dependencies:")
    for dep in pkg.buildtool_depends:
        print(f"    Buildtool: {dep.name}")
    for dep in pkg.depends:
        print(f"    Runtime/Build: {dep.name}")

# Clean up the dummy workspace
shutil.rmtree(temp_dir)

view raw JSON →