Skip to content

Commit

Permalink
Update conda parser (#518)
Browse files Browse the repository at this point in the history
Conda repos are still not enabled because there's still no way to
distinguish python modules
  • Loading branch information
AMDmi3 committed Oct 12, 2022
1 parent 611fb29 commit eda217a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
32 changes: 26 additions & 6 deletions repology/parsers/parsers/conda.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2018-2019 Dmitry Marakasov <[email protected]>
# Copyright (C) 2018-2019,2022 Dmitry Marakasov <[email protected]>
#
# This file is part of repology
#
Expand All @@ -15,21 +15,41 @@
# You should have received a copy of the GNU General Public License
# along with repology. If not, see <http://www.gnu.org/licenses/>.

import json
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 repology.parsers.json import iter_json_dict


class CondaRepodataJsonParser(Parser):
def iter_parse(self, path: str, factory: PackageFactory) -> Iterable[PackageMaker]:
with open(path, 'r', encoding='utf-8') as jsonfile:
for pkgfilename, pkgdata in json.load(jsonfile)['packages'].items():
pkg = factory.begin(pkgfilename)

for pkgfilename, pkgdata in iter_json_dict(path, ('packages', None)):
with factory.begin(pkgfilename) as pkg:
pkg.add_name(pkgdata['name'], NameType.GENERIC_GEN_NAME)
pkg.set_version(pkgdata['version'])
pkg.add_licenses(pkgdata.get('license', ''))

yield pkg


class CondaChanneldataJsonParser(Parser):
def iter_parse(self, path: str, factory: PackageFactory) -> Iterable[PackageMaker]:
for pkgname, pkgdata in iter_json_dict(path, ('packages', None)):
with factory.begin(pkgname) as pkg:
pkg.add_name(pkgname, NameType.GENERIC_SRC_NAME)
if 'version' not in pkgdata:
pkg.log('version missing', Logger.ERROR)
continue

pkg.set_version(pkgdata['version'])
pkg.add_licenses(pkgdata.get('license'))
pkg.set_summary(pkgdata.get('summary'))
pkg.add_links(LinkType.UPSTREAM_DOCUMENTATION, pkgdata.get('doc_url'), pkgdata.get('doc_source_url'))
pkg.add_links(LinkType.UPSTREAM_HOMEPAGE, pkgdata.get('home'))
pkg.add_links(LinkType.UPSTREAM_DOWNLOAD, pkgdata.get('source_url'))
pkg.add_links(LinkType.UPSTREAM_HOMEPAGE, pkgdata.get('dev_url'))

yield pkg
14 changes: 6 additions & 8 deletions repos.d/conda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
family: conda
minpackages: 1
sources:
- name: [noarch, linux-32, linux-64, osx-64, win-32, win-64]
- name: channeldata.json
fetcher:
class: FileFetcher
url: 'https://conda.anaconda.org/conda-forge/{source}/repodata.json'
url: 'https://conda.anaconda.org/conda-forge/channeldata.json'
parser:
class: CondaRepodataJsonParser
subrepo: '{source}'
class: CondaChanneldataJsonParser
repolinks:
- desc: conda-forge home
url: https://conda-forge.org/
Expand All @@ -25,13 +24,12 @@
family: conda
minpackages: 1
sources:
- name: [noarch, linux-32, linux-64, osx-32, osx-64, win-32, win-64]
- name: channeldata.json
fetcher:
class: FileFetcher
url: 'https://conda.anaconda.org/bioconda/{source}/repodata.json'
url: 'https://conda.anaconda.org/bioconda/channeldata.json'
parser:
class: CondaRepodataJsonParser
subrepo: '{source}'
class: CondaChanneldataJsonParser
repolinks:
- desc: Bioconda home
url: https://bioconda.github.io/
Expand Down

0 comments on commit eda217a

Please sign in to comment.