Skip to content

Commit

Permalink
Add package version to metadata (#45)
Browse files Browse the repository at this point in the history
The package version is typically read during the augmentation phase,
but this package doesn't have one (yet). Since the dependencies are
already being read during identification, go ahead and read the version
then as well.
  • Loading branch information
cottsay authored Dec 5, 2024
1 parent b12c637 commit 27c0b85
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions colcon_cargo/package_identification/cargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def identify(self, metadata): # noqa: D102
metadata.type = 'cargo'
if metadata.name is None:
metadata.name = data['name']
metadata.metadata['version'] = data['version']

metadata.dependencies['build'] |= data['depends']
metadata.dependencies['run'] |= data['depends']

Expand Down Expand Up @@ -78,6 +80,7 @@ def extract_data(cargo_toml):
toml_name_attr = extract_project_name(content)
data['name'] = toml_name_attr if toml_name_attr is not None else \
cargo_toml.parent.name
data['version'] = extract_project_version(content)

depends = extract_dependencies(content)
# exclude self references
Expand All @@ -100,6 +103,20 @@ def extract_project_name(content):
return None


def extract_project_version(content):
"""
Extract the Cargo project version from the Cargo.toml file.
:param str content: The Cargo.toml parsed dictionary
:returns: The project version, otherwise None
:rtype: str
"""
try:
return content['package']['version']
except KeyError:
return None


def extract_dependencies(content):
"""
Extract the dependencies from the Cargo.toml file.
Expand Down

0 comments on commit 27c0b85

Please sign in to comment.