|
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 | | -setup(name='setools', |
68 | | - version='4.6.0-dev', |
69 | | - description='SELinux policy analysis tools.', |
70 | | - author='Chris PeBenito', |
71 | | - author_email='pebenito@ieee.org', |
72 | | - url='https://github.com/SELinuxProject/setools', |
73 | | - packages=['setools', 'setools.checker', 'setools.diff', 'setoolsgui', 'setoolsgui.widgets', |
74 | | - 'setoolsgui.widgets.criteria', 'setoolsgui.widgets.details', |
75 | | - 'setoolsgui.widgets.models', 'setoolsgui.widgets.views'], |
76 | | - scripts=['apol', 'sediff', 'seinfo', 'seinfoflow', 'sesearch', 'sedta', 'sechecker'], |
77 | | - data_files=installed_data, |
78 | | - package_data={'': ['*.css', '*.html'], |
79 | | - 'setools': ['perm_map', 'policyrep.pyi', 'py.typed']}, |
| 68 | +# see pyproject.toml for most package options. |
| 69 | +setup(data_files=installed_data, |
80 | 70 | ext_modules=cythonize(ext_py_mods, include_path=['setools/policyrep'], |
81 | 71 | annotate=cython_annotate, |
82 | 72 | compiler_directives={"language_level": 3, |
83 | 73 | "c_string_type": "str", |
84 | 74 | "c_string_encoding": "ascii", |
85 | | - "linetrace": enable_coverage}), |
86 | | - test_suite='tests', |
87 | | - license='GPLv2+, LGPLv2.1+', |
88 | | - classifiers=[ |
89 | | - 'Environment :: Console', |
90 | | - 'Environment :: X11 Applications :: Qt', |
91 | | - 'Intended Audience :: Information Technology', |
92 | | - 'Topic :: Security', |
93 | | - 'Topic :: Utilities', |
94 | | - ], |
95 | | - keywords='SELinux SETools policy analysis tools seinfo sesearch sediff sedta seinfoflow apol', |
96 | | - python_requires='>=3.10', |
97 | | - # setup also requires libsepol and libselinux |
98 | | - # C libraries and headers to compile. |
99 | | - setup_requires=['setuptools', 'Cython>=0.29.14'], |
100 | | - install_requires=['setuptools'], |
101 | | - extras_require={ |
102 | | - "analysis": ["networkx>=2.6", "pygraphviz"], |
103 | | - "test": "tox" |
104 | | - } |
105 | | - ) |
| 75 | + "linetrace": enable_coverage})) |
0 commit comments