Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ unirec/tests/test_speed_ur
unirec/tests/test_speed_uro
unirec/tests/test_template_cmp
unirec/tests/test_time
__pycache__
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ ACLOCAL_AMFLAGS=-I m4

install-exec-hook:
@echo -e "\n\n"
@echo "For installation of Python components run the following commands as root:"
@echo "For installation of Python components run the following commands:"
@for i in ${PYTHON_SUBDIRS}; do \
echo -e "(cd $${i}; ${PYTHON} setup.py install --record=installed-files.txt;)\n"; \
echo -e "(pip install ./$${i})\n"; \
done
@echo -e "\n\n"

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ Python parts must be installed separately when needed.
It can be done using:

```
cd pytrap; sudo python3 setup.py install
pip install ./pytrap
```
and
```
cd pycommon; sudo python3 setup.py install
pip install ./pycommon
```

Project status:
Expand Down
4 changes: 2 additions & 2 deletions pycommon/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
EXTRA_DIST=report2idea.py ip_prefix_search.py nemea-pycommon.spec setup.py README-RPM-release.md README reporter_config
EXTRA_DIST=report2idea.py ip_prefix_search.py nemea-pycommon.spec pyproject.toml README-RPM-release.md README reporter_config

if MAKE_RPMS
RPMFILENAME=nemea-pycommon
.PHONY: rpm
rpm:
mkdir -p RPMBUILD/SOURCES
python3 setup.py sdist
python3 -m build --sdist
cp dist/*.tar.gz RPMBUILD/SOURCES
rpmbuild -ba nemea-pycommon.spec --define "_topdir `pwd`/RPMBUILD"
mv RPMBUILD/RPMS/*/*.rpm RPMBUILD/SRPMS/*.rpm dist/
Expand Down
21 changes: 13 additions & 8 deletions pycommon/README
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# About pycommon
# pycommon

The pycommon module contains functionality for NEMEA modules written in python.
Currently, it is used by reporter modules.
**pycommon** provides shared functionality for [NEMEA](https://github.com/CESNET/Nemea) modules written in Python.
It is primarily used by reporter modules, but can be reused in other NEMEA-related Python projects.

# Installation
---

Run as root:
## Installation

It is recommended to install using `pip`:

```bash
pip install .
```
python3 setup.py install
If you need to install for a specific Python interpreter (e.g., Python 3.9 vs. 3.11), run the above command with the corresponding interpreter:
```bash
python3.11 -m pip install .
```

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

---
18 changes: 11 additions & 7 deletions pycommon/README-RPM-release.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
# How to release new version of RPM?
# How to release a new version of the RPM?
1. Bump the version in `pyproject.toml` and `*.spec`.

1. bump version in `setup.py` and `*.spec`
2. don't forget to commit and push with commit message
2. Don't forget to commit and push with a commit message:

```
pycommon: increased version, released package
```

3. create python src package using `python setup.py sdist`
3. Create a Python source distribution:
```bash
python3 -m pip install build
python3 -m build --sdist
```

4. upload files in `dist/` using `twine`:
4. Upload files in `dist/` using `twine`:

```
twine upload ./*
```

5. run `make rpm`
6. your packages are in `RPMBUILD/`, build for other RPM-based systems can be done using:
5. Run `make rpm`
6. Your packages are in `RPMBUILD/`, build for other RPM-based systems can be done using:

```
copr build @CESNET/NEMEA RPMBUILD/SRPMS/<package.src.rpm>
Expand Down
9 changes: 6 additions & 3 deletions pycommon/nemea-pycommon.spec
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ rm -rf %{pypi_name}.egg-info

%install
# Must do the subpackages' install first because the scripts in /usr/bin are
# overwritten with every setup.py install.
%{__python3} setup.py install --skip-build --single-version-externally-managed --root %{buildroot}
# overwritten with every install.
%{__python3} -m pip install . --root %{buildroot} --no-deps --disable-pip-version-check --no-cache-dir --verbose

mkdir -p %{buildroot}/%{_sysconfdir}/nemea/email-templates/; cp reporter_config/default.html %{buildroot}/%{_sysconfdir}/nemea/email-templates/default.html


%check
%{__python3} setup.py test
%{__python3} -m pip install .[test]
%{__python3} -m pytest


%files -n python%{python3_pkgversion}-%{pypi_name}
%doc README
Expand Down
57 changes: 57 additions & 0 deletions pycommon/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "nemea-pycommon"
version = "1.7.0"
description = "Common Python modules and methods of the NEMEA system."
readme = {text = "The module contains methods for creation and submission of incident reports in IDEA format.", content-type = "text/plain"}
license = {text = "BSD"}
authors = [
{name = "Vaclav Bartos, CESNET", email = "[email protected]"},
]
maintainers = [
{name = "Tomas Cejka", email = "[email protected]"},
]
requires-python = ">=3.6"
dependencies = [
"pynspect",
"idea-format",
"PyYAML",
"ply",
"jinja2",
"redis",
]
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: POSIX",
"Programming Language :: C",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Libraries",
"Topic :: System :: Networking :: Monitoring",
]


[project.optional-dependencies]
test = [
"pytest",
"pytest-cov",
]



[project.urls]
Homepage = "https://github.com/CESNET/Nemea-Framework"

[tool.setuptools]
py-modules = ["report2idea", "ip_prefix_search"]
packages = ["reporter_config", "reporter_config.actions"]


[tool.pytest.ini_options]
testpaths = ["test"]
python_files = ["*_unittest.py","rc_*.py"]
addopts = ""
31 changes: 0 additions & 31 deletions pycommon/setup.py

This file was deleted.

14 changes: 7 additions & 7 deletions pytrap/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: rpm

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

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

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

.PHONY: doc
doc:
python3 setup.py build_sphinx

python3 -m pip install .[docs] --no-cache-dir
cd docs
make html
71 changes: 61 additions & 10 deletions pytrap/README
Original file line number Diff line number Diff line change
@@ -1,37 +1,88 @@
# About pytrap
The `pytrap` module is a native Python extension that allows writing NEMEA modules in Python.

This directory contains an implementation of Python extension. The aim
This directory contains an implementation of a Python extension. The aim
is to allow native calls of base TRAP functionality (used by NEMEA modules).

# Installation

## Prerequisites

Development package of Python is required (python3-devel etc.
according to your OS distribution). It contains needed header files.

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

When all requirements are met, run as root:
### Installing Python development headers

**For Debian/Ubuntu:**
```bash
sudo apt install python3-dev
```

**For Red Hat/Fedora/CentOS:**
```bash
sudo dnf install python3-devel
```
python3 setup.py install
## Installing pytrap

When all requirements are met, run as root:

```bash
pip install .
```

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

# Help
## Viewing help

Help is contained in the python module. After successful installation run in
a python interactive interpret:
a python interactive interpreter:

```python
import pytrap
help(pytrap)
help(pytrap.pytrap)
```

# Examples

See https://github.com/CESNET/Nemea-Framework/tree/master/examples/python
# Documentation

## Building documentation

The project uses Sphinx for documentation generation. First install documentation dependencies:

```bash
pip install .[docs]
```

Then build the documentation:

```bash
cd docs

make html
```

The generated documentation will be available in the `dist/doc/` directory.

# Testing

The project uses pytest for testing. First install documentation dependencies:

```bash
pip install .[test]
```

```bash
# Run all tests
pytest

# Run specific test files (following the project's naming convention)
pytest test/*_unittest.py
```


# Examples

See https://github.com/CESNET/Nemea-Framework/tree/master/examples/python
2 changes: 1 addition & 1 deletion pytrap/docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
BUILDDIR = ../dist/doc

# Put it first so that "make" without argument is like "make help".
help:
Expand Down
5 changes: 4 additions & 1 deletion pytrap/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))
from sphinx_pyproject import SphinxConfig

config = SphinxConfig("../pyproject.toml", globalns=globals())
release = version
project = name

# -- Project information -----------------------------------------------------

Expand Down
Loading