Coverage for src/iso_freeze/lib.py: 60%

20 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-08-01 11:38 +0200

1"""Data structures and base functionality required across multiple modules.""" 

2 

3import subprocess 

4import sys 

5 

6from dataclasses import dataclass 

7from pathlib import Path 

8from typing import Any, Union, Optional 

9 

10 

11@dataclass 

12class PyPackage: 

13 """Class to capture relevant information about Python packages.""" 

14 

15 name: str 

16 version: str 

17 requested: bool = False 

18 hash: Optional[str] = None 

19 

20 

21def run_pip(command: list[Union[str, Path]], check_output: bool) -> Any: 

22 """Run specified pip command with subprocess and return results, if any. 

23 

24 Arguments: 

25 command -- Pip command to execute (list[Union[str, Path]]) 

26 

27 Keyword Arguments: 

28 check_output -- Whether to call subprocess.check_output (default: {False}) 

29 

30 Returns: 

31 Output of pip command, if any (Any) 

32 """ 

33 try: 

34 if check_output: 

35 return subprocess.check_output(command, encoding="utf-8") 

36 else: 

37 subprocess.run(command) 

38 return None 

39 except subprocess.CalledProcessError as error: 

40 error.output 

41 sys.exit()