|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | | -import glob |
4 | | -from setuptools import Extension, setup |
5 | 3 | import sys |
6 | 4 | import os |
7 | | -from os.path import join |
8 | | -from contextlib import suppress |
| 5 | +import glob |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +from setuptools import Extension, setup |
9 | 9 | from Cython.Build import cythonize |
10 | | -import os.path |
11 | 10 |
|
12 | 11 |
|
13 | 12 | # Library linkage |
14 | | -lib_dirs = ['.', '/usr/lib64', '/usr/lib', '/usr/local/lib'] |
15 | | -include_dirs = [] |
| 13 | +lib_dirs: list[str] = ['.', '/usr/lib64', '/usr/lib', '/usr/local/lib'] |
| 14 | +include_dirs: list[str] = [] |
16 | 15 |
|
17 | | -with suppress(KeyError): |
18 | | - userspace_src = os.environ["USERSPACE_SRC"] |
19 | | - include_dirs.insert(0, userspace_src + "/libsepol/include") |
20 | | - include_dirs.insert(1, userspace_src + "/libselinux/include") |
21 | | - lib_dirs.insert(0, userspace_src + "/libsepol/src") |
22 | | - lib_dirs.insert(1, userspace_src + "/libselinux/src") |
| 16 | +userspace_src = os.getenv("USERSPACE_SRC", "") |
| 17 | +if userspace_src: |
| 18 | + userspace_path = Path(userspace_src) |
| 19 | + include_dirs.insert(0, str(userspace_path / "libsepol/include")) |
| 20 | + include_dirs.insert(1, str(userspace_path / "libselinux/include")) |
| 21 | + lib_dirs.insert(0, str(userspace_path / "libsepol/src")) |
| 22 | + lib_dirs.insert(1, str(userspace_path / "libselinux/src")) |
23 | 23 |
|
24 | | -if sys.platform.startswith('darwin'): |
25 | | - macros=[('DARWIN',1)] |
26 | | -else: |
27 | | - macros=[] |
| 24 | +macros: list[tuple[str, str | int]] = [('DARWIN',1)] if sys.platform.startswith('darwin') else [] |
28 | 25 |
|
29 | 26 | # Code coverage. Enable this to get coverage in the cython code. |
30 | | -enable_coverage = bool(os.environ.get("SETOOLS_COVERAGE", False)) |
| 27 | +enable_coverage = bool(os.getenv("SETOOLS_COVERAGE", "")) |
31 | 28 | if enable_coverage: |
32 | 29 | macros.append(("CYTHON_TRACE", 1)) |
33 | 30 |
|
34 | | -cython_annotate = bool(os.environ.get("SETOOLS_ANNOTATE", False)) |
| 31 | +cython_annotate = bool(os.getenv("SETOOLS_ANNOTATE", "")) |
35 | 32 |
|
36 | 33 | ext_py_mods = [Extension('setools.policyrep', ['setools/policyrep.pyx'], |
37 | 34 | include_dirs=include_dirs, |
|
53 | 50 | '-Wwrite-strings', |
54 | 51 | '-fno-exceptions'])] |
55 | 52 |
|
56 | | -installed_data = [('share/man/man1', glob.glob("man/*.1"))] |
57 | | - |
58 | | -linguas = ["ru"] |
59 | | - |
60 | | -with suppress(KeyError): |
61 | | - linguas = os.environ["LINGUAS"].split(" ") |
| 53 | +linguas: set[Path] = set(Path(p) for p in os.getenv("LINGUAS", "").split(" ") if p) |
| 54 | +if not linguas: |
| 55 | + linguas.add(Path("ru")) |
| 56 | +linguas.add(Path(".")) |
62 | 57 |
|
| 58 | +base_source_path = Path("man") # below source root |
| 59 | +base_target_path = Path("share/man") # below prefixdir, usually /usr or /usr/local |
| 60 | +installed_data = list[tuple]() |
63 | 61 | for lang in linguas: |
64 | | - if lang and os.path.exists(join("man", lang)): |
65 | | - installed_data.append((join('share/man', lang, 'man1'), glob.glob(join("man", lang, "*.1")))) |
| 62 | + source_path = base_source_path / lang |
| 63 | + if source_path.exists(): |
| 64 | + for i in range(1, 9): |
| 65 | + installed_data.append((base_target_path / lang / f"man{i}", |
| 66 | + glob.glob(str(source_path / f"*.{i}")))) |
66 | 67 |
|
67 | 68 | # see pyproject.toml for most package options. |
68 | 69 | setup(data_files=installed_data, |
|
0 commit comments