Skip to content

Commit

Permalink
Merge pull request #38 from Midnighter/feat-choices
Browse files Browse the repository at this point in the history
Offer more choices on template initialization, make template parts optional
  • Loading branch information
Midnighter authored Oct 23, 2024
2 parents 0900bc0 + d7eab3a commit 8e78417
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 5 deletions.
32 changes: 32 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,18 @@ package_description:
multiline: true
help: "Please provide a short description for the package."

use_vcs_version:
type: bool
default: yes
help: "Do you want to use dynamic versioning of your package or static? Dynamic means that versions use your version control system (VCS), such as git tags, for creating versions."

use_git:
type: bool
default: yes
help: "Do you want to use git with a development platform, like GitHub or GitLab?"

dev_platform:
when: "{{ use_git }}"
type: str
help: "Which development platform are you planning to use? Used to generate certain documentation and hyperlinks."
choices:
Expand All @@ -43,9 +54,30 @@ dev_platform_url:
default: "https://{{ dev_platform|lower }}.com"

username:
when: "{{ use_git }}"
type: str
help: "Your or your organization's username on {{ dev_platform }}. Used to generate certain documentation and hyperlinks."

use_hatch_envs:
type: bool
default: yes
help: "Do you want to use hatch environments for running isolated commands like linting, building docs, or testing?"

use_lint:
type: bool
default: yes
help: "Do you want to lint your code and generally check the formatting of your files?"

use_types:
type: bool
default: yes
help: "Do you want to use typing annotations and type check your code?"

use_test:
type: bool
default: yes
help: "Do you want to test your code? Generally, we strongly recommend that you do, but for a quick demo you may want to avoid this."

license:
type: str
help: "Which license do you want to use? Used in the license file."
Expand Down
8 changes: 5 additions & 3 deletions template/.pre-commit-config.yaml.jinja
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
repos:
{%- if use_lint %}
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
Expand Down Expand Up @@ -28,15 +29,16 @@ repos:
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.1
hooks:
{% if dev_platform == "GitHub" %}
{%- if dev_platform == "GitHub" %}
- id: check-github-workflows
{% elif dev_platform == "GitLab" %}
{%- elif dev_platform == "GitLab" %}
- id: check-gitlab-ci
{% endif %}
{%- endif %}
- id: check-readthedocs
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]
{%- endif %}
34 changes: 32 additions & 2 deletions template/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@

[build-system]
build-backend = "hatchling.build"
requires = ["hatchling", "hatch-vcs"]
requires = ["hatchling"{% if use_vcs_version %}, "hatch-vcs"{% endif %}]

################################################################################
# Project Configuration
################################################################################

[project]
name = "{{ package_name }}"
{% if use_vcs_version %}
dynamic = ["version"]
{% else %}
version = "0.1.0"
{% endif %}
description = "{{ package_description }}"
authors = [
{ name = "{{ author_name }}", email = "{{ author_email }}" },
Expand All @@ -39,18 +43,22 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
{%- if use_types %}
"Typing :: Typed",
{%- endif %}
]
# TODO: add keywords
keywords = []
# TODO: add dependencies
dependencies = []

[project.urls]
{%- if use_git %}
Homepage = "{{ dev_platform_url }}/{{ username }}/{{ project_slug }}"
Documentation = "https://{{ project_slug }}.readthedocs.io"
"Source Code" = "{{ dev_platform_url }}/{{ username }}/{{ project_slug }}"
"Bug Tracker" = "{{ dev_platform_url }}/{{ username }}/{{ project_slug }}/issues"
{%- endif %}
Documentation = "https://{{ project_slug }}.readthedocs.io"
Download = "https://pypi.org/project/{{ project_slug }}/#files"

[project.optional-dependencies]
Expand All @@ -69,12 +77,15 @@ only-packages = true
[tool.hatch.build.targets.wheel]
packages = ["src/{{ package_name }}"]

{%- if use_vcs_version %}
[tool.hatch.build.hooks.vcs]
version-file = "src/{{ package_name }}/_version.py"

[tool.hatch.version]
source = "vcs"
{%- endif %}

{%- if use_test %}
[tool.pytest.ini_options]
testpaths = ["tests"]
markers = ["raises"]
Expand All @@ -88,14 +99,18 @@ source = [
[tool.coverage.run]
branch = true
parallel = true
{%- if use_vcs_version %}
omit = [
"src/{{ package_name }}/_version.py",
]
{%- endif %}

[tool.coverage.report]
exclude_lines = ["pragma: no cover"]
precision = 2
{%- endif %}

{%- if use_lint %}
[tool.ruff]
line-length = 88

Expand All @@ -111,9 +126,11 @@ ignore = [
"ANN101", # 'Missing type annotation for {self} in method'.
"ANN102", # 'Missing type annotation for {cls} in classmethod'.
]
{%- if use_vcs_version %}
exclude = [
"src/{{ package_name }}/_version.py",
]
{%- endif %}

[tool.ruff.lint.extend-per-file-ignores]
"__init__.py" = [
Expand All @@ -138,8 +155,12 @@ style = "google" # TODO: Other styles are possible here, like 'numpy'
arg-type-hints-in-docstring = false
check-return-types = false
check-yield-types = false
{%- if use_vcs_version %}
exclude = "_version.py"
{%- endif %}
{%- endif %}

{%- if use_types %}
# TODO: Adjust mypy configuration.
#[tool.mypy]
#plugins = [
Expand All @@ -157,11 +178,14 @@ exclude = "_version.py"
#init_forbid_extra = true
#init_typed = true
#warn_required_dynamic_aliases = true
{%- endif %}

{%- if use_hatch_envs %}
################################################################################
# Hatch Environments
################################################################################

{%- if use_lint %}
[tool.hatch.envs.style]
description = """Check the style of the codebase."""
dependencies = [
Expand All @@ -175,6 +199,7 @@ docstrings = "pydoclint"
code = "ruff check {args}"
format = "ruff format {args}"
check = ["docstrings", "code"]
{%- endif %}

[tool.hatch.envs.audit]
description = """Check dependencies for security vulnerabilities."""
Expand All @@ -185,6 +210,7 @@ extra-dependencies = [
[tool.hatch.envs.audit.scripts]
check = ["pip-audit"]

{%- if use_types %}
[tool.hatch.envs.types]
description = """Check the static types of the codebase."""
dependencies = [
Expand All @@ -193,6 +219,7 @@ dependencies = [

[tool.hatch.envs.types.scripts]
check = "mypy src/{{ package_name }}"
{%- endif %}

[tool.hatch.envs.docs]
description = """Build or serve the documentation."""
Expand Down Expand Up @@ -221,6 +248,7 @@ check = [
"twine check dist/*",
]

{%- if use_test %}
[tool.hatch.envs.test]
description = """Run the test suite."""
extra-dependencies = [
Expand All @@ -236,3 +264,5 @@ python = ["3.9", "3.12"]

[tool.hatch.envs.test.scripts]
run = "pytest {args:--cov={{ package_name }} --cov-report=term-missing}"
{%- endif %}
{%- endif %}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
workflow_call: {}

jobs:
{%- if use_lint %}
{%- raw %}
lint:
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -20,7 +22,9 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
{%- endraw %}

{%- if use_hatch_envs %}
- name: Install hatch
uses: pypa/hatch@install

Expand All @@ -32,7 +36,10 @@ jobs:

- name: Build documentation
run: hatch run docs:build
{%- endif %}
{%- endif %}

{%- raw %}
test:
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -48,7 +55,9 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
{%- endraw %}

{%- if use_hatch_envs %}
- name: Install hatch
uses: pypa/hatch@install

Expand All @@ -58,12 +67,19 @@ jobs:
- name: Check dependencies
run: hatch run audit:check

{%- if use_types %}
- name: Check types
run: hatch run types:check
{%- endif %}

{%- if use_test %}
{%- raw %}
- name: Test suite
run: hatch run +py=${{ matrix.python-version }} test:run

- name: Report coverage
shell: bash
run: bash <(curl -s https://codecov.io/bash)
{%- endraw %}
{%- endif %}
{%- endif %}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 8e78417

Please sign in to comment.