Coverage for pipxl/data.py: 100%
29 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-28 21:03 +0100
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-28 21:03 +0100
1# SPDX-FileCopyrightText: 2022-present Jeroen van Zundert <mail@jeroenvanzundert.nl>
2#
3# SPDX-License-Identifier: MIT
5from __future__ import annotations
7from dataclasses import dataclass
10@dataclass
11class ReqFileEntry:
12 name: str
13 version: str
14 requires: dict[str, str]
15 required_by: dict[str, str]
16 url: str
17 hash: str | None # not available for local packages
18 requested: bool
19 license: str | None # only available if uploaded to PyPi
21 def to_string(self, add_hash: bool = True) -> str:
22 out = f"{self.name}=={self.version}"
24 # NOTE: use four spaces, not tabs, to indent, otherwise pip install breaks
25 if add_hash and self.hash is not None:
26 out += f" \\\n --hash={self.hash.replace('=',':')}"
28 for req_by, specifier in self.required_by.items():
29 out += f"\n # via {req_by}"
30 if specifier:
31 out += f" [{specifier}]"
33 return out
36@dataclass
37class Environment:
38 pip_version: str
39 platform_python_implementation: str
40 implementation_version: str
41 platform_system: str
42 platform_release: str
43 platform_machine: str