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 ROS support #1455

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions repology-schemacheck.py
Original file line number Diff line number Diff line change
@@ -107,6 +107,7 @@
'pypi',
'ravenports',
'reactos',
'ros',
'rosa',
'rubygems',
'rudix',
2 changes: 2 additions & 0 deletions repology/packagemaker/names.py
Original file line number Diff line number Diff line change
@@ -246,6 +246,8 @@ class NameType:

OPAM_NAME: ClassVar[int] = GENERIC_SRC_NAME

ROS_NAME: ClassVar[int] = GENERIC_SRC_NAME


@dataclass
class _NameMapping:
80 changes: 80 additions & 0 deletions repology/parsers/parsers/ros.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Copyright (C) 2024 Guilhem Saurel <[email protected]>
#
# This file is part of repology
#
# repology is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# repology is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with repology. If not, see <http://www.gnu.org/licenses/>.

from typing import Iterable

from repology.logger import Logger
from repology.package import LinkType
from repology.packagemaker import NameType, PackageFactory, PackageMaker
from repology.parsers import Parser
from yaml import safe_load


def ros_extract_recipe_url(key, /, *, url, tags, version, **kwargs):
release = tags['release'].format(
package=key,
version=version,
upstream_version=version,
)

if 'github.com' in url:
return url.removesuffix('.git') + f'/blob/{release}/package.xml'
if 'gitlab' in url:
return url.removesuffix('.git') + f'/-/blob/{release}/package.xml'
if 'bitbucket' in url:
# It is not possible to construct a bitbucket url for a file
# on a specific tag
return
err = f'ROS package {key} is neither on github, gitlab, or bitbucket'
raise RuntimeError(err)


class RosYamlParser(Parser):
def iter_parse(self, path: str, factory: PackageFactory) -> Iterable[PackageMaker]:
with open(path) as f:
data = safe_load(f)
for key, packagedata in data['repositories'].items():
with factory.begin(key) as pkg:
# Some included packages are not yet released,
# and only available as source
if 'release' not in packagedata:
pkg.log(f'dropping {key}: no release', severity=Logger.ERROR)
continue

release = packagedata['release']

if 'version' not in release:
pkg.log(f'dropping {key}: has no version.', severity=Logger.ERROR)
continue

pkg.add_name(key, NameType.ROS_NAME)
pkg.set_version(release['version'].split('-')[0])

if recipe_url := ros_extract_recipe_url(key, **release):
pkg.add_links(LinkType.PACKAGE_RECIPE, recipe_url)
else:
pkg.log(f'{key} has no known recipe url', severity=Logger.WARNING)

if source := packagedata.get('source'):
pkg.add_links(LinkType.UPSTREAM_HOMEPAGE, source['url'])
else:
pkg.log(f'{key} has no source', severity=Logger.WARNING)

if doc := packagedata.get('doc'):
pkg.add_links(LinkType.UPSTREAM_DOCUMENTATION, doc['url'])

yield pkg
54 changes: 54 additions & 0 deletions repos.d/ros.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
###########################################################################
# ROS
###########################################################################
{% macro ros(version, name, minpackages, valid_till) %}
- name: ros_{{version}}_{{name}}
type: repository
desc: ROS {% if version > 1 %}{{ version }} {% endif %}{{name}}
statsgroup: ros
family: ros
ruleset: ros
color: '22314E'
minpackages: {{minpackages}}
{% if valid_till %}
valid_till: {{valid_till}}
{% endif %}
default_maintainer: fallback-mnt-ros@repology
sources:
- name: distribution.yaml
fetcher:
class: FileFetcher
url: https://raw.githubusercontent.com/ros/rosdistro/refs/heads/master/{{name}}/distribution.yaml
parser:
class: RosYamlParser
repolinks:
- desc: ROS home
url: https://ros.org/
- desc: ROS packages
url: https://index.ros.org/
- desc: {{name}} GitHub repository
url: https://github.com/ros/rosdistro/tree/master/{{name}}
- desc: {{name}} home
url: https://{% if version > 1 %}docs.ros.org/en{% else %}wiki.ros.org{% endif %}/{{name}}
groups: [ all, production, ros, ros{{version}} ]
{% endmacro %}

{{ ros(1, 'groovy', minpackages=200, valid_till='2014-07-31') }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the note, it may make sense not to add EoLed repos of that would simplify code (e.g. by dropping legacy conditions for them).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not have to write anything specific for these old things, and it seem to work so I included them. But I don't really need those.

{{ ros(1, 'hydro', minpackages=550, valid_till='2015-06-30') }}
{{ ros(1, 'indigo', minpackages=950, valid_till='2019-04-30') }}
{{ ros(1, 'jade', minpackages=450, valid_till='2017-05-31') }}
{{ ros(1, 'kinetic', minpackages=950, valid_till='2021-04-30') }}
{{ ros(1, 'lunar', minpackages=350, valid_till='2019-05-31') }}
{{ ros(1, 'melodic', minpackages=850, valid_till='2023-06-27') }}
{{ ros(1, 'noetic', minpackages=700, valid_till='2025-05-31') }}

{{ ros(2, 'ardent', minpackages=50, valid_till='2018-12-31') }}
{{ ros(2, 'bouncy', minpackages=50, valid_till='2019-06-30') }}
{{ ros(2, 'crystal', minpackages=100, valid_till='2019-12-31') }}
{{ ros(2, 'dashing', minpackages=200, valid_till='2021-05-31') }}
{{ ros(2, 'eloquent', minpackages=200, valid_till='2020-11-30') }}
{{ ros(2, 'foxy', minpackages=450, valid_till='2023-05-31') }}
{{ ros(2, 'galactic', minpackages=350, valid_till='2022-11-30') }}
{{ ros(2, 'humble', minpackages=650, valid_till='2027-05-31') }}
{{ ros(2, 'iron', minpackages=500, valid_till='2024-11-30') }}
{{ ros(2, 'jazzy', minpackages=550, valid_till='2029-05-31') }}