Development

Development environment

It is convenient to setup a separate virtual environment:

Using pipenv

  1. Install pipenv:

    $ pip install pipenv
    
  2. Navigate to the shobnetpy folder:

    $ cd shobnetpy
    
  3. Create virtual environment:

    $ pipenv shell
    
  4. Install requirements:

    $ pipenv install
    $ pipenv install -r requirements_dev.txt
    

Style Guide

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:

reStructuredText

reStructuredText Directives

  • 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:

    1. #########
      1st level
      #########
      
    2. *********
      2nd level
      *********
      
    3. 3rd level
      =========
      
    4. 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

= Shapely User Manual

mesa

= Mesa project website

mesa=geo

= Mesa-Geo project website

networkx

= NetworkX = Network Analysis in python

pytreemap

= pytreemap project website

dynaconf

= dynaconf project website

scipy

= SciPy website

qgispy

= QGIS Python API documentation

Release Workflow (WiP)

  1. Testing

  2. Update dependencies

    1. requirements.txt

    2. poetry

  3. Update documentation

    1. Update API

    2. Update settings

  4. Commit to gitlab

  5. Publish new version