Developer guide
Developer Install
This package can be installed through the following commands:
## Update to real URL !
git clone https://github.com/CNES/slurp
cd slurp
make install
source venv/bin/activate # to go in installed dev environment
Dependencies : git, make
Packages is available in virtualenv in developer mode !
Please use make help to use all preconfigured possibilities.
Coding guide
Here are some rules to apply when developing a new functionality:
Comments: Include a comments ratio high enough and use explicit variables names. A comment by code block of several lines is necessary to explain a new functionality.
Test: Each new functionality shall have a corresponding test in its module’s test file. This test shall, if possible, check the function’s outputs and the corresponding degraded cases.
Documentation: All functions shall be documented (object, parameters, return values).
Use type hints: Use the type hints provided by the typing python module.
Use doctype: Follow sphinx default doctype for automatic API
Quality code: Correct project quality code errors with pre-commit automatic workflow (see below)
Factorization: Factorize the code as much as possible. The command line tools shall only include the main workflow and rely on the slurp python modules.
Be careful with user interface upgrade: If major modifications of the user interface or of the tool’s behaviour are done, update the user documentation (and the notebooks if necessary).
Logging and no print: The usage of the print() function is forbidden: use the logging python standard module instead.
Limit classes: If possible, limit the use of classes as much as possible and opt for a functional approach. The classes are reserved for data modelling if it is impossible to do so using xarray and for the good level of modularity.
Limit new dependencies: Do not add new dependencies unless it is absolutely necessary, and only if it has a permissive license.
Tests
slurp includes a set of tests executed with pytest tool.
To launch tests:
make test
It launches the unit tests present in slurp/tests/test_slurp.py displaying the traces generated by the tests and the tests code coverage level.
During the tests execution, slurp will write the output data in a /tmp directory.
Documentation
slurp documentation can be generated with following command:
make docs
It cleans documentation from docs/build/ directory and builds the sphinx documentation from docs/source/ into docs/build/:
sphinx-build -M clean docs/source/ docs/build
sphinx-build -M html docs/source/ docs/build
Pre-commit validation
A pre-commit validation is installed with code quality tools (see below). It is installed automatically by make install-dev command.
Here is the way to install it manually:
$ pre-commit install -t pre-commit
$ pre-commit install -t pre-push
This installs the pre-commit hook in .git/hooks/pre-commit and .git/hooks/pre-push from .pre-commit-config.yaml file configuration.
It is possible to test pre-commit before commiting:
$ pre-commit run --all-files # Run all hooks on all files
$ pre-commit run --files slurp/__init__.py # Run all hooks on one file
$ pre-commit run pylint # Run only pylint hook
$ pre-commit run --hook-stage push --all-files # Run with push hook
Code quality
The project uses Isort, Black, Flake8 and Pylint quality code checking.
Use the following command in virtualenv to check the code with these tools:
$ make lint
Use the following command to format the code with isort and black:
$ make format
Isort
Isort is a Python utility / library to sort imports alphabetically, and automatically separated into sections and by type.
isort configuration is done in .pyproject.toml
Isort manual usage examples:
$ cd slurp_HOME
$ isort --check slurp tests # Check code with isort, does nothing
$ isort --diff slurp tests # Show isort diff modifications
$ isort slurp tests # Apply modifications
Isort messages can be avoided when really needed with “# isort:skip” on the incriminated line.
Black
Black is a quick and deterministic code formatter to help focus on the content.
black configuration is done in .pyproject.toml
If necessary, Black doesn’t reformat blocks that start with “# fmt: off” and end with # fmt: on, or lines that ends with “# fmt: skip”. “# fmt: on/off” have to be on the same level of indentation.
Black manual usage examples:
$ cd slurp_HOME
$ black --check slurp tests # Check code with black with no modifications
$ black --diff slurp tests # Show black diff modifications
$ black slurp tests # Apply modifications
Flake8
Flake8 is a command-line utility for enforcing style consistency across Python projects. By default it includes lint checks provided by the PyFlakes project, PEP-0008 inspired style checks provided by the PyCodeStyle project, and McCabe complexity checking provided by the McCabe project. It will also run third-party extensions if they are found and installed.
flake8 configuration is done in setup.cfg
Flake8 messages can be avoided (in particular cases !) adding “# noqa” in the file or line for all messages. It is better to choose filter message with “# noqa: E731” (with E371 example being the error number). Look at examples in source code.
Flake8 manual usage examples:
$ cd slurp_HOME
$ flake8 slurp tests # Run all flake8 tests
Pylint
Pylint is a global linting tool which helps to have many information on source code.
pylint configuration is done in dedicated .pylintrc file.
Pylint messages can be avoided (in particular cases !) adding “# pylint: disable=error-message-name” in the file or line. Look at examples in source code.
Pylint manual usage examples:
$ cd slurp_HOME
$ pylint tests slurp # Run all pylint tests
$ pylint --list-msgs # Get pylint detailed errors informations
Bug report
Any proven or suspected malfunction should be traced in a bug report, the latter being an issue in the slurp github repository.
Don’t hesitate to do so: It is best to open a bug report and quickly resolve it than to let a problem remain in the project. Notifying the potential bugs is the first way for contributing to a software.
- In the problem description, be as accurate as possible. Include:
The procedure used to initialize the environment
The incriminated command line or python function
The content of the input and output configuration files (content.json)
Contributing workflow
Any code modification requires a Merge Request. It is forbidden to push patches directly into master (this branch is protected).
It is recommended to open your Merge Request as soon as possible in order to inform the developers of your ongoing work. Please add WIP: before your Merge Request title if your work is in progress: This prevents an accidental merge and informs the other developers of the unfinished state of your work.
The Merge Request shall have a short description of the proposed changes. If it is relative to an issue, you can signal it by adding Closes xx where xx is the reference number of the issue.
Likewise, if you work on a branch (which is recommended), prefix the branch’s name by xx- in order to link it to the xx issue.
- slurp’s Classical workflow is :
Check Licence and sign Contribution license agreement (Individual or Corporate)
Create an issue (or begin from an existing one)
Create a Merge Request from the issue: a MR is created accordingly with WIP:, Closes xx and associated xx-name-issue branch
Modify slurp’s code from a local working directory or from the forge (less possibilities)
Git add, commit and push from local working clone directory or from the forge directly
Follow Conventional commits specifications for commit messages
Beware that pre-commit hooks can be installed for code analysis (see below pre-commit validation).
Launch the tests with pytest on your modifications (or don’t forget to add ones).
When finished, change your Merge Request name (erase WIP: in title ) and ask to review the code.
Contribution license agreement
slurp requires that contributors sign out a Contributor LicenseAgreement. The purpose of this CLA is to ensure that the project has the necessary ownership or grants of rights over all contributions to allow them to distribute under the chosen license (Apache License Version 2.0)
To accept your contribution, we need you to complete, sign and email to cars@cnes.fr an Individual Contributor LicensingAgreement (ICLA) form and a Corporate Contributor Licensing Agreement (CCLA) form if you are contributing on behalf of your company or another entity which retains copyright for your contribution.
The copyright owner (or owner’s agent) must be mentioned in headers of all modified source files and also added to the AUTHORS.md file.