Skip to content

Commit

Permalink
added code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
santacodes committed Jun 24, 2024
1 parent 5374988 commit 601df87
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 33 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) 2023-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
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ def set_dev(session):
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]")
session.run(python, "-m", "uv", "pip", "install", "-e", ".[dev]")
13 changes: 0 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,7 @@ flake8-unused-arguments.ignore-variadic-names = true
[tool.ruff.lint]
extend-select = [
"B", # flake8-bugbear
# "I", # isort
# "ARG", # flake8-unused-arguments
# "C4", # flake8-comprehensions
# "ICN", # flake8-import-conventions
# "ISC", # flake8-implicit-str-concat
# "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
"TID252", # relative-imports
Expand Down
33 changes: 32 additions & 1 deletion src/pybamm_cookiecutter/parameters/input/Chen2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,38 @@

import numpy as np
import pybamm

"""
This code is adopted from the PyBaMM project under the BSD 3-Clause
Copyright (c) 2018-2024, the PyBaMM team.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

def graphite_LGM50_ocp_Chen2020(sto):
"""
Expand Down
47 changes: 33 additions & 14 deletions src/pybamm_cookiecutter/parameters/parameter_sets.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
from __future__ import annotations

import importlib.metadata
import sys
import textwrap
import warnings
from collections.abc import Mapping
from typing import Callable


"""
This code is adopted from the PyBaMM project under the BSD 3-Clause
Copyright (c) 2018-2024, the PyBaMM team.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

class ParameterSets(Mapping):
"""
Dict-like interface for accessing parameter sets through entry points in cookiecutter template.
Expand Down Expand Up @@ -85,17 +114,7 @@ def __getattribute__(self, name):
try:
return super().__getattribute__(name)
except AttributeError as error:
# For backwards compatibility, parameter sets that used to be defined in
# this file now return the name as a string, which will load the same
# parameter set as before when passed to `ParameterValues`
if name in self:
msg = (
f"Parameter sets should be called directly by their name ({name}), "
f"instead of via pybamm_cookiecutter.parameter_sets (pybamm_cookiecutter.parameter_sets.{name})."
)
warnings.warn(msg, DeprecationWarning, stacklevel=2)
return name
raise error
raise error

#: Singleton Instance of :class:ParameterSets """
parameter_sets = ParameterSets()
6 changes: 3 additions & 3 deletions tests/test_entry_points.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import pytest
import pybamm_cookiecutter
import glob
import importlib.util
import sys
from pathlib import Path

def test_entry_points():
"""Testing if the entry points are loading right"""

entry_points = list(pybamm_cookiecutter.parameter_sets)
parameter_sets = glob.glob("src/pybamm_cookiecutter/parameters/input/*.py")
parameter_sets = Path("src/pybamm_cookiecutter/parameters/input/").glob("*.py")
# Making a list Parameter sets in the parameters/input directory
parameter_sets = [x.split('/')[-1].split('.py')[0] for x in parameter_sets]
parameter_sets = [str(x).split('/')[-1].split('.py')[0] for x in parameter_sets]

assert parameter_sets == entry_points, "Entry points missing either in pyproject.toml or in the input directory"

Expand Down

0 comments on commit 601df87

Please sign in to comment.