Skip to content

Commit 56ff6d7

Browse files
committed
pytrap: add pyproject.toml for modern Python packaging
1 parent 66562ae commit 56ff6d7

File tree

9 files changed

+157
-90
lines changed

9 files changed

+157
-90
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ unirec/tests/test_speed_ur
7676
unirec/tests/test_speed_uro
7777
unirec/tests/test_template_cmp
7878
unirec/tests/test_time
79+
__pycache__

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ install-exec-hook:
3232
@echo -e "\n\n"
3333
@echo "For installation of Python components run the following commands as root:"
3434
@for i in ${PYTHON_SUBDIRS}; do \
35-
echo -e "(cd $${i}; ${PYTHON} setup.py install --record=installed-files.txt;)\n"; \
35+
echo -e "(pip install ./$${i})\n"; \
3636
done
3737
@echo -e "\n\n"
3838

pytrap/Makefile.am

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.PHONY: rpm
22

3-
EXTRA_DIST=MANIFEST.in README README.md test.sh nemea-pytrap.spec setup.py \
3+
EXTRA_DIST=MANIFEST.in README README.md test.sh nemea-pytrap.spec pyproject.toml \
44
src/pytrapmodule.c \
55
src/unirecmodule.c \
66
src/unirecipaddr.c \
@@ -15,7 +15,7 @@ EXTRA_DIST=MANIFEST.in README README.md test.sh nemea-pytrap.spec setup.py \
1515

1616
rpm:
1717
mkdir -p RPMBUILD/SOURCES
18-
python3 setup.py sdist
18+
python3 -m build --sdist
1919
cp dist/*.tar.gz RPMBUILD/SOURCES
2020
rpmbuild -ba nemea-pytrap.spec --define "_topdir `pwd`/RPMBUILD"
2121
mv RPMBUILD/RPMS/*/*.rpm RPMBUILD/SRPMS/*.rpm dist/
@@ -27,13 +27,13 @@ TESTS = test.sh
2727

2828
.PHONY: coverage
2929
coverage:
30-
CFLAGS=-coverage python setup.py build_ext --inplace
31-
CFLAGS=-coverage python3 setup.py build_ext --inplace
32-
python3 setup.py test || echo "Skipped python3 tests"
30+
CFLAGS=-coverage python3 -m pip install .[test] --no-deps --disable-pip-version-check --no-cache-dir
31+
CFLAGS=-coverage python3 -m pytest --cov=pycommon || echo "Skipped python3 tests"
3332
@lcov --capture --directory . --output-file coverage.info 2>/dev/null && \
3433
genhtml coverage.info --output-directory out 2>/dev/null || echo "Skipped coverage analysis"
3534

3635
.PHONY: doc
3736
doc:
38-
python3 setup.py build_sphinx
39-
37+
python3 -m pip install .[doc] --no-cache-dir
38+
cd docs
39+
make html

pytrap/README

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,89 @@
11
# About pytrap
22

3+
The pytrap module is a native Python extension that allows for writing NEMEA modules in Python.
4+
TODO
35
This directory contains an implementation of Python extension. The aim
46
is to allow native calls of base TRAP functionality (used by NEMEA modules).
57

68
# Installation
79

10+
## Prerequisites
11+
812
Development package of Python is required (python3-devel etc.
913
according to your OS distribution). It contains needed header files.
1014

11-
Since this module uses libtrap and libunirec, https:/github.com/CESNET/Nemea-framework
15+
Since this module uses libtrap and libunirec, https://github.com/CESNET/Nemea-framework
1216
must be installed in the system.
1317

14-
When all requirements are met, run as root:
18+
### Installing Python development headers
19+
20+
**For Debian/Ubuntu:**
21+
```bash
22+
sudo apt install python3-dev
23+
```
1524

25+
**For Red Hat/Fedora/CentOS:**
26+
```bash
27+
sudo dnf install python3-devel
1628
```
17-
python3 setup.py install
29+
## Installing pytrap
30+
31+
When all requirements are met, run as root:
32+
33+
```bash
34+
pip install .
1835
```
1936

20-
Note: for different versions of python, it is needed to perform this command
21-
separately for each of them.
2237

23-
# Help
38+
## Viewing help
2439

2540
Help is contained in the python module. After successful installation run in
26-
a python interactive interpret:
41+
a python interactive interpreter:
2742

2843
```python
2944
import pytrap
3045
help(pytrap)
3146
help(pytrap.pytrap)
3247
```
3348

34-
# Examples
3549

36-
See https://github.com/CESNET/Nemea-Framework/tree/master/examples/python
50+
# Documentation
51+
52+
## Building documentation
53+
54+
The project uses Sphinx for documentation generation. First install documentation dependencies:
55+
56+
```bash
57+
pip install .[docs]
58+
```
59+
60+
Then build the documentation:
61+
62+
```bash
63+
cd docs
64+
65+
make html
66+
```
67+
68+
The generated documentation will be available in the `dist/doc/` directory.
69+
70+
# Testing
71+
72+
The project uses pytest for testing. First install documentation dependencies:
73+
74+
```bash
75+
pip install .[test]
76+
```
77+
78+
```bash
79+
# Run all tests
80+
pytest
81+
82+
# Run specific test files (following the project's naming convention)
83+
pytest test/*_unittest.py
84+
```
85+
86+
87+
# Examples
3788

89+
See https://github.com/CESNET/Nemea-Framework/tree/master/examples/python

pytrap/docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
SPHINXOPTS ?=
77
SPHINXBUILD ?= sphinx-build
88
SOURCEDIR = .
9-
BUILDDIR = _build
9+
BUILDDIR = ../dist/doc
1010

1111
# Put it first so that "make" without argument is like "make help".
1212
help:

pytrap/docs/conf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
#
1313
import os
1414
import sys
15-
sys.path.insert(0, os.path.abspath('..'))
15+
from sphinx_pyproject import SphinxConfig
1616

17+
config = SphinxConfig("../pyproject.toml", globalns=globals())
18+
release = version
19+
project = name
1720

1821
# -- Project information -----------------------------------------------------
1922

pytrap/nemea-pytrap.spec

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ NEMEA modules in Python.
2222
Summary: Python extension of the NEMEA project
2323
%{?python_provide:%python_provide python%{python3_pkgversion}-%{pypi_name}}
2424
Requires: libtrap
25+
BuildRequires: python%{python3_pkgversion}-build
26+
BuildRequires: python%{python3_pkgversion}-pip
27+
BuildRequires: python%{python3_pkgversion}-wheel
2528
BuildRequires: python%{python3_pkgversion}-setuptools
2629
BuildRequires: python%{python3_pkgversion}-devel
2730
BuildRequires: gcc
@@ -44,12 +47,15 @@ rm -rf %{pypi_name}.egg-info
4447

4548
%install
4649
# Must do the subpackages' install first because the scripts in /usr/bin are
47-
# overwritten with every setup.py install.
48-
%{__python3} setup.py install --skip-build --single-version-externally-managed --root %{buildroot}
50+
# Install into the build root using pip (PEP 517 compatible)
51+
%{__python3} -m pip install . \
52+
--root %{buildroot} \
53+
--no-deps --disable-pip-version-check --no-cache-dir --verbose
4954

5055
%check
51-
TRAP_SOCKET_DIR=/tmp PAGER="" %{__python3} setup.py test
52-
56+
# Install test dependencies and run tests
57+
%{__python3} -m pip install .[test] --no-deps --disable-pip-version-check --no-cache-dir
58+
TRAP_SOCKET_DIR=/tmp PAGER="" %{__python3} -m pytest -v
5359
%files -n python%{python3_pkgversion}-%{pypi_name}
5460
%doc README
5561
%{python3_sitearch}/*

pytrap/pyproject.toml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[build-system]
2+
requires = ["setuptools>=61", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "nemea-pytrap"
7+
version = "0.17.0"
8+
description = "Python extension of the NEMEA project."
9+
readme = {file = "README.md", content-type = "text/markdown"}
10+
authors = [
11+
{ name = "Tomas Cejka", email = "[email protected]" },
12+
]
13+
maintainers = [
14+
{ name = "Tomas Cejka", email = "[email protected]" },
15+
]
16+
license = { text = "BSD" }
17+
requires-python = ">=3.8"
18+
classifiers = [
19+
"Development Status :: 4 - Beta",
20+
"Operating System :: POSIX :: Linux",
21+
"Programming Language :: C",
22+
"Programming Language :: Python :: 3",
23+
"Programming Language :: Python :: 3.8",
24+
"Programming Language :: Python :: 3.9",
25+
"Programming Language :: Python :: 3.10",
26+
"Programming Language :: Python :: 3.11",
27+
"Programming Language :: Python :: 3.12",
28+
"Programming Language :: Python :: Implementation :: CPython",
29+
"Topic :: Software Development :: Libraries",
30+
"Topic :: System :: Networking :: Monitoring"
31+
]
32+
dependencies = []
33+
34+
[project.optional-dependencies]
35+
test = [
36+
"pytest",
37+
"pytest-cov",
38+
"pytest-forked",
39+
]
40+
docs = [
41+
"sphinx",
42+
"sphinx-rtd-theme",
43+
"sphinx-pyproject"
44+
]
45+
46+
[project.urls]
47+
Homepage = "https://github.com/CESNET/Nemea-Framework"
48+
49+
# Configure setuptools to find packages and handle C extensions
50+
[tool.setuptools]
51+
package-dir = { "" = "src" }
52+
53+
[tool.setuptools.packages.find]
54+
where = ["src"]
55+
56+
[[tool.setuptools.ext-modules]]
57+
name = "pytrap.pytrap"
58+
sources = [
59+
"src/pytrapmodule.c",
60+
"src/unirecmodule.c",
61+
"src/unirecipaddr.c",
62+
"src/unirecmacaddr.c",
63+
"src/iplist.c",
64+
"src/fields.c"
65+
]
66+
libraries = ["trap", "unirec"]
67+
68+
69+
[tool.pytest.ini_options]
70+
testpaths = ["test"]
71+
python_files = ["*_unittest.py"]
72+
addopts = "--forked"

pytrap/setup.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)