Coverage for pipxl/data.py: 100%

1# SPDX-FileCopyrightText: 2022-present Jeroen van Zundert <mail@jeroenvanzundert.nl>

2#

3# SPDX-License-Identifier: MIT

4

5 from __future__ import annotations

6

7 from dataclasses import dataclass

8

9

10@dataclass

11 class 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

20

21 def to_string(self, add_hash: bool = True) -> str:

22 out = f"{self.name}=={self.version}"

23

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('=',':')}"

27

28 for req_by, specifier in self.required_by.items():

29 out += f"\n # via {req_by}"

30 if specifier:

31 out += f" [{specifier}]"

32

33 return out

34

35

36@dataclass

37 class 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