Development
Development environment
It is convenient to setup a separate virtual environment:
Using pipenv
Install pipenv:
$ pip install pipenv
Navigate to the shobnetpy folder:
$ cd shobnetpy
Create virtual environment:
$ pipenv shell
Install requirements:
$ pipenv install $ pipenv install -r requirements_dev.txt
Style Guide
Code should stick to PEP 8 (https://peps.python.org/pep-0008/)
Documenting code
Docstrings in numpy format
Members starting with an underscore (_) will not be included in the docs.
String formatting
The use of f-strings has precedence over format() and the modulo operator. F-strings are easier to read and perform better. Exceptions apply when lazy evaluation of strings is required. F-Strings also allow format specifiers as 2nd argument after a “:” within the curly brackets.
message = (
f"Number of retrieved rows ({len(mz_df)}) for BC={gtvalue}, OT={otvalue} and "
f"BAC={bakvalue} deviates from requested number ({samplesize:5d}) by more than 1!"
)
Testing
We use pytest to conduct unit tests:
pytest
To execute a specific test method:
pytest shobnetpy/tests/test_networks.py::NetworkTest::test_degree_distribution
Hint
To continue with tests that failed last time, type pytest –ff
Documentation Guide
SHoBNetPy uses sphinx to document concepts, modules, use instructions, API and so on.
Resources:
Docs for new modules can be generated by
# Windows cd shobnetpy\doc\sphinx sphinx-apidoc.exe -o .\source\application\api\ ..\shobnetpy\ #*unix cd shobnetpy/doc/sphinx sphinx-apidoc -o ./source/application/api/ ../shobnetpy/
Note
You may need to remove existing subpackage rst files for new modules to be added. Then, replace Submodules with .. contents:: in teh new rst files. Generated files modules.rst, shopnetpy.rst and setup.rst can be deleted to avoid warnings (they are not linked).
Heading hierarchy:
######### 1st level #########
********* 2nd level *********
3rd level =========
4th level ---------
Building documentation
HTML pages
cd <path to shobnetpy>/doc/sphinx make html
For windows, make.bat html should work.
Docx document
cd <path to shobnetpy>/doc/sphinx make docx
In order for this to work, either ensure to be in the shopnetpy (see Development environment) virtual environment or set the path to the sphinx-build executable manually by
set SPHINXBUILD=<path to shobnetpy>\.venv\Scripts\sphinx-build.exe
in Windows command line before running the above make-commands.
Logging
See Implementation.
3rd Party Packages
shapely
mesa
mesa=geo
networkx
pytreemap
dynaconf
scipy
qgispy
Release Workflow (WiP)
Testing
Update dependencies
requirements.txt
poetry
Update documentation
Update API
Update settings
Commit to gitlab
Publish new version