Skip to content
This repository was archived by the owner on May 26, 2026. It is now read-only.

Commit a625bb6

Browse files
authored
add black and flake8
1 parent c513e00 commit a625bb6

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

README.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ A python project template for educational purposes
1717
**venv** stands for virtual environment and is part of the python standard library (i.e. you don't have to install it).
1818
Python virtual environments' role is to create an isolated python environment for each project so that there are no dependency issues etc. from conflicting project requirements (e.g. Project A need pandas 1.0 and Project B needs pandas 1.1).
1919

20-
The command `python -m venv .venv` creates a directory call .venv.
20+
The terminal command `python -m venv .venv` creates a directory call .venv.
2121
You can activate the virtual environment with `source .venv/bin/activate`.
2222

2323
To enable the new venv in jupyter notebooks follow the instructions here:
@@ -37,32 +37,50 @@ For this project we have 3 files where the requirements are stored:
3737
* [docs/requirements.txt](docs/requirements.txt) has the dependencies for building the documentation.
3838
* [setup.py](setup.py) has the **examplepackage** dependencies as part of the `install_requires` parameter of the `setup` function. More info in the dedicated section below.
3939

40-
The command `pip installs -r requirements.txt` install requirements from the specified file.
40+
The terminal command `pip installs -r requirements.txt` install requirements from the specified file.
4141

4242
Alternatives to using requirements.txt files are conda enviroment yaml files (if you choose to use a conda env that is):
4343
https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
4444

45+
## Pre-commit hooks
46+
*[insert description]*
47+
4548
## flake8
49+
flake8 checks if the code is uggly according to [PEP8](https://www.python.org/dev/peps/pep-0008/).
50+
4651
Quotting the the [flake8 documentation](https://flake8.pycqa.org/en/latest/manpage.html) directly:
47-
*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.*
52+
*"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."*
4853

49-
In summary, flake8 checks if the code is uggly according to [PEP8](https://www.python.org/dev/peps/pep-0008/).
5054
flake8 is part of the requirements.dev.txt file and can be installed with pip.
51-
To run a flake8 check you simply execute the command:
55+
To run a flake8 check you simply execute the terminal command:
5256
`flake8 examplepackage` *or any other dir that contains python files*
5357

54-
You can configure flake8 by adding a section for flake8 in the setup.cfg[setup.cfg] file. For example you can choose to instruct flake8 to ignore certain errors or change the default line length.
58+
You can configure flake8 by adding a section for flake8 in the [setup.cfg](setup.cfg) file. For example you can choose to instruct flake8 to ignore certain errors or change the default line length.
5559

5660
## black
61+
black makes sure the flake8 checks pass by autoformatting all the .py files.
62+
63+
Quotting the the [black documentation](https://black.readthedocs.io/en/stable/?badge=stable) directly:
64+
*"Black makes code review faster by producing the smallest diffs possible. Blackened code looks the same regardless of the project you’re reading. Formatting becomes transparent after a while and you can focus on the content instead."*
65+
66+
To format a directory with black run the terminal command:
67+
`black examplepackage` or file.py etc.
68+
69+
Black (like flake8) is configurable but through a .toml file (not setup.cfg) that is currently excluded from this template.
70+
71+
Some IDEs have format on save features and can be configured to use black:
72+
* Visual studio code: https://dev.to/adamlombard/how-to-use-the-black-python-code-formatter-in-vscode-3lo0
73+
74+
## pydocstyle
5775
*[insert description]*
5876

5977
## pytest
6078
*[insert description]*
6179

62-
## setup.py
80+
## setup.cfg
6381
*[insert description]*
6482

65-
## setup.cfg
83+
## setup.py
6684
*[insert description]*
6785

6886
## Installing a package in Development mode
@@ -71,9 +89,6 @@ You can configure flake8 by adding a section for flake8 in the setup.cfg[setup.c
7189
## .gitignore
7290
*[insert description]*
7391

74-
## Pre-commit hooks
75-
*[insert description]*
76-
7792
## Github Actions
7893
*[insert description]*
7994

0 commit comments

Comments
 (0)