Skip to content

Commit

Permalink
Add opam support (fixes #1278)
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDmi3 committed Jul 23, 2024
1 parent d40b2aa commit cea98d2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions repology-schemacheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
'nix',
'noir',
'npackd',
'opam',
'openbsd',
'openindiana',
'openmamba',
Expand Down
2 changes: 2 additions & 0 deletions repology/packagemaker/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ class NameType:

SERPENTOS_NAME: ClassVar[int] = GENERIC_SRC_NAME

OPAM_NAME: ClassVar[int] = GENERIC_SRC_NAME


@dataclass
class _NameMapping:
Expand Down
31 changes: 31 additions & 0 deletions repology/parsers/parsers/opam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (C) 2024 Dmitry Marakasov <[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.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
24 changes: 24 additions & 0 deletions repos.d/modules/opam.yaml
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit cea98d2

Please sign in to comment.