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 4 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
4 changes: 2 additions & 2 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ jobs:

- name: Install cookiecutter and generate a project
santacodes marked this conversation as resolved.
Show resolved Hide resolved
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
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: Your Python package name (should be in `snake_case`)
default: "{{ project_name|lower|replace('-', '_')|replace(' ', '_') }}"
validator: |
{% if ('-' in project_slug or ' ' in project_slug) %}
Package name should not contain empty spaces or hyphens
{% endif %}

santacodes marked this conversation as resolved.
Show resolved Hide resolved
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 repository"
santacodes marked this conversation as resolved.
Show resolved Hide resolved

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 template for creating battery modeling projects based on PyBaMM"
santacodes marked this conversation as resolved.
Show resolved Hide resolved
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) recommended for pure python projects"
santacodes marked this conversation as resolved.
Show resolved Hide resolved

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
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
[build-system]
{%- if cookiecutter.backend == "hatch" %}
{%- if backend == "hatch" %}
requires = [
"hatchling",
{%- if cookiecutter.vcs == true %}
{%- if backend == "hatch" and vcs == true %}
"hatch-vcs",
{%- endif %}
]
build-backend = "hatchling.build"
{%- endif %}

[project]
name = "{{ cookiecutter.project_name }}"
name = "{{ project_name }}"
authors = [
{ name = "{{ cookiecutter.full_name }}", email = "{{ cookiecutter.email }}" },
{ name = "{{ full_name }}", email = "{{ email }}" },
]
{%- if cookiecutter.org | lower == "pybamm-team" %}
{%- if org | lower == "pybamm-team" %}
maintainers = [
{ name = "PyBaMM Team", email = "pybamm@pybamm.org" },
santacodes marked this conversation as resolved.
Show resolved Hide resolved
]
{%- endif %}
description = "{{ cookiecutter.project_short_description }}"
description = "{{ project_short_description }}"
readme = "README.md"
requires-python = ">=3.8" # PyBaMM supports 3.8 and above
santacodes marked this conversation as resolved.
Show resolved Hide resolved
classifiers = [
"Development Status :: 1 - Planning",
"Intended Audience :: Science/Research",
"Intended Audience :: Developers",
{%- if cookiecutter.license == "BSD" %}
{%- if license == "BSD-3-Clause" %}
"License :: OSI Approved :: BSD License",
{%- elif cookiecutter.license == "Apache" %}
{%- elif license == "Apache" %}
"License :: OSI Approved :: Apache Software License",
{%- elif cookiecutter.license == "MIT" %}
{%- elif license == "MIT" %}
"License :: OSI Approved :: MIT License",
{%- endif %}
"Operating System :: OS Independent",
Expand All @@ -40,13 +40,13 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11", # PyBaMM supports >=3.8,<3.12
"Programming Language :: Python :: 3.11", # PyBaMM supports >=3.9,<3.13
santacodes marked this conversation as resolved.
Show resolved Hide resolved
"Topic :: Scientific/Engineering",
{%- if cookiecutter.mypy %}
{%- if mypy %}
"Typing :: Typed",
{%- endif %}
]
{%- if cookiecutter.backend == "hatch" %}
{%- if backend == "hatch" %}
dynamic = ["version"]
{%- endif %}
dependencies = ["pybamm",]
Expand Down Expand Up @@ -74,35 +74,38 @@ docs = [
]

[project.urls]
Homepage = "{{ cookiecutter.url }}"
"Bug Tracker" = "{{ cookiecutter.url }}/issues"
Discussions = "{{ cookiecutter.url }}/discussions"
Changelog = "{{ cookiecutter.url }}/releases"
Homepage = "{{ url }}"
"Bug Tracker" = "{{ url }}/issues"
Discussions = "{{ url }}/discussions"
Changelog = "{{ url }}/releases"

[project.entry-points."parameter_sets"]
Chen2020 = "{{ cookiecutter.__project_slug }}.parameters.input.Chen2020:get_parameter_values"
Chen2020 = "{{ project_slug }}.parameters.input.Chen2020:get_parameter_values"

[project.entry-points."models"]
SPM = "{{ cookiecutter.__project_slug }}.models.input.SPM:SPM"
SPM = "{{ project_slug }}.models.input.SPM:SPM"

{# keep this line here for newline #}
{%- if cookiecutter.backend == "hatch" %}
{%- if backend == "hatch" %}
[tool.hatch]
{%- if cookiecutter.vcs == true %}
{%- if backend == "hatch" and vcs == true %}
version.source = "vcs"
build.hooks.vcs.version-file = "src/{{ cookiecutter.__project_slug }}/_version.py"
build.hooks.vcs.version-file = "src/{{ project_slug }}/_version.py"
{%- endif %}
envs.default.dependencies = [
"pybamm",
]
{%- endif %}

{%- if cookiecutter.backend == "hatch" and cookiecutter.vcs == false %}
{%- if backend == "hatch" and vcs == false %}
[tool.hatch.version]
path = "src/{{ cookiecutter.__project_slug }}/__init__.py"
path = "src/{{ project_slug }}/__init__.py"

[tool.hatch.build.targets.wheel]
packages = ["src/{{ project_slug }}"]
{%- endif %}
{# keep this line here for newline #}
{%- if cookiecutter.mypy %}
{%- if mypy %}
[tool.mypy]
python_version = "3.11"
strict = false
Expand All @@ -121,7 +124,7 @@ disable_error_code = ["call-overload", "operator"]
{%- endif %}

[tool.coverage]
run.source = ["{{ cookiecutter.__project_slug }}"]
run.source = ["{{ project_slug }}"]
port.exclude_lines = [
'pragma: no cover',
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"""
Copyright (c) {{ cookiecutter.__year }} {{ cookiecutter.full_name }}. All rights reserved.
Copyright (c) {% now 'utc', '%Y' %} {{ full_name }}. All rights reserved.

{{ cookiecutter.project_name }}: {{ cookiecutter.project_short_description }}
{{ project_name }}: {{ project_short_description }}
"""
{%- if cookiecutter.mypy %}
{%- if mypy %}
from __future__ import annotations
{%- endif %}

{%- if cookiecutter.vcs %}
{%- if vcs %}
from ._version import version as __version__
{%- else %}
__version__ = "0.1.0"
{%- endif %}
import pybamm
from .entry_point import Model, parameter_sets, models
{# keep this line here for newline #}
{%- if cookiecutter.mypy %}
{%- if mypy %}
__all__: list[str] = [
{%- else %}
__all__ = [
Expand Down
Loading
Loading