Skip to content

Commit

Permalink
Added parameter entry points (#15)
Browse files Browse the repository at this point in the history
Additions - 
+ `parameter_sets.py` from the main PyBaMM repository which acts as an
entry point for the parameter sets mapped through the group
`cookie_parameter_sets`.
+ `Chen2020.py` to test and load a parameter set through the entry point
to ensure that everything works.
+ Tests to test the entry points.

Updates - 
- A nox `dev` session. 
- Updated rules in compliance with the main PyBaMM repository in
`pyproject.toml`.

Accessing parameter sets through entry points here is the same as
accessing it through PyBaMM. Instead using `pybamm.parameter_sets` here
it would imply `pybamm_cookiecutter.paramter_sets` to access them. I
think it would make it easier for current users to adapt to the template
as the implementations are almost the same. Before release, the template
should be modified in compliance with the module name a user would give.

---------

Co-authored-by: Arjun Verma <arjunverma.oc@gmail.com>
Co-authored-by: Ferran Brosa Planella <Ferran.Brosa-Planella@warwick.ac.uk>
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
  • Loading branch information
4 people authored Jul 8, 2024
1 parent 341cf53 commit 6636bcf
Show file tree
Hide file tree
Showing 9 changed files with 579 additions and 28 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2023, PyBaMM Team
Copyright (c) 2024, PyBaMM Team

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down
7 changes: 7 additions & 0 deletions LICENSES-bundled.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This project and source distributions bundle several libraries that are
compatibly licensed.


Name: PyBaMM
Files: src/pybamm_cookiecutter/parameters/*
License: BSD-3-Clause
12 changes: 12 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import nox
from pathlib import Path
import os

# Options to modify nox behaviour
nox.options.default_venv_backend = "uv|virtualenv"
nox.options.reuse_existing_virtualenvs = True

VENV_DIR = Path("./venv").resolve()

@nox.session(name="docs")
def build_docs(session: nox.Session) -> None:
"""Build the documentation and load it in a browser tab, rebuilding on changes."""
Expand All @@ -26,3 +30,11 @@ def run_template_generation(session):
session.install("setuptools", silent=False)
session.install("-e", ".[dev]", silent=False)
session.run("pytest", "tests")

@nox.session(name="dev")
def set_dev(session):
"""Install pybamm-cookiecutter in editable mode"""
session.install("virtualenv")
session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True)
python = os.fsdecode(VENV_DIR.joinpath("bin/python"))
session.run(python, "-m", "pip", "install", "-e", ".[dev]")
68 changes: 41 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ Homepage = "https://github.com/pybamm-team/pybamm-cookiecutter"
Discussions = "https://github.com/pybamm-team/pybamm-cookiecutter/discussions"
Changelog = "https://github.com/pybamm-team/pybamm-cookiecutter/releases"

[project.entry-points."cookie_parameter_sets"]
Chen2020 = "pybamm_cookiecutter.parameters.input.Chen2020:get_parameter_values"

[tool.hatch]
version.source = "vcs"
build.hooks.vcs.version-file = "src/pybamm_cookiecutter/_version.py"
Expand All @@ -73,8 +76,8 @@ packages = [
"src/pybamm_cookiecutter",
"tests"
]
python_version = "3.8"
strict = true
python_version = "3.11"
strict = false
warn_return_any = false
show_error_codes = true
enable_error_code = [
Expand All @@ -84,6 +87,9 @@ enable_error_code = [
]
disallow_untyped_defs = false
disallow_untyped_calls = false
ignore_missing_imports = true
allow_redefinition = true
disable_error_code = ["call-overload", "operator"]

[tool.coverage]
run.source = ["pybamm_cookiecutter"]
Expand All @@ -92,32 +98,40 @@ port.exclude_lines = [
]

[tool.ruff]
select = [
"E", "F", "W", # flake8
"B", # flake8-bugbear
"I", # isort
"ARG", # flake8-unused-arguments
"C4", # flake8-comprehensions
"EM", # flake8-errmsg
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"G", # flake8-logging-format
"PGH", # pygrep-hooks
"PIE", # flake8-pie
"PL", # pylint
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"RET", # flake8-return
"RUF", # Ruff-specific
"SIM", # flake8-simplify
"T20", # flake8-print
"UP", # pyupgrade
"YTT", # flake8-2020
"EXE", # flake8-executable
"NPY", # NumPy specific rules
"PD", # pandas-vet
]
extend-include = ["*.ipynb"]
extend-exclude = ["__init__.py"]
src = ["src"]
exclude = []
isort.required-imports = ["from __future__ import annotations"]
flake8-unused-arguments.ignore-variadic-names = true


[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
"RUF", # Ruff-specific
"UP", # pyupgrade
"YTT", # flake8-2020
"TID252", # relative-imports
]
ignore = [
"E741", # Ambiguous variable name
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"SIM108", # Use ternary operator
"ARG001", # Unused function argument:
"ARG002", # Unused method arguments
"PLR2004", # Magic value used in comparison
"PLR0915", # Too many statements
"PLR0913", # Too many arguments
"PLR0912", # Too many branches
"RET504", # Unnecessary assignment
"RET505", # Unnecessary `else`
"RET506", # Unnecessary `elif`
"B018", # Found useless expression
"RUF002", # Docstring contains ambiguous
"UP007", # For pyupgrade
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["T20"]
"docs/*" = ["T20"]
2 changes: 2 additions & 0 deletions src/pybamm_cookiecutter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import pybamm

from ._version import version as __version__
from .parameters.parameter_sets import parameter_sets

__all__ : list[str] = [
"__version__",
"pybamm",
"parameter_sets",
]
3 changes: 3 additions & 0 deletions src/pybamm_cookiecutter/parameters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from __future__ import annotations

__all__ = ["parameter_sets",]
Loading

0 comments on commit 6636bcf

Please sign in to comment.