Skip to content

Commit bf1a659

Browse files
authored
Merge pull request #38 from smkent/pymax
Add optional maximum Python version question
2 parents 7c44984 + f9cedfc commit bf1a659

5 files changed

Lines changed: 1309 additions & 3 deletions

File tree

copier.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ python_version_minimum:
9999
- '3.13'
100100
- '3.14'
101101

102+
python_version_maximum:
103+
type: str
104+
qmark: 🐍
105+
help: Maximum Python version
106+
default: No maximum
107+
choices: |
108+
- 'No maximum'
109+
{%- set min_minor = python_version_minimum.split(".")[1] | int -%}
110+
{%- for minor in range(min_minor, 15) %}
111+
- '3.{{ minor }}'
112+
{%- endfor %}
113+
102114
enable_coverage:
103115
type: bool
104116
qmark: 📊

includes/python.jinja

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
{%- set all_versions = ["3.10", "3.11", "3.12", "3.13", "3.14"] -%}
22
{%- set min_minor = python_version_minimum.split(".")[1] | int -%}
3+
{%- set max_minor = (
4+
python_version_maximum.split(".")[1] | int
5+
if python_version_maximum != 'No maximum' else
6+
(all_versions|last).split(".")[1] | int
7+
) -%}
38
{%- macro for_each_version() -%}
4-
{%- for v in all_versions if v.split(".")[1] | int >= min_minor -%}
9+
{%- for v in all_versions if (
10+
v.split(".")[1] | int >= min_minor and v.split(".")[1] | int <= max_minor
11+
) -%}
512
{{ caller(loop, v) }}
613
{%- endfor -%}
714
{%- endmacro -%}
815

916
{%- macro latest() -%}
10-
{{- all_versions|last -}}
17+
{%- for v in all_versions if v.split(".")[1] | int <= max_minor -%}
18+
{{ v if loop.last }}
19+
{%- endfor -%}
20+
{%- endmacro -%}
21+
22+
{%- macro requires_python() -%}
23+
>={{ python_version_minimum }}
24+
{%- if python_version_maximum != 'No maximum' -%}
25+
,<3.{{ max_minor + 1 }}
26+
{%- endif %}
1127
{%- endmacro -%}

template/pyproject.toml.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description = "{{ project_description }}"
1010
readme = "README.md"
1111
license = "{{ copyright_license }}"
1212
license-files = ["LICENSE"]
13-
requires-python = ">={{ python_version_minimum }}"
13+
requires-python = "{{ py.requires_python() }}"
1414
authors = [
1515
{ name = "{{ user_name }}", email = "{{ user_email }}" },
1616
]

0 commit comments

Comments
 (0)