From 8a2544475f9458e2842ae8faee71ea1be7f3fd4f Mon Sep 17 00:00:00 2001 From: Marvin Vogt Date: Wed, 15 Feb 2023 22:36:16 +0100 Subject: [PATCH] Template python versions --- cookiecutter.json | 25 +++++++++++++++++++- tests/context.yaml | 1 + {{cookiecutter.project_slug}}/pyproject.toml | 10 ++++---- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/cookiecutter.json b/cookiecutter.json index e902ab5..e19ffb3 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -5,5 +5,28 @@ "project_name": "Name of the project (will be shown e.g. as the title in the readme)", "project_slug": "{{ cookiecutter.project_name.lower().replace(' ', '-') }}", "package_name": "{{ cookiecutter.project_slug.replace('-', '_') }}", - "project_short_description": "A short description of the project" + "project_short_description": "A short description of the project", + "python_version": ["3.7+", "3.8+", "3.9+", "3.10+", "3.11+"], + "_python_version_specs": { + "3.7+": { + "versions": ["3.7", "3.8", "3.9", "3.10", "3.11"], + "black_taget_versions": ["py37", "py38", "py39", "py310", "py311"] + }, + "3.8+": { + "versions": ["3.8", "3.9", "3.10", "3.11"], + "black_taget_versions": ["py38", "py39", "py310", "py311"] + }, + "3.9+": { + "versions": ["3.9", "3.10", "3.11"], + "black_taget_versions": ["py39", "py310", "py311"] + }, + "3.10+": { + "versions": ["3.10", "3.11"], + "black_taget_versions": ["py310", "py311"] + }, + "3.11+": { + "versions": ["3.11"], + "black_taget_versions": ["py311"] + } + } } diff --git a/tests/context.yaml b/tests/context.yaml index c7b592a..e04fb50 100644 --- a/tests/context.yaml +++ b/tests/context.yaml @@ -4,3 +4,4 @@ default_context: github_username: "johndoe" project_name: "example-project" project_short_description: "A short description of the project" + python_version: "3.8+" diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 4fb7db8..c12cb14 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -18,9 +18,9 @@ classifiers = [ "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", + {%- for version in cookiecutter._python_version_specs[cookiecutter.python_version]['versions'] %} + "Programming Language :: Python :: {{ version }}", + {%- endfor %} "Topic :: Software Development :: Libraries :: Python Modules", "Typing :: Typed", ] @@ -30,7 +30,7 @@ packages = [ ] [tool.poetry.dependencies] -python = ">=3.7.1, <4.0" +python = ">={{ cookiecutter._python_version_specs[cookiecutter.python_version]['versions'][0] }}, <4.0" [tool.poetry.dev-dependencies] autoflake = "*" @@ -65,7 +65,7 @@ profile = "black" src_paths = ["src", "tests"] [tool.black] -target-version = ["py37", "py38", "py39"] +target-version = {{ cookiecutter._python_version_specs[cookiecutter.python_version]['black_taget_versions'] }} include = '\.pyi?$' [tool.pytest.ini_options]