Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Augments colcon pkg with dependencies from pyproject file. #38

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)