Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/nixguix/loader.py
Show All 20 Lines | |||||
def retrieve_sources(url: str) -> Dict[str, Any]: | def retrieve_sources(url: str) -> Dict[str, Any]: | ||||
response = requests.get(url, | response = requests.get(url, | ||||
allow_redirects=True) | allow_redirects=True) | ||||
if response.status_code != 200: | if response.status_code != 200: | ||||
raise ValueError("Got %d HTTP code on %s", | raise ValueError("Got %d HTTP code on %s", | ||||
response.status_code, url) | response.status_code, url) | ||||
return json.loads(response.content.decode('utf-8')) | sources = json.loads(response.content.decode('utf-8')) | ||||
byIntegrity = {} | |||||
for s in sources['sources']: | |||||
byIntegrity[s['integrity']] = s['url'] | |||||
sources['byIntegrity'] = byIntegrity | |||||
return sources | |||||
class NixGuixLoader(PackageLoader): | class NixGuixLoader(PackageLoader): | ||||
"""Load sources from a sources.json file. This loader is used to load | """Load sources from a sources.json file. This loader is used to load | ||||
sources used by functional package manager (eg. Nix and Guix). | sources used by functional package manager (eg. Nix and Guix). | ||||
""" | """ | ||||
visit_type = 'nixguix' | visit_type = 'nixguix' | ||||
def __init__(self, url): | def __init__(self, url): | ||||
super().__init__(url=url) | super().__init__(url=url) | ||||
s = retrieve_sources(url) | s = retrieve_sources(url) | ||||
self.sources = s['sources'] | self.sources = s['byIntegrity'] | ||||
self.provider_url = url | self.provider_url = url | ||||
# The revision used to create the sources.json file. For Nix, | # The revision used to create the sources.json file. For Nix, | ||||
# this revision belongs to the github.com/nixos/nixpkgs | # this revision belongs to the github.com/nixos/nixpkgs | ||||
# repository | # repository | ||||
self.revision = s['revision'] | self.revision = s['revision'] | ||||
# Note: this could be renamed get_artifacts in the PackageLoader | # Note: this could be renamed get_artifacts in the PackageLoader | ||||
# base class. | # base class. | ||||
def get_versions(self): | def get_versions(self): | ||||
return self.sources.keys() | |||||
# Note: this could be renamed get_artifact_info in the PackageLoader | |||||
# base class. | |||||
def get_package_info(self, integrity): | |||||
# TODO: try all mirrors and not only the first one. A source | # TODO: try all mirrors and not only the first one. A source | ||||
# can be fetched from several urls, called mirrors. We | # can be fetched from several urls, called mirrors. We | ||||
# currently only use the first one, but if the first one | # currently only use the first one, but if the first one | ||||
# fails, we should try the second one and so on. | # fails, we should try the second one and so on. | ||||
return [s['url'][0] for s in self.sources] | url = self.sources[integrity][0] | ||||
yield integrity, {'url': url, | |||||
# Note: this could be renamed get_artifact_info in the PackageLoader | 'raw': { | ||||
# base class. | 'url': url, | ||||
def get_package_info(self, source): | 'integrity': integrity}} | ||||
# TODO: we need to provide the sha256 of the source also | |||||
yield source, {'url': source, 'raw': {'url': source}} | |||||
def resolve_revision_from( | def resolve_revision_from( | ||||
self, known_artifacts: Dict, artifact_metadata: Dict) \ | self, known_artifacts: Dict, artifact_metadata: Dict) \ | ||||
-> Optional[bytes]: | -> Optional[bytes]: | ||||
for rev_id, known_artifact in known_artifacts.items(): | for rev_id, known_artifact in known_artifacts.items(): | ||||
known_url = known_artifact['extrinsic']['raw']['url'] | known_integrity = known_artifact['extrinsic']['raw']['integrity'] | ||||
if artifact_metadata['url'] == known_url: | if artifact_metadata['integrity'] == known_integrity: | ||||
return rev_id | return rev_id | ||||
ardumont: I would expect the coverage to currently be green here... | |||||
Done Inline ActionsI locally put a breakpoint line 82 and the breakpoint has been reached. So, this code is executed by the test test_loader_incremental. lewo: I locally put a breakpoint line 82 and the breakpoint has been reached. So, this code is… | |||||
return None | return None | ||||
def extra_branches(self) -> Dict[bytes, Mapping[str, Any]]: | def extra_branches(self) -> Dict[bytes, Mapping[str, Any]]: | ||||
"""We add a branch to the snapshot called 'evaluation' pointing to the | """We add a branch to the snapshot called 'evaluation' pointing to the | ||||
revision used to generate the sources.json file. This revision | revision used to generate the sources.json file. This revision | ||||
is specified in the sources.json file itself. For the nixpkgs | is specified in the sources.json file itself. For the nixpkgs | ||||
origin, this revision is coming from the | origin, this revision is coming from the | ||||
github.com/nixos/nixpkgs repository. | github.com/nixos/nixpkgs repository. | ||||
Show All 37 Lines |
I would expect the coverage to currently be green here...