cookiecutter-pylibrary
cookiecutter-pylibrary copied to clipboard
Outdated: won't accept 2020 as year_from.
Error:
$ cookiecutter gh:ionelmc/cookiecutter-pylibrary
....
release_date [today]:
Select year_from:
1 - 2019
2 - 2018
...
Choose from 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 [1]: 2020
Error: invalid choice: 2020. (choose from 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
Select year_from:
1 - 2019
2 - 2018
...
Seems like something that should be calculated, or even allowed to be in the future and free-form.
This is currently defined in cookiecutter.json
We can use jinja2-time to get the current year with {% now 'utc', '%Y' %}
as in year_to
. I'm not sure how to turn that in cookiecutter.json into a list of options [X, X-1, X-2, ...] going back a few years. Failing that, I guess we could do free-form text input with that as the default, like year_to
. Not sure if we'd then need to sanity-check that the input looked like a year.
I just added the year meanwhile a better way is studied.
I'm not absolutely sure whether cookiecutter allows the definition of new/custom filter functions, then it can be simplified.
But a loop might work in combination with range(2021, 2004, -1)
.
So:
[{% for y in range(year, 2004, -1) -%}{%- if loop.index > 1 %},{% endif %}"{{ y }}"{%- endfor %}]
If numbers work, then (json?):
{{ range(2021, 2005, -1) | list }}
Now, just somehow get the year filter included...
Ooof. I think I over-engineered year_from. I changed it to be a simple input like year_to is.