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

Add get_package_condition_context function #182

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions src/rosdistro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,29 @@ def get_distribution_cache(index, dist_name):
return DistributionCache(dist_name, data)


def get_package_condition_context(index, dist_name):
if dist_name not in index.distributions.keys():
raise RuntimeError("Unknown distribution: '{0}'. Valid distribution names are: {1}".format(dist_name, ', '.join(sorted(index.distributions.keys()))))

condition_context = {
'ROS_DISTRO': dist_name,
}

dist = index.distributions[dist_name]
python_version = dist.get('python_version')
if python_version:
condition_context['ROS_PYTHON_VERSION'] = str(python_version)

ros_version = {
'ros1': '1',
'ros2': '2',
}.get(dist.get('distribution_type'))
if ros_version:
condition_context['ROS_VERSION'] = ros_version

return condition_context


# internal

def _get_dist_file_data(index, dist_name, type_):
Expand Down
1 change: 1 addition & 0 deletions test/files/index_v4.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ distributions:
distribution_cache: foo/release-cache.yaml
distribution_status: active
distribution_type: ros1
python_version: 3
type: index
version: 4
13 changes: 13 additions & 0 deletions test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from rosdistro import get_distribution_files
from rosdistro import get_index
from rosdistro import get_index_url
from rosdistro import get_package_condition_context

from . import path_to_url

Expand Down Expand Up @@ -96,3 +97,15 @@ def test_get_index_from_http_with_query_parameters():
get_distribution_file(i, 'foo')
finally:
proc.terminate()


def test_get_condition_context():
url = path_to_url(os.path.join(FILES_DIR, 'index_v4.yaml'))
i = get_index(url)
condition_context = get_package_condition_context(i, 'foo')

assert condition_context == {
'ROS_DISTRO': 'foo',
'ROS_PYTHON_VERSION': '3',
'ROS_VERSION': '1',
}
Loading