Skip to content
Merged

Dev #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ jobs:
cache: 'pip'
- run: pip install -r requirements.txt

- name: Lint model code
- name: Lint
run: |
flake8 ./simulation
pylint ./simulation

- name: Lint tests
run: |
flake8 ./tests
pylint ./tests
bash lint.sh
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This repository provides a template for building discrete-event simulation (DES)

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

✨ **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.
✨ **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).

🧱 **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).

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

🔎 **Linting**

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

```
flake8 simulation/model.py
pylint simulation/model.py
```

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

```
%load_ext pycodestyle_magic
%pycodestyle_on
nbqa pylint notebooks/analysis.ipynb
```

A bash script has been provided which can be used to lint all files in succession by running:

```
bash lint.sh
```

<br>
Expand Down Expand Up @@ -225,6 +229,7 @@ repo/
├── CONTRIBUTING.md # Contribution instructions
├── environment.yaml # Conda environment (includes Python version)
├── LICENSE # Licence file
├── lint.sh # Bash script to lint all .py and .ipynb files at once
├── pyproject.toml # Metadata for local `simulation/` package
├── README.md # This file! Describes the repository
└── requirements.txt # Virtual environment (used by GitHub actions)
Expand Down
13 changes: 6 additions & 7 deletions docs/time_weighted_averages.ipynb

Large diffs are not rendered by default.

14 changes: 5 additions & 9 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@ name: template-des
channels:
- conda-forge
dependencies:
- black
- flake8=7.1.1
- ipykernel=6.29.5
- jinja2=3.1.5
- joblib=1.4.2
- nbformat=5.10.4
- nbqa
- numpy=2.1.3
- nbqa=1.9.0
- numpy=2.2.2
- pandas=2.2.3
- pip=24.3.1
- pip=25.0
- plotly_express=0.4.1
- pycodestyle=2.12.1
- pylint=3.3.3
- pylint=3.3.4
- pytest=8.3.4
- pytest-xdist=3.6.1
- python=3.13.0
- python=3.13.1
- simpy=4.1.1
- pip:
- kaleido==0.2.1
- pycodestyle_magic==0.5
- -e .[dev]
13 changes: 13 additions & 0 deletions lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

echo "Linting model code..."
pylint ./simulation

echo "Linting tests..."
pylint ./tests

echo "Linting notebooks..."
nbqa pylint ./notebooks

echo "Linting time-weighted averages notebook..."
nbqa pylint ./docs/time_weighted_averages.ipynb
Loading