Add new parameter python_versions in copier.yml#35
Conversation
ahms5
left a comment
There was a problem hiding this comment.
really nice feature, thank you. I just have a few comments.
copier.yml
Outdated
| python_versions: | ||
| when: false | ||
| type: yaml | ||
| default: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14'] |
There was a problem hiding this comment.
maybe use " instead of ', be usually use ", even we dont have a strinkt rule. This might make the change in conftest.py obsolete.
tests/conftest.py
Outdated
| "project_getting_started": "This is how to get started.", | ||
| "git_username": "pyfar", | ||
| "minimum_python_version": "3.11", | ||
| "minimum_python_version": "'3.11'", |
There was a problem hiding this comment.
| "minimum_python_version": "'3.11'", | |
| "minimum_python_version": "3.11", |
| {% set min_index = python_versions.index(minimum_python_version) %} | ||
| {{ python_versions[min_index:] }} |
copier.yml
Outdated
| - "3.14" | ||
| choices: > | ||
| {% for v in python_versions %} | ||
| - "'{{ v }}'" |
There was a problem hiding this comment.
| - "'{{ v }}'" | |
| - {{ v }} |
do we really need them?
There was a problem hiding this comment.
Actually, yes. The entire implementation is a bit tricky, and I'm not sure I fully understand it, but here's what I noticed:
After defining default: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"], YAML stores it as python_versions = ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']. As soon as we try to create choices for minimum_python_version from python_versions, each element of the python_versions array is taken separately and treated as a float value. Since it is treated as a float value, the zero in 3.10 is removed and the choice is displayed as 3.1. And even if we put the choices in quotes, they will only be displayed correctly in the questions, but as soon as we select the choice with 3.10, it will be stored as a float, i.e. as 3.1. For this reason, we need to store the values as strings and not as floats...
But I've already noticed that I can just change the parameter type from yaml to str, so we only need a pair of quotation marks (to display the choices correctly).
I noticed that for parameters related to Python versions, we create a new array with Python versions in several places. Later, this will require us to manually add new or remove old Python versions in each of these arrays.
To avoid this, we can add a new parameter that defines all available Python versions once and use it in all other parameters related to Python versions.
Changes proposed in this pull request:
python_versionsto copier.yml, which defines all Python versions valid for the project.minimum_python_versionparameter are now created from the newpython_versionsparameter.valid_python_versionsnow also uses the new parameterpython_versionsto define the array of all available Python versions.conftest.pyfile, since the Python versions are now stored with obligatory apostrophes ' ' as follows:"minimum_python_version": "'3.11'",