Debian Codegraph @

dhpython/build/types.py

raw symbols SCIP
1 # Copyright © 2025 Stefano Rivera <[email protected]>
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
9 #
10 # The above copyright notice and this permission notice shall be included in
11 # all copies or substantial portions of the Software.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 # THE SOFTWARE.
20
21 from dataclasses import asdict, dataclass, field, replace
22 from typing import Any
23 from shlex import quote
24
25 from dhpython.interpreter import Interpreter
26 from dhpython.version import Version
27
28
29 @dataclass
30 class Args:
31 ENV: dict[str, str]
32 args: str
33 autopkgtest: bool
34 build_dir: str
35 destdir: str
36 dir: str
37 home_dir: str
38 install_dir: str
39 interpreter: Interpreter
40 package: str
41 version: Version
42 # during tests only:
43 test_dir: str | None = None
44 # Injected by base:
45 ignore_no_tests: bool = False
46 wheel: str | None = None
47 # Injected by plugin_distutils:
48 setup_py: str | None = None
49 parallel: int = 1
50
51 def format(self, template: str) -> str:
52 return template.format(**self.as_dict())
53
54 def format_quoted(self, template: str) -> str:
55 quoted = self.as_dict()
56 for k, v in quoted.items():
57 if v and (k in ('dir', 'destdir') or k.endswith('_dir')):
58 assert isinstance(v, str)
59 quoted[k] = quote(v)
60 return template.format(**quoted)
61
62 def as_dict(self) -> dict[str, Any]:
63 return asdict(self)
64
65
66 @dataclass
67 class Context:
68 ENV: dict[str, str]
69 dir: str
70 destdir: str
71 args: dict[str, str] = field(default_factory=dict)
72
73 def copy(self) -> "Context":
74 return replace(self)