Skip to content

Commit

Permalink
Augments colcon pkg with dependencies from pyproject file. (#38)
Browse files Browse the repository at this point in the history
Related to #37 

### Summary

This PR introduces the ability to indicate the colcon/ros dependencies of the project via the `pyproject.toml` file.
Otherwise, dependencies for the package aren't loaded up, and the ordering when building isn't respected

### Use

Add to `pyproject.toml` the following section:

```toml
[colcon-package]
depend = ["another_pkg_1"]   # This will add to both `build_depend` and `exec_depend` following `package.xml` standards
build_depend = ["another_pkg_2"]
exec_depend = ["another_pkg_3"]
test_depend = ["another_pkg_4"]
```
  • Loading branch information
francocipollone authored Jul 10, 2023
1 parent 25a9b95 commit 1e7f10e
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions colcon_poetry_ros/package_augmentation/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
class PoetryPackageAugmentation(PackageAugmentationExtensionPoint):
"""Augment Python packages that use Poetry by referencing the pyproject.toml file"""

_PACKAGE_SECTION = "tool.colcon-poetry-ros.dependencies"
_DEPEND_LIST = "depend"
_BUILD_DEPEND_LIST = "build_depend"
_EXEC_DEPEND_LIST = "exec_depend"
_TEST_DEPEND_LIST = "test_depend"
_PACKAGE_BUILD_CATEGORY = "build"
_PACKAGE_EXEC_CATEGORY = "run"
_PACKAGE_TEST_CATEGORY = "test"

def __init__(self):
super().__init__()
satisfies_version(
Expand All @@ -39,21 +48,34 @@ def augment_package(
pyproject_toml = desc.path / "pyproject.toml"
pyproject = toml.loads(pyproject_toml.read_text())

# See https://www.python.org/dev/peps/pep-0518/#build-system-table
if "build-system" in pyproject and "requires" in pyproject["build-system"]:
build_deps = pyproject["build-system"]["requires"]
# Parses dependencies to other colcon packages indicated in the pyproject.toml file.
if self._PACKAGE_SECTION in pyproject and self._BUILD_DEPEND_LIST in pyproject[self._PACKAGE_SECTION]:
build_depend = set(pyproject[self._PACKAGE_SECTION][self._BUILD_DEPEND_LIST])
else:
build_depend = set()

if self._PACKAGE_SECTION in pyproject and self._EXEC_DEPEND_LIST in pyproject[self._PACKAGE_SECTION]:
exec_depend = set(pyproject[self._PACKAGE_SECTION][self._EXEC_DEPEND_LIST])
else:
exec_depend = set()

if self._PACKAGE_SECTION in pyproject and self._TEST_DEPEND_LIST in pyproject[self._PACKAGE_SECTION]:
test_depend = set(pyproject[self._PACKAGE_SECTION][self._TEST_DEPEND_LIST])
else:
build_deps = set()
test_depend = set()

run_deps = project.get_dependencies(config.run_depends_extras.get())
test_deps = project.get_dependencies(config.test_depends_extras.get())
# Depend add the deps to the build and exec depends
if self._PACKAGE_SECTION in pyproject and self._DEPEND_LIST in pyproject[self._PACKAGE_SECTION]:
depends = pyproject[self._PACKAGE_SECTION][self._DEPEND_LIST]
build_depend.update(depends)
exec_depend.update(depends)

desc.dependencies["build_depends"] = set(
create_dependency_descriptor(dep) for dep in build_deps
desc.dependencies[self._PACKAGE_BUILD_CATEGORY] = set(
create_dependency_descriptor(dep) for dep in build_depend
)
desc.dependencies["run_depends"] = set(
create_dependency_descriptor(dep) for dep in run_deps
desc.dependencies[self._PACKAGE_EXEC_CATEGORY] = set(
create_dependency_descriptor(dep) for dep in exec_depend
)
desc.dependencies["test_depends"] = set(
create_dependency_descriptor(dep) for dep in test_deps
desc.dependencies[self._PACKAGE_TEST_CATEGORY] = set(
create_dependency_descriptor(dep) for dep in test_depend
)

0 comments on commit 1e7f10e

Please sign in to comment.