Repository navigation
Expand file tree
/
Copy pathconfig.py
More file actions
105 lines (81 loc) · 3.23 KB
/
Copy pathconfig.py
File metadata and controls
105 lines (81 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import dataclasses
import pathlib
@dataclasses.dataclass
class PcFileConfig:
"""
Contents of [[tool.hatch.build.hooks.nativelib.pcfile]] items
"""
pcfile: str
"""
File to write pkgconf file to (relative to pyproject.toml)
"""
description: str | None = None
"""Description of this package. If not specified, uses the first line of the package description."""
name: str | None = None
"""Name of this package. If not specified, is basename of pcfile without extension"""
version: str | None = None
"""If not specified, set to package version"""
includedir: str | None = None
"""Where include files can be found (relative to pyproject.toml)"""
libdir: str | None = None
"""Where the library is located. If not specified, it is next to pcfile"""
shared_libraries: list[str] | None = None
"""Name of shared libraries located in libdir (without extension)"""
libs_private: str | None = None
"""The link flags for private libraries not exposed to applications"""
requires: list[str] | None = None
"""
Names of other packages this package requires. They must be installed
at build time.
"""
requires_private: list[str] | None = None
"""
Names of private packages this package requires. They must be installed
at build time.
"""
extra_cflags: str | None = None
"""A list of extra compiler flags to be added to Cflags after header search path"""
extra_link_flags: str | None = None
"""A list of extra link flags to be added to Libs"""
variables: dict[str, str] | None = None
"""
Custom variables to add to the generated file. Prefix, libdir, includedir must not be specified."""
init_module: str = "auto"
"""
If specified, the name of the python module that will be written next to
the .pc file which will load the shared_libraries
"""
enable_if: str | None = None
"""
This is a PEP 508 environment marker specification.
This pcfile will only be generated if the environment marker matches the current
build environment
"""
def get_name(self) -> str:
if self.name:
return self.name
return self.get_pc_path().name[:-3]
def get_out_path(self) -> pathlib.Path:
return self.get_pc_path().parent
def get_pc_path(self) -> pathlib.Path:
pc_path = pathlib.PurePosixPath(self.pcfile)
if pc_path.is_absolute():
raise ValueError(f"pcfile must not be absolute (is {pc_path})")
if not pc_path.name.endswith(".pc"):
raise ValueError(f"pcfile must end with .pc (is {pc_path})")
return pathlib.Path(pc_path)
def get_init_module(self) -> str:
if self.init_module == "auto":
name = self.get_pc_path().name[:-3]
name = name.replace("-", "_").replace(".", "_")
module = f"_init_{name}"
else:
module = self.init_module
if not module.isidentifier():
raise ValueError(
f"init_module must be a valid python identifier (got {module})"
)
return module
def get_init_module_path(self) -> pathlib.Path:
module = self.get_init_module()
return self.get_out_path() / f"{module}.py"