Skip to content

Commit 5c6b461

Browse files
authored
Merge pull request #18 from pythonhealthdatascience/dev
Dev
2 parents 80fe389 + e4cfaf3 commit 5c6b461

26 files changed

+1972
-790
lines changed

.github/workflows/lint.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ jobs:
2323
cache: 'pip'
2424
- run: pip install -r requirements.txt
2525

26-
- name: Lint model code
26+
- name: Lint
2727
run: |
28-
flake8 ./simulation
29-
pylint ./simulation
30-
31-
- name: Lint tests
32-
run: |
33-
flake8 ./tests
34-
pylint ./tests
28+
bash lint.sh

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ This repository provides a template for building discrete-event simulation (DES)
5555

5656
For clarity, changes from the DES book in this template are explained in `docs/hsma_changes.md`.
5757

58-
**Style:** The coding style is based on the [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html). Linting is implemented using `flake8` and `pylint` for `.py` files, and `pycodestyle` for `.ipynb` files.
58+
**Style:** The coding style is based on the [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html). Linting is implemented using `pylint` (with `nbqa` to enable it to run on jupyter notebooks).
5959

6060
🧱 **Package structure:** In Python, a package can simply be defined as a directory with an `__init__.py` file in it. In this repository, the scripts for model (within `simulation/`) are treated as a little local package. This keeps the code model code isolated from our experiments and analysis. It is installed as an editable (`-e`) local import - with `-e` meaning it will update with changes to the local files in `simulation/`. As it is installed in our environment, it can then easily be used anywhere else in the directory - here, in `notebooks/` and `tests/` - without needing any additional code (e.g. no need to modify `sys.path`, or have additional `__init__.py` files).
6161

@@ -162,18 +162,22 @@ If you have changed the model behaviour, you may wish to amend, remove or write
162162

163163
🔎 **Linting**
164164

165-
You can lint the `.py` files by running either of this commands from the terminal:
165+
You can lint the `.py` files by running:
166166

167167
```
168-
flake8 simulation/model.py
169168
pylint simulation/model.py
170169
```
171170

172-
The first commands in the `.ipynb` files will lint the notebooks using `pycodestyle` when executed:
171+
You can lint the `.ipynb` by adding `nbqa` to the start of the command - e.g.:
173172

174173
```
175-
%load_ext pycodestyle_magic
176-
%pycodestyle_on
174+
nbqa pylint notebooks/analysis.ipynb
175+
```
176+
177+
A bash script has been provided which can be used to lint all files in succession by running:
178+
179+
```
180+
bash lint.sh
177181
```
178182

179183
<br>
@@ -225,6 +229,7 @@ repo/
225229
├── CONTRIBUTING.md # Contribution instructions
226230
├── environment.yaml # Conda environment (includes Python version)
227231
├── LICENSE # Licence file
232+
├── lint.sh # Bash script to lint all .py and .ipynb files at once
228233
├── pyproject.toml # Metadata for local `simulation/` package
229234
├── README.md # This file! Describes the repository
230235
└── requirements.txt # Virtual environment (used by GitHub actions)

docs/time_weighted_averages.ipynb

Lines changed: 6 additions & 7 deletions
Large diffs are not rendered by default.

environment.yaml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@ name: template-des
22
channels:
33
- conda-forge
44
dependencies:
5-
- black
6-
- flake8=7.1.1
75
- ipykernel=6.29.5
86
- jinja2=3.1.5
97
- joblib=1.4.2
108
- nbformat=5.10.4
11-
- nbqa
12-
- numpy=2.1.3
9+
- nbqa=1.9.0
10+
- numpy=2.2.2
1311
- pandas=2.2.3
14-
- pip=24.3.1
12+
- pip=25.0
1513
- plotly_express=0.4.1
16-
- pycodestyle=2.12.1
17-
- pylint=3.3.3
14+
- pylint=3.3.4
1815
- pytest=8.3.4
1916
- pytest-xdist=3.6.1
20-
- python=3.13.0
17+
- python=3.13.1
2118
- simpy=4.1.1
2219
- pip:
2320
- kaleido==0.2.1
24-
- pycodestyle_magic==0.5
2521
- -e .[dev]

lint.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
echo "Linting model code..."
4+
pylint ./simulation
5+
6+
echo "Linting tests..."
7+
pylint ./tests
8+
9+
echo "Linting notebooks..."
10+
nbqa pylint ./notebooks
11+
12+
echo "Linting time-weighted averages notebook..."
13+
nbqa pylint ./docs/time_weighted_averages.ipynb

0 commit comments

Comments
 (0)