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

Migrated to copier #34

Merged
merged 9 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install cookiecutter and generate a project
- name: Install copier and generate a project
run: |
python -m pip install cookiecutter
cookiecutter . --no-input
python -m pip install copier jinja2_time
copier copy . ./pybamm-example-project --trust --defaults

- name: Set up uv
uses: yezz123/setup-uv@v4
Expand Down
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ repos:
- id: rst-directive-colons
- id: rst-inline-touching-normal

# Jupyter notebooks

- repo: https://github.com/nbQA-dev/nbQA
rev: "1.8.5"
hooks:
- id: nbqa-ruff
additional_dependencies: [ruff==0.0.281]

# mypy

- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
34 changes: 15 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,36 @@

<!-- SPHINX-START -->
[![Powered by NumFOCUS](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](http://numfocus.org)
[![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-red.json)](https://github.com/copier-org/copier)

This repository contains a `cookiecutter` template for battery modeling projects using PyBaMM, released under the [BSD-3-Clause license](https://github.com/pybamm-team/pybamm-cookiecutter/blob/main/LICENSE). Currently under active development.
This repository contains a `copier` template for battery modeling projects using PyBaMM, released under the [BSD-3-Clause license](https://github.com/pybamm-team/pybamm-cookiecutter/blob/main/LICENSE). Currently under active development.

## 📄 Using `pybamm-cookiecutter`

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

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 `cookiecutter` to generate a project with this template.
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.

To use pybamm-cookiecutter template, first clone this repository on your local machine.
Install `copier` and `jinja2_time` extension using `pip`.
```bash
git clone https://github.com/pybamm-team/pybamm-cookiecutter.git
pip install copier jinja2-time
```
Create a temporary virtual environment inside the reposiory and activate it.
```bash
python3 -m venv venv
source venv/bin/activate
```
Install cookiecutter and generate the project using the pybamm-cookiecutter template by moving outside the parent pybamm-cookiecutter directory.
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
pip install cookiecutter
cookiecutter pybamm-cookiecutter/
copier copy https://github.com/pybamm-team/pybamm-cookiecutter.git name_of_your_project/ --trust
```

Cookiecutter will prompt you with various configurations and you may choose the ones that suit your use case.

**Note**: If you created a repository using this template within GitHub and cloned it locally, you can skip the next step.
Copier will prompt you with various configurations and you may choose the ones that suit your use case.

Once the project is generated through cookiecutter, initialise `git` by executing `git init` inside your project directory.
**Note**: A `git` repository is automatically initialised when a project is created within a directory.

After generation, you can navigate to the generated project and run `nox -s generated-project-tests` to ensure if the project units are working as intended.

### Installing the `pybamm-cookiecutter` project

This is our version of the project generated using the cookiecutter template. There are two ways to install this project, either through `nox` or `pip`. `nox` uses `uv pip` or `pip` internally, and in this case creates a virtual environment for you to activate.
This refers to the project used for the development of this template. There are two ways to install this project: either through `nox` or `pip`. `nox` uses `uv pip` or `pip` internally, and in this case, creates a virtual environment for you to activate.
To install, navigate to the root directory of this repository and execute either of these commands:

`nox -s dev`
Expand All @@ -70,7 +66,7 @@ To check if the project was successfully installed, import the project inside Py
```python
import pybamm_cookiecutter

pybamm_cookiecutter._version.version
pybamm_cookiecutter.__version__
```

## 🛠️ Contributing to `pybamm-cookiecutter`
Expand Down
92 changes: 92 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
project_name:
type: str
default: "pybamm-example-project"
help: "The name of your project"

project_slug:
type: str
help: The name of the directory containing the Python files for your project. This should be in `snake_case`, and this is what you will import it with, such as `import pybamm_example_project`.
default: "{{ project_name|lower|replace('-', '_')|replace(' ', '_') }}"
validator: |
{% if ('-' in project_slug or ' ' in project_slug) %}
The name of the directory should not contain spaces or hyphens
{% endif %}

platform:
type: str
choices:
- github
- gitlab
default: github
help: "The platform you are using to host your project"

org:
type: str
default: "pybamm-team"
help: "The name of your organisation (or username, if you are not part of an organisation)"

url:
type: str
default: "https://{{ platform }}.com/{{ org }}/{{ project_name }}"
help: "The origin URL to your code repository"

branch:
type: str
default: "main"
help: "The default branch of your repository"

full_name:
type: str
default: "John Doe"
help: "Your name on your hosting platform (will be used later as your committer name)"

email:
type: str
default: "john@doe.com"
help: "Your email for your hosting platform (will be used later to configure Git)"

project_short_description:
type: str
default: "A battery modelling project that uses the PyBaMM framework"
help: "A short description of your project"

license:
type: str
choices:
- BSD-3-Clause
- Apache
- MIT
default: BSD-3-Clause
help: "Select a license"

backend:
type: str
choices:
- "hatch"
default: "hatch"
help: "Choose a build backend. hatch (hatchling) is recommended for pure Python projects"

vcs:
type: bool
default: false
help: "Let hatch get the version from your version control system (Git/Mercurial/SVN) using the hatch-vcs plugin?"

mypy:
type: bool
default: false
help: "Use the mypy type checker"


_copy_without_render:
type: list
default: ["*.yml"]

_jinja_extensions:
- jinja2_time.TimeExtension

_subdirectory: template

_tasks:
- git init -b {{branch}}
- git config user.name {{full_name}}
- git config user.email {{email}}
23 changes: 0 additions & 23 deletions hooks/post_gen_project.py

This file was deleted.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ classifiers = [
"Typing :: Typed",
]
dynamic = ["version"]
dependencies = ["pybamm", "cookiecutter"]
dependencies = ["pybamm", "copier", "jinja2-time"]
santacodes marked this conversation as resolved.
Show resolved Hide resolved

[project.optional-dependencies]
dev = [
"pytest >=6",
"pytest-cov >=3",
"nox[uv]",
"pre-commit",
"pytest-cookies",
"pytest-copie",
]
docs = [
"sphinx",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ repos:
entry: PyBind|Numpy|Scipy|Cmake|CCache|Github|Pybamm
exclude: .pre-commit-config.yaml
{# keep this line here for newline #}
{%- if cookiecutter.mypy %}
{%- if mypy %}
# mypy

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
hooks:
- id: mypy
files: "^(src/{{ cookiecutter.__project_slug }}|tests$)"
files: "^(src/{{ __project_slug }}|tests$)"
{%- endif %}
File renamed without changes.
28 changes: 28 additions & 0 deletions template/README.md.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# {{ project_name }}

[![Actions Status][actions-badge]][actions-link]
[![Documentation Status][rtd-badge]][rtd-link]

[![PyPI version][pypi-version]][pypi-link]
[![Conda-Forge][conda-badge]][conda-link]
[![PyPI platforms][pypi-platforms]][pypi-link]

[![GitHub Discussions][github-discussions-badge]][github-discussions-link]

<!-- SPHINX-START -->

<!-- prettier-ignore-start -->

[actions-badge]: {{url}}/workflows/CI/badge.svg
[actions-link]: {{url}}/actions
[conda-badge]: https://img.shields.io/conda/vn/conda-forge/{{project_name}}
[conda-link]: https://github.com/conda-forge/{{project_name}}-feedstock
[github-discussions-badge]: https://img.shields.io/static/v1?label=Discussions&message=Ask&color=blue&logo=github
[github-discussions-link]: {{url}}/discussions
[pypi-link]: https://pypi.org/project/{{project_name}}/
[pypi-platforms]: https://img.shields.io/pypi/pyversions/{{project_name}}
[pypi-version]: https://img.shields.io/pypi/v/{{project_name}}
[rtd-badge]: https://readthedocs.org/projects/{{project_name}}/badge/?version=latest
[rtd-link]: https://{{project_name}}.readthedocs.io/en/latest/?badge=latest

<!-- prettier-ignore-end -->
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
from pathlib import Path

# ---- Project information ------------------------------------------------------------

project = "{{ cookiecutter.project_name }}"
copyright = "{{ cookiecutter.__year }}, {{ cookiecutter.full_name }}"
author = "{{ cookiecutter.full_name }}"
version = release = importlib.metadata.version("{{ cookiecutter.__project_slug }}")
project = "{{ project_name }}"
copyright = "{% now 'utc', '%Y' %}, {{ full_name }}"
author = "{{ full_name }}"
version = release = importlib.metadata.version("{{ project_slug }}")

# ---- Path configuration -------------------------------------------------------------

Expand Down Expand Up @@ -134,18 +133,18 @@
# },
"icon_links": [
{
{%- if cookiecutter.platform == "github" %}
{%- if platform == "github" %}
"name": "GitHub",
"icon": "fa-brands fa-square-github",
{%- elif cookiecutter.platform == "gitlab" %}
{%- elif platform == "gitlab" %}
"name": "GitLab",
"icon": "fa-brands fa-square-gitlab",
{%- endif %}
"url": "{{ cookiecutter.url }}",
"url": "{{ url }}",
},
{
"name": "PyPI",
"url": "https://pypi.org/project/{{ cookiecutter.project_name }}/",
"url": "https://pypi.org/project/{{ project_name }}/",
"icon": "fa-solid fa-box",
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# {{ cookiecutter.project_name }}
# {{ project_name }}

```{toctree}
:maxdepth: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def run_user_tests(session):
@nox.session(name="coverage")
def run_coverage(session):
"""Run the coverage tests and generate an XML report."""
session.posargs.append("--cov=src/pybamm_cookiecutter")
session.posargs.append("--cov=src/{{project_slug}}")
session.posargs.append("--cov-report=xml")
run_user_tests(session)

Expand Down
Loading
Loading