Development

Python virtual environment

At this point of writing, when setting up for python3.11.2 in debian 12

setup

python3 -m venv --system-site-packages venv
source venv/bin/activate
pip3 install --upgrade pip
pip3 install swig==4.1.1.post1
pip3 install pykcs11==1.4.4
pip3 install dmarc endesive bs4 sqlalchemy aioprocessing python-magic pytest
git clone https://github.com/crustymonkey/python-libmilter.git
cd python-libmilter; git checkout python3; cd .. # ensure libmilter is installed from python3 branch
pip install python-libmilter # install from local directory
git clone https://gitlab.com/YOURNAMESPACE/fuglu/ # use your clone
cd fuglu; pip install --editable fuglu; cd ..
sudo mkdir /var/log/fuglu; sudo chown YOURUSER:YOURGROUP /var/log/fuglu # log dir must be writeable by local user
sudo mkdir /etc/fuglu; sudo chown YOURUSER:YOURGROUP /etc/fuglu # config dir should be writeable by local user
cp -r fuglu/conf/* /etc/fuglu/ # also strip .dist suffix from all file names
python3 -m fuglu --lint # test if setup is fine
python3 -m fuglu --foreground # run fuglu without detaching from shell
python3 -m pytest fuglu/test/unit/ # run unit tests, may take a while

IDE

When using vscode 1.85.2. cd to the root of the project that contain the python virtual environment as setup described in setup

VScode

vscode should auto detect. Verify by open a terminal within vscode.

vscode .

unit test

Ensure you have the virtual environment setup . Then install test dependencies.

pip3 install --editable '.[test]'
apt-get install unrar

different ways to test

# run all unittests under fuglu/tests/unit
$ python3 -m pytest fuglu/tests/unit

# run a single unit module
$ python3 -m pytest fuglu/tests/unit/shared_test.py

# run a single unit class
$ python3 -m pytest -v fuglu/tests/unit/milterplugin_test.py::TestMilterPluginBase

# run a single unit function
$ python3 -m pytest -v fuglu/tests/unit/milterplugin_test.py::TestMilterPluginBase::test_lint_ok

# exclude a test
$ python3 -m pytest -v  fuglu/tests/unit/milterplugin_test.py::TestMilterPluginBase -k 'not test_lint_notimpl'

# to show debug logging during pytest
$ python3 -m pytest -rA -s  --log-cli-level=DEBUG  fuglu/tests/unit/plugins_attachment_test.py::AttachmentPluginTestCase::test_archiveextractsize