Skip to content
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

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"Programming Language :: Python :: Implementation :: PyPy",
],
use_incremental=True,
install_requires=["click", "click-default-group", "incremental", "jinja2", "setuptools", "toml"],
install_requires=["click", "click-default-group", "incremental", "jinja2", "setuptools", "toml", "python-dateutil"],
extras_require={"dev": ["packaging"]},
package_dir={"": "src"},
packages=find_packages("src"),
Expand Down
9 changes: 4 additions & 5 deletions src/towncrier/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
from ._git import remove_files, stage_newsfile


def _get_date():
return date.today().isoformat()


@click.command(name="build")
@click.option(
"--draft",
Expand Down Expand Up @@ -135,7 +131,10 @@ def __main(
project_name = ""

if project_date is None:
project_date = _get_date().strip()
project_date = date.today()
else:
from dateutil.parser import parse
project_date = parse(project_date).date()
Copy link
Member

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


if config["title_format"]:
top_line = config["title_format"].format(
Expand Down
1 change: 1 addition & 0 deletions src/towncrier/newsfragments/349.enhancement
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed type of `versiondata.date` in the main template from `string` to `date`. This allows users to customize the date rendering in the template with `strftime`, like so: `{{versiondata.date.strftime("%B")}}`.