-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial work to use date type objects for the date and not strings #350
base: trunk
Are you sure you want to change the base?
Changes from all commits
a4e1d85
ebc97c6
27b42dd
39fc371
84070c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1 @@ | ||||||||||
The `versiondata.date` is not `date` instance. This allows users to customize the date rendering in the template with `strftime`, like so: `{{versiondata.date.strftime("%B")}}`. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ | |
{{ top_underline * ((top_line)|length)}} | ||
{% elif versiondata.name %} | ||
{{ versiondata.name }} {{ versiondata.version }} ({{ versiondata.date }}) | ||
{{ top_underline * ((versiondata.name + versiondata.version + versiondata.date)|length + 4)}} | ||
{{ top_underline * ((versiondata.name + versiondata.version)|length + 4)}}{{ top_underline * (versiondata.date|title|length)}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need these changes to the default template? I was thinking that the scope and purpose of the PR is to just change the internal of the date object. |
||
{% else %} | ||
{{ versiondata.version }} ({{ versiondata.date }}) | ||
{{ top_underline * ((versiondata.version + versiondata.date)|length + 3)}} | ||
{{ top_underline * (versiondata.version|length + 3)}}{{ top_underline * (versiondata.date|title|length)}} | ||
{% endif %} | ||
{% for section, _ in sections.items() %} | ||
{% set underline = underlines[0] %}{% if section %}{{section}} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{% if top_line %} | ||
{{ top_line }} | ||
{{ top_underline * ((top_line)|length)}} | ||
{% elif versiondata.name %} | ||
{{ versiondata.name }} {{ versiondata.version }} ({{ versiondata.date }} / {{ versiondata.date|date:"D d M Y" }}) | ||
{{ top_underline * ((versiondata.name + versiondata.version)|length + 4)}}{{ top_underline * (versiondata.date|title|length)}} | ||
{% else %} | ||
{{ versiondata.version }} ({{ versiondata.date }} # {{ versiondata.date|date:"D d M Y" }}) | ||
{{ top_underline * (versiondata.version|length + 3)}}{{ top_underline * (versiondata.date|title|length)}} | ||
{% endif %} | ||
{% for section, _ in sections.items() %} | ||
{% set underline = underlines[0] %}{% if section %}{{section}} | ||
{{ underline * section|length }}{% set underline = underlines[1] %} | ||
|
||
{% endif %} | ||
|
||
{% if sections[section] %} | ||
{% for category, val in definitions.items() if category in sections[section]%} | ||
{{ definitions[category]['name'] }} | ||
{{ underline * definitions[category]['name']|length }} | ||
|
||
{% if definitions[category]['showcontent'] %} | ||
{% for text, values in sections[section][category].items() %} | ||
- {{ text }} ({{ values|join(', ') }}) | ||
{% endfor %} | ||
|
||
{% else %} | ||
- {{ sections[section][category]['']|join(', ') }} | ||
|
||
{% endif %} | ||
{% if sections[section][category]|length == 0 %} | ||
No significant changes. | ||
|
||
{% else %} | ||
{% endif %} | ||
|
||
{% endfor %} | ||
{% else %} | ||
No significant changes. | ||
|
||
|
||
{% endif %} | ||
{% endfor %} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -271,3 +271,47 @@ def test_multiple_file_no_start_string(self): | |||||
""") | ||||||
|
||||||
self.assertEqual(expected_output, output) | ||||||
|
||||||
|
||||||
def test_dateformat(self): | ||||||
""" | ||||||
Testing support of dateformat filter during template rendering. | ||||||
""" | ||||||
tempdir = self.mktemp() | ||||||
os.mkdir(tempdir) | ||||||
|
||||||
definitions = {} | ||||||
fragments = split_fragments(fragments={}, definitions=definitions) | ||||||
|
||||||
template = pkg_resources.resource_string( | ||||||
"towncrier", "test/templates/date.rst" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this file should hint the actual test in which it is used.
Suggested change
but I hope that we can have a very simple and minimal template something like
And check the expected output. src/towncrier/test/templates/date.rst has some many side-effects and things that are not related to version datetime functionaliyt that is hard to see what is the target of the test. |
||||||
).decode("utf8") | ||||||
|
||||||
content = render_fragments( | ||||||
template=template, | ||||||
issue_format=None, | ||||||
top_line="", | ||||||
fragments=fragments, | ||||||
definitions=definitions, | ||||||
underlines=["-", "~"], | ||||||
wrap=True, | ||||||
versiondata={"name": "MyProject", "version": "1.0", "date": "13.3.2022"}, | ||||||
) | ||||||
|
||||||
append_to_newsfile( | ||||||
directory=tempdir, | ||||||
filename="NEWS.rst", | ||||||
start_string=None, | ||||||
top_line="", | ||||||
content=content, | ||||||
) | ||||||
|
||||||
with open(os.path.join(tempdir, "NEWS.rst"), "r") as f: | ||||||
output = f.read() | ||||||
|
||||||
expected_output = dedent("""\ | ||||||
MyProject 1.0 (1.1.2001 / Sun 13 Mar 2022) | ||||||
========================================== | ||||||
""") | ||||||
|
||||||
self.assertEqual(expected_output, output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a minor comment
Can we just support ISO date format and then use stdlib
datetime.strptime
to parse the date ?Not a big deal... just a shame that we dont't have "smart" parse function in stdlib.
At the same time, I think that we should encourage standard date representation, and only support ISO format.
... and it this way, we don't need to add yet another dependency