Skip to content

Commit

Permalink
more cookicutter option added
Browse files Browse the repository at this point in the history
  • Loading branch information
ilkersigirci committed Jan 26, 2025
1 parent 43469b6 commit 957adac
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ create-example-project: ## Create and test a new project with the cookiecutter t
github_author_handle=ilkersigirci \
project_name=python-template-example \
project_slug=python_template_example \
python_version=3.12 \
git_remote_location=github \
devcontainer=n \
docs=n \
mypy=n \
open_source_license="MIT license"
9 changes: 9 additions & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"project_name": "python-template",
"project_slug": "{{cookiecutter.project_name|lower|replace('-', '_')}}",
"project_description": "This is a template repository for Python projects",
"python_version": "3.11",
"git_remote_location": [
"github",
"gitlab"
Expand All @@ -13,6 +14,14 @@
"y",
"n"
],
"docs": [
"y",
"n"
],
"mypy": [
"y",
"n"
],
"open_source_license": [
"MIT license",
"BSD license",
Expand Down
7 changes: 7 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ def remove_dir(filepath: str) -> None:

if "{{cookiecutter.devcontainer}}" != "y":
remove_dir(".devcontainer")

if "{{cookiecutter.docs}}" != "y":
remove_dir("docs")
remove_file("mkdocs.yml")

if "{{cookiecutter.git_remote_location}}" == "github":
remove_file(".github/workflows/doc.yml")
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repos:
# args: [requirements.in, -o, requirements.txt]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.9.2
hooks:
# Run the Ruff linter.
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name}}/.python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.11.7
{{cookiecutter.python_version}}
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name}}/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"ruff.nativeServer": "on",
"autoDocstring.generateDocstringOnEnter": true,
"autoDocstring.docstringFormat": "google",
"autoDocstring.customTemplatePath": "docs/templates/google-notypes.mustache",
"autoDocstring.customTemplatePath": "templates/google-notypes.mustache",
"autoDocstring.includeExtendedSummary": false,
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
Expand Down
24 changes: 15 additions & 9 deletions {{cookiecutter.project_name}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ DOCKER_IMAGE={{cookiecutter.project_name}}
DOCKER_TARGET=development


.PHONY: help install test clean build publish doc pre-commit format lint profile
.PHONY: help install test clean build publish pre-commit format lint profile
.DEFAULT_GOAL=help

help:
Expand Down Expand Up @@ -56,10 +56,7 @@ install-precommit: ## Install pre-commit hooks
uv run pre-commit install

install-lint:
uv pip install ruff==0.8.0

install-doc: ## Install mkdocs, mkdocs-material and mkdocstrings
uv pip install mkdocs mkdocs-material mkdocstrings[python]
uv pip install ruff==0.9.2

update-dependencies: ## Updates the lockfiles and installs dependencies. Dependencies are updated if necessary
uv sync
Expand Down Expand Up @@ -91,10 +88,6 @@ test-coverage-parallel:
uv lock --locked
uv run --module pytest -n auto --cov=${PACKAGE} --cov-report=html:coverage

test-docs: ## Test documentation examples with doctest
uv lock --locked
uv run --module pytest --doctest-modules ${PACKAGE}

test: clean-test test-all ## Cleans and runs all tests
test-parallel: clean-test test-all-parallel ## Cleans and runs all tests with parallelization

Expand Down Expand Up @@ -133,6 +126,11 @@ publish: ## Builds the project and publish the package to Pypi
uv publish dist/*
# uv publish --publish-url https://test.pypi.org/legacy/ --username DUMMY --password DUMMY dist/*

{% if cookiecutter.docs == 'y' -%}
## Documentation related commands
install-doc: ## Install mkdocs, mkdocs-material and mkdocstrings
uv pip install mkdocs mkdocs-material mkdocstrings[python]

doc: ## Build documentation with mkdocs
uv run mkdocs build

Expand All @@ -142,6 +140,11 @@ doc-github: ## Build documentation with mkdocs and deploy to github pages
doc-dev: ## Show documentation preview with mkdocs
uv run mkdocs serve -w ${PACKAGE}

test-docs: ## Test documentation examples with doctest
uv lock --locked
uv run --module pytest --doctest-modules ${PACKAGE}
{%- endif %}

pre-commit-one: ## Run pre-commit with specific files
uv lock --locked
uv run pre-commit run --files ${PRECOMMIT_FILE_PATHS}
Expand All @@ -168,6 +171,8 @@ format: ## Run ruff for all package files. CHANGES CODE
uv run --module ruff format ${PACKAGE}
uv run --module ruff check ${PACKAGE} --fix --show-fixes

{% if cookiecutter.mypy == 'y' -%}
## Type checking related commands
typecheck: ## Checks code with mypy
uv lock --locked
uv run --module mypy --package ${PACKAGE}
Expand All @@ -180,6 +185,7 @@ typecheck-no-cache: ## Checks code with mypy no cache
typecheck-report: ## Checks code with mypy and generates html report
uv lock --locked
uv run --module mypy --package ${PACKAGE} --html-report mypy_report
{%- endif %}

# profile: ## Profile the file with scalene and shows the report in the terminal
# uv lock --locked
Expand Down
24 changes: 18 additions & 6 deletions {{cookiecutter.project_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "{{cookiecutter.project_slug}}"
version = "0.0.1"
description = "{{cookiecutter.project_description}}"
readme = "README.md"
requires-python = ">=3.11,<3.13"
requires-python = ">={{cookiecutter.python_version}}"

authors = [
{name = "{{cookiecutter.author}}", email = "{{cookiecutter.email}}"},
Expand Down Expand Up @@ -36,18 +36,22 @@ dependencies = []
[dependency-groups]
dev = [
"ipykernel>=6.29.5",
"mypy>=1.13.0",
"pre-commit>=4.0.1",
"ruff>=0.8.6",
"ruff>=0.9.2",
# "scalene~=1.5.21.2",
{% if cookiecutter.mypy == 'y' -%}
"mypy>=1.13.0",
{% endif %}
]
{% if cookiecutter.docs == 'y' -%}
doc = [
"mkdocs>=1.6.1",
"mkdocs-material>=9.5.42",
"mkdocstrings[python]>=0.26.2",
# "mdx-include",
# "mkdocs-markdownextradata-plugin",
]
{% endif %}
test = [
"pytest-cov>=5.0.0",
"pytest-rerunfailures>=14.0",
Expand All @@ -57,8 +61,11 @@ test = [
]

[tool.uv]
{% if cookiecutter.docs == 'y' -%}
default-groups = ["dev", "doc", "test"]

{% else -%}
default-groups = ["dev", "test"]
{% endif %}

[tool.pytest.ini_options]
minversion = "7.0.0"
Expand Down Expand Up @@ -120,7 +127,9 @@ select = [
"B", # flake8-bugbear
"C", # flake8-comprehensions
"C9", # mccabe
{% if cookiecutter.docs == 'y' -%}
"D", # flake8-docstrings
{% endif %}
"E", # pycodestyle errors (default)
"F", # pyflakes (default)
"I", # isort
Expand Down Expand Up @@ -152,8 +161,10 @@ unfixable = [
# [tool.ruff.lint.flake8-import-conventions.extend-aliases]
# some_alias = ""

{% if cookiecutter.docs == 'y' -%}
[tool.ruff.lint.pydocstyle]
convention = "google"
{% endif %}

[tool.ruff.lint.mccabe]
max-complexity = 10
Expand All @@ -164,7 +175,7 @@ combine-as-imports = true
# known-first-party = ["SomeLibrary"]
# known-third-party = ["SomeLibrary"]

# mypy section
{% if cookiecutter.mypy == 'y' -%}
# Read more here: https://mypy.readthedocs.io/en/stable/config_file.html#using-a-pyproject-toml-file
[tool.mypy]
# python_version = "3.8"
Expand All @@ -179,6 +190,7 @@ show_error_codes = true
module = "tests.*"
ignore_missing_imports = true
check_untyped_defs = true
{% endif %}

[tool.coverage.run]
source = ['src/{{cookiecutter.project_slug}}']
Expand All @@ -201,7 +213,7 @@ exclude_lines = [
# ]

# [build-system]
# requires = ["uv>=0.5.0,<1.0.0"]
# requires = ["uv>=0.5.24,<1.0.0"]
# build-backend = "uv._build_backend" # FIXME: Only builds source distribution, not wheel

[build-system]
Expand Down

0 comments on commit 957adac

Please sign in to comment.