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

Added pybamm-cookiecutter CLI #36

Merged
merged 25 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bd1f36e
added the pybamm_cookiecutter CLI
santacodes Aug 1, 2024
b1f4568
removed project tests
santacodes Aug 2, 2024
96ec3f2
fix template generation tests
santacodes Aug 2, 2024
fd060f7
Apply suggestions from code review
santacodes Aug 2, 2024
da1e566
changes in documentation and bundled licenses
santacodes Aug 2, 2024
5137e29
added colorama as a dependency
santacodes Aug 2, 2024
5dedc7f
fixed template reference and git init working directory
santacodes Aug 2, 2024
169366a
Apply suggestions from code review
santacodes Aug 6, 2024
9617009
Merge branch 'main' into cli
santacodes Aug 6, 2024
0f49cbd
edited readme and changed into absolute imports
santacodes Aug 6, 2024
d740cde
fix failing doctests inside generated project
santacodes Aug 6, 2024
d49e1ba
resolved merge conflicts
santacodes Aug 6, 2024
ac497cc
fixed failing tests
santacodes Aug 6, 2024
9788104
Update README.md
santacodes Aug 8, 2024
5e08eb6
fixed packaging for the project wheels
santacodes Aug 12, 2024
bfb8a81
Merge branch 'main' into cli
santacodes Aug 13, 2024
0af65f1
added defaults and version flag in cli along with a cli test
santacodes Aug 13, 2024
074995a
Apply suggestions from code review
santacodes Aug 14, 2024
1d89eab
removed pipx for cli tests
santacodes Aug 14, 2024
4a04d90
untracking _version.py
santacodes Aug 14, 2024
bb1e154
Delete src/pybamm_cookiecutter/_version.py
santacodes Aug 14, 2024
24d87d1
Merge branch 'main' into cli
santacodes Aug 14, 2024
ddb4718
moved git archives
santacodes Aug 14, 2024
72a8447
added tests badge to README
santacodes Aug 14, 2024
3b7bc62
moved LICENSES-bundled to template
santacodes Aug 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ jobs:
- name: Test template generation
run: nox -s template-tests

- name: Test project
run: nox -s project-tests

- name: Run coverage tests
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
run: nox -s coverage
Expand Down Expand Up @@ -121,7 +118,7 @@ jobs:
- name: Install copier and generate a project
run: |
python -m pip install copier jinja2_time
copier copy . ./pybamm-example-project --trust --defaults
copier copy . . --trust --defaults

- name: Set up uv
uses: yezz123/setup-uv@v4
Expand Down
5 changes: 4 additions & 1 deletion LICENSES-bundled.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ compatibly licensed.


Name: PyBaMM
Files: src/pybamm_cookiecutter/parameters/*
Files: - src/{{ project_slug }}/parameters/input/Chen2020.py
- src/{{ project_slug }}/models/input/BasicReservoir.py
- src/{{ project_slug }}/models/input/SPM.py
- src/{{ project_slug }}/entry_point.py
License: BSD-3-Clause
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,31 @@ This repository contains a `copier` template for battery modeling projects using

## 📄 Using `pybamm-cookiecutter`

### Generating projects with `pybamm-cookiecutter` manually using copier
### Generating projects with `pybamm-cookiecutter`

This template is not on PyPI yet, so it cannot be installed through `pip` until the first release. Meanwhile, it can be used by cloning this repository and using `copier` to generate a project with this template.
#### Manually using copier

Install `copier` and `jinja2_time` extension using `pip`.
```bash
pip install copier jinja2-time
```
Generate a project from the `pybamm-cookiecutter` template.
**Note:** This requires an internet connection. You could manually clone the git repository and run the copy command, or just execute the copy command with the URL to the git repository.

```bash
copier copy https://github.com/pybamm-team/pybamm-cookiecutter.git name_of_your_project/ --trust
copier copy https://github.com/pybamm-team/pybamm-cookiecutter.git . --trust
# this will generate the project in the current working directory
copier copy https://github.com/pybamm-team/pybamm-cookiecutter.git path_to_copy_to/ --trust
# this will generate the project in the specified path
```
#### Using pipx
santacodes marked this conversation as resolved.
Show resolved Hide resolved

Install the `pybamm-cookiecutter` package.
```bash
pipx install pybamm-cookiecutter
santacodes marked this conversation as resolved.
Show resolved Hide resolved
```
Navigate into the directory you want your project directory to reside in, or use `--path` argument to explicitly mention the path where you want your project to be generated.
```bash
pybamm-cookiecutter --path /path_to_copy_to
```
santacodes marked this conversation as resolved.
Show resolved Hide resolved

Copier will prompt you with various configurations and you may choose the ones that suit your use case.
Expand Down
9 changes: 6 additions & 3 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ _jinja_extensions:
_subdirectory: template

_tasks:
- git init -b {{branch}}
- git config user.name {{full_name}}
- git config user.email {{email}}
- command: git init -b {{branch}}
working_directory: "{{project_name}}"
- command: git config user.name {{full_name}}
working_directory: "{{project_name}}"
- command: git config user.email {{email}}
working_directory: "{{project_name}}"
5 changes: 0 additions & 5 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ def run_template_generation(session):
"""Run tests for the template generation."""
install_and_run_tests(session, "tests/template_tests")

@nox.session(name="project-tests")
def run_project_tests(session):
"""Run the tests for testing project units"""
install_and_run_tests(session, "tests/project_tests")

@nox.session(name="coverage")
def run_coverage(session):
"""Run the coverage tests and generate an XML report."""
Expand Down
15 changes: 7 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ classifiers = [
"Typing :: Typed",
]
dynamic = ["version"]
dependencies = ["pybamm", "copier", "jinja2-time"]
dependencies = ["copier", "jinja2-time", "colorama"]

[project.optional-dependencies]
dev = [
Expand All @@ -55,19 +55,18 @@ docs = [
"sphinx-gallery",
]

[project.scripts]
pybamm-cookiecutter = "pybamm_cookiecutter.cli:pybamm_cookiecutter_cli"

[project.entry-points."pipx.run"]
pybamm-cookiecutter = "pybamm_cookiecutter.cli:pybamm_cookiecutter_cli"

[project.urls]
Homepage = "https://github.com/pybamm-team/pybamm-cookiecutter"
"Bug Tracker" = "https://github.com/pybamm-team/pybamm-cookiecutter/issues"
Discussions = "https://github.com/pybamm-team/pybamm-cookiecutter/discussions"
Changelog = "https://github.com/pybamm-team/pybamm-cookiecutter/releases"

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

[project.entry-points."models"]
SPM = "pybamm_cookiecutter.models.input.SPM:SPM"
BasicReservoir = "pybamm_cookiecutter.models.input.BasicReservoir:BasicReservoir"

[tool.hatch]
version.source = "vcs"
build.hooks.vcs.version-file = "src/pybamm_cookiecutter/_version.py"
Expand Down
9 changes: 2 additions & 7 deletions src/pybamm_cookiecutter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@
"""
from __future__ import annotations

import pybamm

from ._version import version as __version__
from .entry_point import Model, parameter_sets, models
from .cli import pybamm_cookiecutter_cli
santacodes marked this conversation as resolved.
Show resolved Hide resolved

__all__ : list[str] = [
"__version__",
"pybamm",
"parameter_sets",
"Model",
"models",
"pybamm_cookiecutter_cli",
]
3 changes: 3 additions & 0 deletions src/pybamm_cookiecutter/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if __name__ == "__main__":
from pybamm_cookiecutter.cli import pybamm_cookiecutter_cli
pybamm_cookiecutter_cli()
santacodes marked this conversation as resolved.
Show resolved Hide resolved
40 changes: 40 additions & 0 deletions src/pybamm_cookiecutter/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import copier
import argparse
from pathlib import Path
from colorama import Fore
import os
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved

TEMPLATE = str(Path.cwd())

def pybamm_cookiecutter_cli():
"""
Command Line Interface (CLI) for generating PyBaMM based projects using copier.

Parameters
----------
--path: pathlib.Path

Examples
-------
$ pybamm-cookiecutter
Generates a project in the current working directory of the terminal.
$ pybamm-cookiecutter --path /myproject
Generates a project in the `myproject` directory.
"""
try:
parser = argparse.ArgumentParser(description = "A copier template generator for PyBaMM based projects")
parser.add_argument("--path", type = str, required = False, default = os.getcwd(),
help = "The destination path for project generation")
santacodes marked this conversation as resolved.
Show resolved Hide resolved

args = parser.parse_args()
destination_path = Path(args.path)

copier.run_copy(src_path = TEMPLATE, dst_path = destination_path, unsafe=True)

except Exception as error:
print(Fore.RED + "Error caused by an exception: " + Fore.RESET, error)
print(Fore.CYAN + "If you are unsure what the error is, feel free to open an issue at" + Fore.YELLOW +" - https://github.com/pybamm-team/pybamm-cookiecutter/issues" + Fore.RESET)

if __name__ == '__main__':

pybamm_cookiecutter_cli()
154 changes: 0 additions & 154 deletions src/pybamm_cookiecutter/entry_point.py

This file was deleted.

Loading
Loading