-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding "better" python version propagation, and removing hardcoded py…
…thon 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.
- Loading branch information
Showing
15 changed files
with
72 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{# You use this file by including it via jinja like: | ||
{%- import 'python-versions.jinja' as py -%} | ||
Then pass the python_versions list into the various macros like so: | ||
{{ py.min(python_versions) }} | ||
This template creates no output, but does allow you to transform python_versions answer into a | ||
number of helpful values for when you need a single python version. | ||
Note that the import syntax and access MUST BE in the form above. Copier has problems processing import lines | ||
that are any more complex when they occur in files who's paths are also jinja templated. #} | ||
|
||
|
||
{# This gives a middle python version from a potentially long list of versions | ||
For even-length lists we prefer the older of the two middle values. | ||
["3.9","3.10","3.11","3.12"] -> "3.10" | ||
For odd-length lists we prefer the middle value | ||
["3.9","3.10","3.11"] -> "3.10" #} | ||
{% macro pref(python_versions) -%} | ||
{%- set n = python_versions | length -%} | ||
{{ python_versions[((n+1)//2 - 1)] }} | ||
{%- endmacro -%} | ||
|
||
{# These give the minimum and maximum python versions supported #} | ||
{% macro min(python_versions) -%} | ||
{%- set n = python_versions | length -%} | ||
{{ python_versions[0] }} | ||
{%- endmacro -%} | ||
|
||
{% macro max(python_versions) -%} | ||
{%- set n = python_versions | length -%} | ||
{{ python_versions[n-1] }} | ||
{%- endmacro -%} |