diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..f19633a --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -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/action@v3.0.0 diff --git a/.github/workflows/testing.yml b/.github/workflows/test_and_coverage.yml similarity index 71% rename from .github/workflows/testing.yml rename to .github/workflows/test_and_coverage.yml index 25fa267..a484743 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/test_and_coverage.yml @@ -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: @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..de0b44c --- /dev/null +++ b/.pre-commit-config.yaml @@ -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] diff --git a/CHANGELOG.md b/CHANGELOG.md index b838ac4..36b728f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/README.md b/README.md index 0365c2c..f5df1c5 100644 --- a/README.md +++ b/README.md @@ -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] @@ -35,6 +35,6 @@ pip install -e .[dev,plot] `` -## Resources: +## Resources: #### Similar package: *pynamical* https://github.com/gboeing/pynamical diff --git a/docs/index.md b/docs/index.md index a3cb61c..f0456f5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 diff --git a/docs/reference.md b/docs/reference.md index a5fef88..bc2a841 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -1,8 +1,8 @@ ### LorenzPy package: ::: lorenzpy -### simulations module: +### simulations module: ::: lorenzpy.simulations -### measures module: +### measures module: ::: lorenzpy.measures diff --git a/pyproject.toml b/pyproject.toml index c6ccdc8..15b0014 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -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] diff --git a/src/lorenzpy/__init__.py b/src/lorenzpy/__init__.py index d9c57ab..80d29da 100644 --- a/src/lorenzpy/__init__.py +++ b/src/lorenzpy/__init__.py @@ -8,4 +8,4 @@ from . import measures, simulations -__version__ = "0.1.0" +__version__ = "0.0.1" diff --git a/src/lorenzpy/simulations.py b/src/lorenzpy/simulations.py index db0ba4f..da6ef51 100644 --- a/src/lorenzpy/simulations.py +++ b/src/lorenzpy/simulations.py @@ -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 @@ -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). @@ -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,).