From cea98d2717c1483dded8193907e03a1c7e67ef61 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Tue, 23 Jul 2024 18:28:13 +0300 Subject: [PATCH] Add opam support (fixes #1278) --- repology-schemacheck.py | 1 + repology/packagemaker/names.py | 2 ++ repology/parsers/parsers/opam.py | 31 +++++++++++++++++++++++++++++++ repos.d/modules/opam.yaml | 24 ++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 repology/parsers/parsers/opam.py create mode 100644 repos.d/modules/opam.yaml diff --git a/repology-schemacheck.py b/repology-schemacheck.py index 03601100a..0d84f4b4a 100755 --- a/repology-schemacheck.py +++ b/repology-schemacheck.py @@ -87,6 +87,7 @@ 'nix', 'noir', 'npackd', + 'opam', 'openbsd', 'openindiana', 'openmamba', diff --git a/repology/packagemaker/names.py b/repology/packagemaker/names.py index c5741f4ad..0ce4a8a6c 100644 --- a/repology/packagemaker/names.py +++ b/repology/packagemaker/names.py @@ -240,6 +240,8 @@ class NameType: SERPENTOS_NAME: ClassVar[int] = GENERIC_SRC_NAME + OPAM_NAME: ClassVar[int] = GENERIC_SRC_NAME + @dataclass class _NameMapping: diff --git a/repology/parsers/parsers/opam.py b/repology/parsers/parsers/opam.py new file mode 100644 index 000000000..82e2cc951 --- /dev/null +++ b/repology/parsers/parsers/opam.py @@ -0,0 +1,31 @@ +# Copyright (C) 2024 Dmitry Marakasov +# +# 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 . + +from typing import Iterable + +from repology.packagemaker import NameType, PackageFactory, PackageMaker +from repology.parsers import Parser +from repology.parsers.json import iter_json_list + + +class OpamStatsJsonParser(Parser): + def iter_parse(self, path: str, factory: PackageFactory) -> Iterable[PackageMaker]: + for pkgdata in iter_json_list(path, (None,)): + with factory.begin() as pkg: + pkg.add_name(pkgdata['name'], NameType.OPAM_NAME) + pkg.set_version(pkgdata['versions'][-1]['version']) + yield pkg diff --git a/repos.d/modules/opam.yaml b/repos.d/modules/opam.yaml new file mode 100644 index 000000000..da7d2ec32 --- /dev/null +++ b/repos.d/modules/opam.yaml @@ -0,0 +1,24 @@ +########################################################################### +# opam (OCaml) +########################################################################### +- name: opam + type: modules + desc: opam + family: opam + ruleset: opam + minpackages: 4000 + sources: + - name: stats.json + fetcher: + class: FileFetcher + url: https://opam.ocaml.org/json/stats.json + parser: + class: OpamStatsJsonParser + shadow: true + repolinks: + - desc: opam - OCaml Package Manager + url: https://opam.ocaml.org/ + packagelinks: + - type: PROJECT_HOMEPAGE + url: 'https://opam.ocaml.org/packages/{srcname}/' + groups: [all, production]