Skip to content

Commit

Permalink
Merge pull request #1 from DuncDennis/develop_CICD_workflow
Browse files Browse the repository at this point in the history
Develop cicd workflow
  • Loading branch information
DuncDennis authored Mar 13, 2023
2 parents 48b56df + 13d12ab commit 2e5f53a
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 62 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: pre-commit
on: [pull_request, push, workflow_dispatch]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"
architecture: "x64"
- uses: pre-commit/[email protected]
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
name: Testing lorenzpy
on:
push:
branches:
- main
pull_request:
branches:
- main
name: test and coverage
on: [pull_request, push, workflow_dispatch]

jobs:
install-test:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -26,12 +20,6 @@ jobs:
run: pip --version
- name: installation of package in dev mode
run: pip install .[dev]
- name: checking with black
run: black --check .
- name: checking with ruff
run: ruff check --format=github .
- name: checking with mypy
run: mypy
- name: running pytest
run: pytest
- name: Upload coverage reports to Codecov
Expand Down
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: "23.1.0"
hooks:
- id: black
language_version: python3
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.245'
hooks:
- id: ruff
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.1.1'
hooks:
- id: mypy
args: [--config-file=pyproject.toml]
58 changes: 37 additions & 21 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,73 @@
# Changelog:

---
### Pre-release status (13.03.2023):
- Now using [pre-commit](https://pre-commit.com/) as an automatic CI tool.
- pre-commit runs some standard hooks, black, ruff and mypy.
- The config for black, ruff and mypy is still in `pyproject.toml`
- To run the pre-commit manual, run `pre-commit run --all-files`
- To reinstall the pre-commits, run `pre-commit install`
- My pre-commit GH action is running on ubuntu on python3.9
- **Note:** There is some redundancy, as I have to specify the versions of
black, ruff and mypy twice. Once in the `.pre-commit-config.yaml` and once in the
`pyproject.toml`.
Maybe I am only specifying which *hook* to use in the `.pre-commit-config.yaml`.
- Q:
- Should I add the tests also to pre-commit?
- When to test?


### Pre-release status (12.03.2023):
### Pre-release status (12.03.2023):

**Development features:**
**Development features:**

1. Use [Black](https://github.com/psf/black) for formatting the code.
1. Use [Black](https://github.com/psf/black) for formatting the code.
- Local terminal usage: `black .`
- Config in `pyproject.toml`
- Set line-length to `88`, set python versions to `py8`to `py11`
- GitHub Actions:
- GitHub Actions:
- Just check with black by running: `black --check .`

2. Use [Ruff](https://github.com/charliermarsh/ruff) as the Python linter.
- Local terminal usage: `ruff check .`
- Config in `pyproject.toml`
- set line-length, the Rules (*pycodestyle*, *pyflakes*, *pydocstyle*, *isort*),
the source files, and to ignore rule *F401* to not complain about unused imports
in `__init__` files.
- GitHub Actions:
- set line-length, the Rules (*pycodestyle*, *pyflakes*, *pydocstyle*, *isort*),
the source files, and to ignore rule *F401* to not complain about unused imports
in `__init__` files.
- GitHub Actions:
- run `ruff check --format=github .`
3. Use [MyPy](https://github.com/python/mypy) as for type checking.

3. Use [MyPy](https://github.com/python/mypy) as for type checking.
- Local terminal usage: `mypy`
- Config in `pyproject.toml`
- Specify files: `src/lorenzpy/`
- Ignore missing imports for `plotly`
- GitHub Actions:
- GitHub Actions:
- Just running `mypy`

4. Testing with [pytest-cov](https://github.com/pytest-dev/pytest-cov)
- Local terminal usage: `pytest`
- Config in `pyproject.toml`
- automatically add the following options when `pytest` is run:
- automatically add the following options when `pytest` is run:
- `--verbose --cov-config=pyproject.toml --cov-report term-missing --cov=lorenzpy`
- Note: This is somehow important for GitHub actions to work fine...
- Omit the `plot` folder for the coverage.
- GitHub Actions:
- Omit the `plot` folder for the coverage.
- GitHub Actions:
- simply running `pytest` and then uploading the coverage reports to [Codecov](https://about.codecov.io/)
using the GitHub action: [codecov-action](https://github.com/codecov/codecov-action)

5. Generating docs with [mkdocs](https://github.com/mkdocs/mkdocs):
- Following [this tutorial](https://realpython.com/python-project-documentation-with-mkdocs/)
- Generate the docs with `mkdocs gh-deploy`
- Use the plugin [mkdocstrings](https://github.com/mkdocstrings/mkdocstrings) to
automatically use the code-docstrings in the documentation.

**Deployment on PyPI**:
**Deployment on PyPI with GitHub Actions**:
- Following the [PyPA tutorial](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/)
- Also use [this PyPA tutorial](https://packaging.python.org/en/latest/tutorials/packaging-projects/) to manually upload the package to test PyPI.
- This uses `build` and `twine`

**Resources**:
Taking inspiration from:
https://github.com/dkmiller/modern-python-package, and
https://github.com/denkiwakame/py-tiny-pkg.
**Resources**:
Taking inspiration from:
https://github.com/dkmiller/modern-python-package, and
https://github.com/denkiwakame/py-tiny-pkg.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
[![Python versions](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)

## 🚧 Under construction 🚧
There is no release of the package yet and most of the functionalities are missing.
For now only the basic functionalities are implemented in order to build up the
developing workflow.
There is no release of the package yet and most of the functionalities are missing.
For now only the basic functionalities are implemented in order to build up the
developing workflow.

## Documentation:
## Documentation:
The documentation can be found here: https://duncdennis.github.io/lorenzpy/

## Installation:
## Installation:

#### User installation:
Only the core LorenzPy functionality:
#### User installation:
Only the core LorenzPy functionality:

``
pip install .
``

With plotting functionalities:
With plotting functionalities:

``
pip install .[plot]
Expand All @@ -35,6 +35,6 @@ pip install -e .[dev,plot]
``


## Resources:
## Resources:
#### Similar package: *pynamical*
https://github.com/gboeing/pynamical
10 changes: 5 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Welcome to LorenzPy

This site contains the documentation for the `LorenzPy` Python package
that can be used to simulate and measure discrete and continuous chaotic dynamical
This site contains the documentation for the `LorenzPy` Python package
that can be used to simulate and measure discrete and continuous chaotic dynamical
systems.

## Contents:
## Contents:

1. [Reference](reference.md) The API reference.
1. [Reference](reference.md) The API reference.

## Project Overview:
## Project Overview:
::: lorenzpy
4 changes: 2 additions & 2 deletions docs/reference.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
### LorenzPy package:
::: lorenzpy

### simulations module:
### simulations module:
::: lorenzpy.simulations

### measures module:
### measures module:
::: lorenzpy.measures
11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ dependencies = [
dev = [
"pytest==7.2.0",
"pytest-cov==4.0",
"black==22.12.0",
"black==23.1.0",
"mypy==1.1.1",
"ruff==0.0.254",
"mkdocs",
"mkdocstrings[python]",
"mkdocs-material"
"mkdocs", # add version?
"mkdocstrings[python]", # add version?
"mkdocs-material", # add version?
"pre-commit==3.1.1", # add version?
]
plot = [
"plotly==5.13.1",
Expand All @@ -50,7 +51,7 @@ line-length = 88
files = "src/lorenzpy/"

[[tool.mypy.overrides]]
module = ['plotly.*'] # ignore missing imports from the plotly package.
module = ['plotly.*', 'numpy', 'pytest'] # ignore missing imports from the plotly package.
ignore_missing_imports = true

[tool.ruff]
Expand Down
2 changes: 1 addition & 1 deletion src/lorenzpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

from . import measures, simulations

__version__ = "0.1.0"
__version__ = "0.0.1"
8 changes: 4 additions & 4 deletions src/lorenzpy/simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class _SimBase(ABC):

@abstractmethod
def iterate(self, x: np.ndarray) -> np.ndarray:
"""The abstract iterate function."""
"""Generate the next time step when the previous one is given."""

def simulate(
self, time_steps: int, starting_point: np.ndarray | None = None
Expand Down Expand Up @@ -124,10 +124,10 @@ class _SimBaseRungeKutta(_SimBase):

@abstractmethod
def flow(self, x: np.ndarray) -> np.ndarray:
"""The abstract flow function."""
"""Return the flow of the continuous dynamical system."""

def iterate(self, x: np.ndarray) -> np.ndarray:
"""Calculates next timestep x(t+dt) with given x(t) using runge kutta.
"""Calculate the next timestep x(t+dt) with given x(t) using runge kutta.
Args:
x: the previous point x(t).
Expand Down Expand Up @@ -178,7 +178,7 @@ def __init__(
self.dt = self.default_parameters["dt"] if dt is None else dt

def flow(self, x: np.ndarray) -> np.ndarray:
"""Calculates (dx/dt, dy/dt, dz/dt) with given (x,y,z) for RK4.
"""Calculate (dx/dt, dy/dt, dz/dt) with given (x,y,z) for RK4.
Args:
x: (x,y,z) coordinates. Needs to have shape (3,).
Expand Down

0 comments on commit 2e5f53a

Please sign in to comment.