From 505a588ca99fe89281cf0af96a7695b4d7faf873 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:04:49 +0530 Subject: [PATCH 1/9] Make PyBOP version private attr, use `importlib.metadata` --- docs/conf.py | 2 +- pybop/__init__.py | 2 +- pybop/_version.py | 3 +++ pybop/version.py | 1 - 4 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 pybop/_version.py delete mode 100644 pybop/version.py diff --git a/docs/conf.py b/docs/conf.py index 2b8b9278e..ae94c5adf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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" diff --git a/pybop/__init__.py b/pybop/__init__.py index 1e8227101..b623add9e 100644 --- a/pybop/__init__.py +++ b/pybop/__init__.py @@ -12,7 +12,7 @@ # # Version info # -from pybop.version import __version__ +from pybop._version import __version__ # # Constants diff --git a/pybop/_version.py b/pybop/_version.py new file mode 100644 index 000000000..44f0ff34e --- /dev/null +++ b/pybop/_version.py @@ -0,0 +1,3 @@ +import importlib.metadata + +__version__ = importlib.metadata.version("pybop") diff --git a/pybop/version.py b/pybop/version.py deleted file mode 100644 index f3d58cf85..000000000 --- a/pybop/version.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "23.12" From b07ca7f21703f60f8d185b12a9b12a9ad3c8fe3f Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:05:51 +0530 Subject: [PATCH 2/9] Remove distutils & metadata boilerplate, shift to PEP517 --- setup.py | 52 ++-------------------------------------------------- 1 file changed, 2 insertions(+), 50 deletions(-) diff --git a/setup.py b/setup.py index 5a3697807..4d6c06e08 100644 --- a/setup.py +++ b/setup.py @@ -1,51 +1,3 @@ -from distutils.core import setup -import os -from setuptools import find_packages +from setuptools import setup, find_packages -# User-friendly description from README.md -current_directory = os.path.dirname(os.path.abspath(__file__)) -try: - with open(os.path.join(current_directory, "README.md"), encoding="utf-8") as f: - long_description = f.read() -except Exception: - long_description = "" - -# Defines __version__ -root = os.path.abspath(os.path.dirname(__file__)) -with open(os.path.join(root, "pybop", "version.py")) as f: - exec(f.read()) - -setup( - name="pybop", - packages=find_packages("."), - version=__version__, # noqa F821 - license="BSD-3-Clause", - description="Python Battery Optimisation and Parameterisation", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/pybop-team/PyBOP", - install_requires=[ - "pybamm>=23.5", - "numpy>=1.16", - "scipy>=1.3", - "pandas>=1.0", - "pints>=0.5", - ], - extras_require={ - "plot": ["plotly>=5.0"], - "all": ["pybop[plot]"], - "docs": [ - "sphinx>=6", - "pydata-sphinx-theme", - "sphinx-autobuild", - "sphinx-autoapi", - "sphinx_copybutton", - "sphinx_favicon", - "sphinx_design", - "myst-parser", - ], - }, - # https://pypi.org/classifiers/ - classifiers=[], - python_requires=">=3.8,<=3.12", -) +setup(packages=find_packages(where=".")) From 388496ba9426ee793e39a15c9bfb05db71826f73 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:11:06 +0530 Subject: [PATCH 3/9] Move `pytest`, `ruff` config to `pyproject.toml` --- pytest.ini | 3 --- ruff.toml | 8 -------- 2 files changed, 11 deletions(-) delete mode 100644 pytest.ini delete mode 100644 ruff.toml diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index ab0a003d6..000000000 --- a/pytest.ini +++ /dev/null @@ -1,3 +0,0 @@ -# pytest.ini -[pytest] -addopts = --showlocals -v diff --git a/ruff.toml b/ruff.toml deleted file mode 100644 index 29a4a2442..000000000 --- a/ruff.toml +++ /dev/null @@ -1,8 +0,0 @@ -extend-include = ["*.ipynb"] -extend-exclude = ["__init__.py"] - -[lint] -ignore = ["E501","E741"] - -[lint.per-file-ignores] -"**.ipynb" = ["E402", "E703"] From aa6a9d25dad9c1dd149173efea5110fa3a2930a9 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:11:35 +0530 Subject: [PATCH 4/9] Migrate to `pyproject.toml` (declarative metadata) --- pyproject.toml | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 3 --- 2 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..ca8f61856 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,59 @@ +[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 = [ + "sphinx>=6", + "pydata-sphinx-theme", + "sphinx-autobuild", + "sphinx-autoapi", + "sphinx_copybutton", + "sphinx_favicon", + "sphinx_design", + "myst-parser", +] +all = ["pybop[plot]"] + +[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"] diff --git a/setup.py b/setup.py deleted file mode 100644 index 4d6c06e08..000000000 --- a/setup.py +++ /dev/null @@ -1,3 +0,0 @@ -from setuptools import setup, find_packages - -setup(packages=find_packages(where=".")) From 913fcdee814e9bd510d2564f7a005324c74391af Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:28:01 +0530 Subject: [PATCH 5/9] Add CHANGELOG entry for `pyproject.toml` --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d089db95f..c3443f09b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. From 2af4397273df60605cfb5f9420d380d8928be953 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Mon, 19 Feb 2024 15:07:55 +0530 Subject: [PATCH 6/9] update Python version requirements to remove 3.12 Co-Authored-By: Brady Planden <55357039+BradyPlanden@users.noreply.github.com> --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ca8f61856..58f02a4f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ readme = "README.md" license = { file = "LICENSE" } # https://pypi.org/classifiers/ classifiers = [] -requires-python = ">=3.8, <=3.12" +requires-python = ">=3.8, <3.12" dependencies = [ "pybamm>=23.5", "numpy>=1.16", From 9bc2c306bd78457ab4c59dae1c2f64a8239e3662 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Mon, 19 Feb 2024 17:14:12 +0530 Subject: [PATCH 7/9] Make notes about `[dev]` and `[docs]` extras, revise config --- CONTRIBUTING.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9fecf0c01..6d6f8aaa3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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): @@ -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 @@ -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. @@ -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). From a6e32a16bf5f62c5f98c0909a872ca1fe395bbb4 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Mon, 19 Feb 2024 17:14:51 +0530 Subject: [PATCH 8/9] Add the `[dev]` extras (pytest, nbmake, pre-commit) --- pyproject.toml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 58f02a4f4..38bf5f1c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,8 +28,8 @@ dependencies = [ [project.optional-dependencies] plot = ["plotly>=5.0"] docs = [ - "sphinx>=6", "pydata-sphinx-theme", + "sphinx>=6", "sphinx-autobuild", "sphinx-autoapi", "sphinx_copybutton", @@ -37,6 +37,16 @@ docs = [ "sphinx_design", "myst-parser", ] +dev = [ + "nox", + "nbmake", + "pre-commit", + "pytest>=6", + "pytest-cov", + "pytest-mock", + "pytest-xdist", + "ruff", + ] all = ["pybop[plot]"] [tool.setuptools.packages.find] From 45df79646dc393dd395a45d52d2031fb2381ed7e Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Mon, 19 Feb 2024 17:15:19 +0530 Subject: [PATCH 9/9] Use `[dev]` extras for nox session invocations --- noxfile.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/noxfile.py b/noxfile.py index c14e5b880..e88df2604 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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", @@ -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)