Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PEP517/518 pyproject.toml support #203

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Features

- [#203](https://github.com/pybop-team/PyBOP/pull/203) - Adds support for modern Python packaging via a `pyproject.toml` file and configures the `pytest` test runner and `ruff` linter to use their configurations stored as declarative metadata.
- [#123](https://github.com/pybop-team/PyBOP/issues/123) - Configures scheduled tests to run against the last three PyPI releases of PyBaMM via dynamic GitHub Actions matrix generation.
- [#187](https://github.com/pybop-team/PyBOP/issues/187) - Adds M1 Github runner to `test_on_push` workflow, updt. self-hosted supported python versions in scheduled tests.
- [#118](https://github.com/pybop-team/PyBOP/issues/118) - Adds example jupyter notebooks.
Expand Down
20 changes: 11 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ If you'd like to contribute to PyBOP, please have a look at the guidelines below

## Developer-Installation

To install PyBOP for development purposes, which includes the testing and plotting dependencies, use the `[all]` flag as demonstrated below:
To install PyBOP for development purposes, which includes the plotting dependencies, use the `[all]` and the `[dev]` flags as demonstrated below:

For `zsh`:

```sh
pip install -e '.[all]'
pip install -e '.[all,dev]'
```

For `bash`:
```sh
pip install -e .[all]
pip install -e .[all,dev]
```

## Pre-commit checks

Before you commit any code, please perform the following checks using [Nox](https://nox.thea.codes/en/stable/index.html):
Expand All @@ -40,7 +42,7 @@ If you would like to skip the failing checks and push the code for further discu

## Workflow

We use [GIT](https://en.wikipedia.org/wiki/Git) and [GitHub](https://en.wikipedia.org/wiki/GitHub) to coordinate our work. When making any kind of update, we try to follow the procedure below.
We use [Git](https://en.wikipedia.org/wiki/Git) and [GitHub](https://en.wikipedia.org/wiki/GitHub) to coordinate our work. When making any kind of update, we try to follow the procedure below.

### A. Before you begin

Expand Down Expand Up @@ -105,8 +107,8 @@ On the other hand... We _do_ want to compare several tools, to generate document

1. Core PyBOP: A minimal set, including things like NumPy, SciPy, etc. All infrastructure should run against this set of dependencies, as well as any numerical methods we implement ourselves.
2. Extras: Other inference packages and their dependencies. Methods we don't want to implement ourselves, but do want to provide an interface to can have their dependencies added here.
3. Documentation generating code: Everything you need to generate and work on the docs.
4. Development code: Everything you need to do PyBOP development (so all of the above packages, plus ruff and other testing tools).
3. Documentation generating code: Everything you need to generate and work on the docs. This is managed by the `[docs]` set of extras.
4. Development code: Everything you need to do PyBOP development (so all of the above packages, plus ruff and other testing tools). This is managed by the `[dev]` set of extras.

Only 'core pybop' is installed by default. The others have to be specified explicitly when running the installation command.

Expand Down Expand Up @@ -283,14 +285,14 @@ as above, and then use some of the profiling tools. In order of increasing detai

## Infrastructure

### Setuptools
### Installation via `pip`

Installation of PyBOP _and dependencies_ is handled via [setuptools](http://setuptools.readthedocs.io/)
Installation of PyBOP and its dependencies is handled via [`pip`](https://pip.pypa.io/) through the [setuptools](http://setuptools.readthedocs.io/) build-backend.

Configuration files:

```
setup.py
pyproject.toml
```

Note that this file must be kept in sync with the version number in [pybop/**init**.py](https://github.com/pybop-team/PyBOP/blob/develop/pybop/__init__.py).
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
sys.path.insert(0, root_path)

from pybop.version import __version__ # noqa: E402
from pybop._version import __version__ # noqa: E402

# -- Project information -----------------------------------------------------
project = "PyBOP"
Expand Down
9 changes: 3 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@

@nox.session
def unit(session):
session.install("-e", ".[all]", silent=False)
session.install("-e", ".[all,dev]", silent=False)
if PYBOP_SCHEDULED:
session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False)
session.install("pytest", "pytest-mock", silent=False)
session.run("pytest", "--unit")


@nox.session
def coverage(session):
session.install("-e", ".[all]", silent=False)
session.install("-e", ".[all,dev]", silent=False)
if PYBOP_SCHEDULED:
session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False)
session.install("pytest", "pytest-cov", "pytest-mock", silent=False)
session.run(
"pytest",
"--unit",
Expand All @@ -38,10 +36,9 @@ def coverage(session):
@nox.session
def notebooks(session):
"""Run the examples tests for Jupyter notebooks."""
session.install("-e", ".[all]", silent=False)
session.install("-e", ".[all,dev]", silent=False)
if PYBOP_SCHEDULED:
session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False)
session.install("pytest", "nbmake", silent=False)
session.run("pytest", "--nbmake", "--examples", "examples/", external=True)


Expand Down
2 changes: 1 addition & 1 deletion pybop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#
# Version info
#
from pybop.version import __version__
from pybop._version import __version__

#
# Constants
Expand Down
3 changes: 3 additions & 0 deletions pybop/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import importlib.metadata

__version__ = importlib.metadata.version("pybop")
1 change: 0 additions & 1 deletion pybop/version.py

This file was deleted.

69 changes: 69 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[build-system]
requires = ["setuptools>=64"]
build-backend = "setuptools.build_meta"

[project]
name = "pybop"
version = "23.12"
authors = [
{name = "The PyBOP Team"},
]
maintainers = [
{name = "The PyBOP Team"},
]
description = "Python Battery Optimisation and Parameterisation"
readme = "README.md"
license = { file = "LICENSE" }
# https://pypi.org/classifiers/
classifiers = []
requires-python = ">=3.8, <3.12"
dependencies = [
"pybamm>=23.5",
"numpy>=1.16",
"scipy>=1.3",
"pandas>=1.0",
"pints>=0.5",
]

[project.optional-dependencies]
plot = ["plotly>=5.0"]
docs = [
"pydata-sphinx-theme",
"sphinx>=6",
"sphinx-autobuild",
"sphinx-autoapi",
"sphinx_copybutton",
"sphinx_favicon",
"sphinx_design",
"myst-parser",
]
dev = [
"nox",
"nbmake",
"pre-commit",
"pytest>=6",
"pytest-cov",
"pytest-mock",
"pytest-xdist",
"ruff",
]
all = ["pybop[plot]"]
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved

[tool.setuptools.packages.find]
include = ["pybop", "pybop.*"]

[project.urls]
Homepage = "https://github.com/pybop-team/PyBOP"

[tool.pytest.ini_options]
addopts = "--showlocals -v"

[tool.ruff]
extend-include = ["*.ipynb"]
extend-exclude = ["__init__.py"]

[tool.ruff.lint]
ignore = ["E501","E741"]

[tool.ruff.lint.per-file-ignores]
"**.ipynb" = ["E402", "E703"]
3 changes: 0 additions & 3 deletions pytest.ini

This file was deleted.

8 changes: 0 additions & 8 deletions ruff.toml

This file was deleted.

51 changes: 0 additions & 51 deletions setup.py

This file was deleted.

Loading