Skip to content

Commit 8aa5e4a

Browse files
authored
Adding "better" python version propagation, and removing hardcoded python versions. (#484)
- There are now three defined python versions you can use in templates, they are derived from python_versions and available through jinja macros. - py.pref(), py.max(), and py.min() are the macros, using the preferred import {%- import 'python-versions.jinja' as py -%}. Notably this is the only type of import that copier will accept in files who's pathnames contain templates. which eliminates several more syntactically ergonomic methods of achieving this same interface. - py.pref(python_versions), the preferred version, is the "middle-est" in the python_versions list, see python-versions.jinja for the math. For the default case where python_versions = [3.9,3.10,3,11], 3.10 is the preferred python version. - Hardcoded mentions of python 3.9 and python 3.10 have been set to py.min(python_versions) or py.pref(python_versions) respectively so that this change does not affect projects using the default configuration, and any python upgrade compatibility issues can be deferred until either the project template or an individual project changes python version support. - References to python_versions[0] have been replaced with py.min(python_versions) for consistency.
1 parent 82f1f91 commit 8aa5e4a

15 files changed

+72
-17
lines changed

python-project-template/.github/workflows/pre-commit-ci.yml.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{%- import 'python-versions.jinja' as py %}
12
# This workflow runs pre-commit hooks on pushes and pull requests to main
23
# to enforce coding style. To ensure correct configuration, please refer to:
34
# https://lincc-ppt.readthedocs.io/en/latest/practices/ci_precommit.html
@@ -19,7 +20,7 @@ jobs:
1920
- name: Set up Python
2021
uses: actions/setup-python@v5
2122
with:
22-
python-version: '3.10'
23+
python-version: '{{ py.pref(python_versions) }}'
2324
- name: Install dependencies
2425
run: |
2526
sudo apt-get update

python-project-template/.github/workflows/publish-to-pypi.yml renamed to python-project-template/.github/workflows/publish-to-pypi.yml.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{%- import 'python-versions.jinja' as py %}
12
# This workflow will upload a Python Package using Twine when a release is created
23
# For more information see: https://github.com/pypa/gh-action-pypi-publish#trusted-publishing
34

@@ -26,7 +27,7 @@ jobs:
2627
- name: Set up Python
2728
uses: actions/setup-python@v5
2829
with:
29-
python-version: '3.10'
30+
python-version: '{{ py.pref(python_versions) }}'
3031
- name: Install dependencies
3132
run: |
3233
python -m pip install --upgrade pip

python-project-template/.github/workflows/{% if include_benchmarks %}asv-main.yml{% endif %}.jinja

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ on:
99
branches: [ main ]
1010

1111
env:
12-
PYTHON_VERSION: "3.10"
12+
{%- endraw %}
13+
{%- import 'python-versions.jinja' as py%}
14+
PYTHON_VERSION: "{{ py.pref(python_versions) }}"
15+
{%- raw %}
1316
ASV_VERSION: "0.6.4"
1417
WORKING_DIR: ${{github.workspace}}/benchmarks
1518

python-project-template/.github/workflows/{% if include_benchmarks %}asv-nightly.yml{% endif %}.jinja

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ on:
1010
workflow_dispatch:
1111

1212
env:
13-
PYTHON_VERSION: "3.10"
13+
{%- endraw %}
14+
{%- import 'python-versions.jinja' as py%}
15+
PYTHON_VERSION: "{{ py.pref(python_versions) }}"
16+
{%- raw %}
1417
ASV_VERSION: "0.6.4"
1518
WORKING_DIR: ${{github.workspace}}/benchmarks
1619
NIGHTLY_HASH_FILE: nightly-hash

python-project-template/.github/workflows/{% if include_benchmarks %}asv-pr.yml{% endif %}.jinja

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ concurrency:
1616
cancel-in-progress: true
1717

1818
env:
19-
PYTHON_VERSION: "3.10"
19+
{%- endraw %}
20+
{%- import 'python-versions.jinja' as py%}
21+
PYTHON_VERSION: "{{ py.pref(python_versions) }}"
22+
{%- raw %}
2023
ASV_VERSION: "0.6.4"
2124
WORKING_DIR: ${{github.workspace}}/benchmarks
2225
ARTIFACTS_DIR: ${{github.workspace}}/artifacts

python-project-template/.github/workflows/{% if include_docs %}build-documentation.yml{% endif %}.jinja

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{%- import 'python-versions.jinja' as py %}
12
# This workflow will install Python dependencies, build the package and then build the documentation.
23

34
name: Build documentation
@@ -20,10 +21,10 @@ jobs:
2021

2122
steps:
2223
- uses: actions/checkout@v4
23-
- name: Set up Python 3.10
24+
- name: Set up Python {{ py.pref(python_versions) }}
2425
uses: actions/setup-python@v5
2526
with:
26-
python-version: '3.10'
27+
python-version: '{{ py.pref(python_versions) }}'
2728
- name: Install dependencies
2829
run: |
2930
sudo apt-get update

python-project-template/.pre-commit-config.yaml.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{%- import 'python-versions.jinja' as py %}
12
repos:
23
# Compare the local template version to the latest remote template version
34
# This hook should always pass. It will print a message if the local version
@@ -98,7 +99,7 @@ repos:
9899
# supported by your project here, or alternatively use
99100
# pre-commit's default_language_version, see
100101
# https://pre-commit.com/#top_level-default_language_version
101-
language_version: python3.10
102+
language_version: python{{ py.pref(python_versions) }}
102103
{%- endif %}
103104
{%- if 'ruff_lint' in enforce_style %}
104105
- repo: https://github.com/astral-sh/ruff-pre-commit

python-project-template/README.md.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{%- import 'python-versions.jinja' as py %}
12
# {{project_name}}
23

34
[![Template](https://img.shields.io/badge/Template-LINCC%20Frameworks%20Python%20Project%20Template-brightgreen)](https://lincc-ppt.readthedocs.io/en/latest/)
@@ -29,7 +30,7 @@ environments. If you have conda installed locally, you can run the following to
2930
create and activate a new environment.
3031

3132
```
32-
>> conda create -n <env_name> python=3.10
33+
>> conda create -n <env_name> python={{ py.pref(python_versions) }}
3334
>> conda activate <env_name>
3435
```
3536

python-project-template/pyproject.toml.jinja

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{%- import 'python-versions.jinja' as py %}
12
[project]
23
name = "{{project_name}}"
34
license = {file = "LICENSE"}
@@ -18,7 +19,7 @@ classifiers = [
1819
"Programming Language :: Python",
1920
]
2021
dynamic = ["version"]
21-
requires-python = ">={{ python_versions[0] }}"
22+
requires-python = ">={{ py.min(python_versions) }}"
2223
dependencies = [
2324
]
2425

@@ -66,15 +67,15 @@ testpaths = [
6667

6768
[tool.black]
6869
line-length = 110
69-
target-version = ["py{{ python_versions[0] | replace(".", "") }}"]
70+
target-version = ["py{{ py.min(python_versions) | replace(".", "") }}"]
7071

7172
[tool.isort]
7273
profile = "black"
7374
line_length = 110
7475

7576
[tool.ruff]
7677
line-length = 110
77-
target-version = "py{{ python_versions[0] | replace(".", "") }}"
78+
target-version = "py{{ py.min(python_versions) | replace(".", "") }}"
7879

7980
[tool.ruff.lint]
8081
select = [

python-project-template/src/{% if 'pylint' in enforce_style %}.pylintrc{% endif %} renamed to python-project-template/src/{% if 'pylint' in enforce_style %}.pylintrc{% endif %}.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{%- import 'python-versions.jinja' as py %}
12
[MAIN]
23

34
# Analyse import fallback blocks. This can be used to support both Python 2 and
@@ -87,7 +88,7 @@ persistent=yes
8788

8889
# Minimum Python version to use for version dependent checks. Will default to
8990
# the version used to run pylint.
90-
py-version=3.9
91+
py-version={{ py.min(python_versions) }}
9192

9293
# Discover python modules and packages in the file system subtree.
9394
recursive=no

0 commit comments

Comments
 (0)