Skip to content

Commit 42aad09

Browse files
authored
Merge pull request #131 from pebenito/setup-to-pyproject
setup.py: Move static definitions to pyproject.toml.
2 parents f0acf98 + 5718140 commit 42aad09

2 files changed

Lines changed: 95 additions & 62 deletions

File tree

pyproject.toml

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,70 @@
11
[build-system]
2-
requires = ["setuptools", "Cython>=0.27"]
2+
# setup also requires libsepol and libselinux
3+
# C libraries and headers to compile.
4+
requires = ["setuptools", "Cython>=0.29.14"]
35
build-backend = "setuptools.build_meta"
46

7+
[project]
8+
name = "setools"
9+
version = "4.6.0.dev"
10+
description="SELinux policy analysis tools."
11+
authors = [{name = "Chris PeBenito", email="pebenito@ieee.org"}]
12+
readme = {file = "README.md", content-type = "text/markdown"}
13+
urls.Homepage = "https://github.com/SELinuxProject/setools"
14+
urls.Repository = "https://github.com/SELinuxProject/setools.git"
15+
urls."Bug Tracker" = "https://github.com/SELinuxProject/setools/issues"
16+
17+
keywords = ["SELinux",
18+
"SETools",
19+
"policy",
20+
"analysis",
21+
"seinfo",
22+
"sesearch",
23+
"sediff",
24+
"sedta",
25+
"seinfoflow",
26+
"apol"]
27+
28+
# https://pypi.org/classifiers/
29+
classifiers = ["Development Status :: 5 - Production/Stable",
30+
"Environment :: Console",
31+
"Environment :: X11 Applications :: Qt",
32+
"Intended Audience :: Information Technology",
33+
"License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
34+
"License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
35+
"Programming Language :: Cython",
36+
"Topic :: Security",
37+
"Topic :: Utilities",
38+
"Typing :: Typed"]
39+
40+
requires-python=">=3.10"
41+
# also requires libsepol.so and libselinux.so.
42+
dependencies = ["setuptools"]
43+
44+
optional-dependencies.analysis = ["networkx>=2.6",
45+
"pygraphviz"]
46+
optional-dependencies.gui = ["PyQt6"]
47+
optional-dependencies.test = ["tox"]
48+
49+
[tool.setuptools]
50+
include-package-data = false
51+
script-files = ["apol",
52+
"sediff",
53+
"seinfo",
54+
"seinfoflow",
55+
"sesearch",
56+
"sedta",
57+
"sechecker"]
58+
59+
[tool.setuptools.packages.find]
60+
include = ["setools*"]
61+
62+
[tool.setuptools.package-data]
63+
"*" = ["*.css", "*.html", "perm_map", "py.typed"]
64+
65+
[tool.setuptools.exclude-package-data]
66+
"*" = ["*.c", "*.pyi", "*.pyx"]
67+
568

669
#
770
# Coverage config

setup.py

Lines changed: 31 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
11
#!/usr/bin/env python3
22

3-
import glob
4-
from setuptools import Extension, setup
53
import sys
64
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
99
from Cython.Build import cythonize
10-
import os.path
1110

1211

1312
# 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] = []
1615

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"))
2323

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 []
2825

2926
# 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", ""))
3128
if enable_coverage:
3229
macros.append(("CYTHON_TRACE", 1))
3330

34-
cython_annotate = bool(os.environ.get("SETOOLS_ANNOTATE", False))
31+
cython_annotate = bool(os.getenv("SETOOLS_ANNOTATE", ""))
3532

3633
ext_py_mods = [Extension('setools.policyrep', ['setools/policyrep.pyx'],
3734
include_dirs=include_dirs,
@@ -53,53 +50,26 @@
5350
'-Wwrite-strings',
5451
'-fno-exceptions'])]
5552

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("."))
6257

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]()
6361
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}"))))
6667

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,
8070
ext_modules=cythonize(ext_py_mods, include_path=['setools/policyrep'],
8171
annotate=cython_annotate,
8272
compiler_directives={"language_level": 3,
8373
"c_string_type": "str",
8474
"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

Comments
 (0)