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

title_format doesn't work in 21.9.0 #386

Closed
Zlopez opened this issue Jun 2, 2022 · 14 comments
Closed

title_format doesn't work in 21.9.0 #386

Zlopez opened this issue Jun 2, 2022 · 14 comments

Comments

@Zlopez
Copy link

Zlopez commented Jun 2, 2022

I have title_format = "{version} ({project_date})" in my pyproject.toml [towncrier] section and in towncrier 21.9.0 this seems to be ignored. The title is missing in both --draft and the generated file.

This worked in the past, but with the latest version it doesn't work anymore.

The whole configuration file can be found here.

@adiroiban
Copy link
Member

adiroiban commented Jun 2, 2022

I see that this functionality was touched as part of #346

and the code is here

if config["title_format"]:

The default template is at https://github.com/twisted/towncrier/blob/master/src/towncrier/templates/default.rst

@adiroiban
Copy link
Member

Ok.

I think that the quick fix is to update your template and add at the start

{% if render_title %}
{% if versiondata.name %}
{{ versiondata.name }} {{ versiondata.version }} ({{ versiondata.date }})
{{ top_underline * ((versiondata.name + versiondata.version + versiondata.date)|length + 4)}}
{% else %}
{{ versiondata.version }} ({{ versiondata.date }})
{{ top_underline * ((versiondata.version + versiondata.date)|length + 3)}}
{% endif %}
{% endif %}
{% for section, _ in sections.items() %}
{% set underline = underlines[0] %}{% if section %}{{section}}
{{ underline * section|length }}{% set underline = underlines[1] %}

{% endif %}

to match the default template.


The current towncrier config is a bit of mess.

I think most configuration values are only valid when using the default template.

@Zlopez
Copy link
Author

Zlopez commented Jun 2, 2022

I tried to add the lines to the _template.rst and still nothing.

Output of towncrier --draft

Loading template...
Finding news fragments...
Rendering news fragments...
Draft only -- nothing has been written.
What is seen below is what would be written.



Bug Fixes
---------

* Failure when converting the redis value to integer
  (`PR#475 <https://github.com/fedora-infra/the-new-hotness/pull/475>`_)

The correct output should be

Loading template...
Finding news fragments...
Rendering news fragments...
Draft only -- nothing has been written.
What is seen below is what would be written.


1.2.0 (2022-06-02)
==================

Bug Fixes
---------

* Failure when converting the redis value to integer
  (`PR#475 <https://github.com/fedora-infra/the-new-hotness/pull/475>`_)

@Zlopez
Copy link
Author

Zlopez commented Jun 2, 2022

I even tried to use the https://github.com/twisted/towncrier/blob/master/src/towncrier/templates/default.rst without any change and the output of towncrier --draft is still without title.

Loading template...
Finding news fragments...
Rendering news fragments...
Draft only -- nothing has been written.
What is seen below is what would be written.

  
  Bug Fixes ---------

  - Failure when converting the redis value to integer (PR475)

@adiroiban
Copy link
Member

Hm... I don't know what is going on there.

I did a trial run on the releaese code and I can see that the title is included.

$ git top
523f6ef Adi Roiban 2022-02-10 disable release check for the actual release.
$ git statjus
A  src/towncrier/newsfragments/337.removal.rst
$ towncrier build --draft
Loading template...
Finding news fragments...
Rendering news fragments...
Draft only -- nothing has been written.
What is seen below is what would be written.

towncrier 21.9.0 (2022-06-02)
=============================

Deprecations and Removals
-------------------------

- Some test (`#337 <https://github.com/hawkowl/towncrier/issues/337>`_)


I don't know what is going on there.

You can try to force your luck using

{{ versiondata.version }} ({{ versiondata.date }})
{{ top_underline * ((versiondata.version + versiondata.date)|length + 3)}}
{% for section, _ in sections.items() %}
{% set underline = underlines[0] %}{% if section %}{{section}}
{{ underline * section|length }}{% set underline = underlines[1] %}

@Zlopez
Copy link
Author

Zlopez commented Jun 2, 2022

Hm, it seems that the issue must be somewhere in my configuration than. I will try to look at it more closely later.

@Zlopez
Copy link
Author

Zlopez commented Jun 2, 2022

The behavior of the towncrier is inconsistent in this case. I used the default template again and now it worked. So I tried to add the macro I have in my own and it stopped working, so I removed the macro again and now the title doesn't work anymore, even if I'm in the same state that worked before.

Does towncrier has any cache or something, that could cause this?

EDIT: When commenting out all the templates in configuration it started working again :-D

@Zlopez
Copy link
Author

Zlopez commented Jun 2, 2022

After some playing I figured out that the issue is actually in https://github.com/twisted/towncrier/blob/523f6ef428885ed80c2ba377fe5b5ad043818766/src/towncrier/_builder.py#L291= the top_line is provided, but the render is ignoring it sometimes.

I have Jinja2 3.1.2 in my virtual env.

@Zlopez
Copy link
Author

Zlopez commented Jun 2, 2022

It seems that the current master has plenty of changes till then. Let me check the default from the release.

@Zlopez
Copy link
Author

Zlopez commented Jun 2, 2022

When I copied over this part of default template from the 21.9.0

{% if top_line %}
{{ top_line }}
{{ top_underline * ((top_line)|length)}}
{% elif versiondata.name %}
{{ versiondata.name }} {{ versiondata.version }} ({{ versiondata.date }})
{{ top_underline * ((versiondata.name + versiondata.version + versiondata.date)|length + 4)}}
{% else %}
{{ versiondata.version }} ({{ versiondata.date }})
{{ top_underline * ((versiondata.version + versiondata.date)|length + 3)}}
{% endif %}

to my template it started working like a charm :-)

It looks that the only thing I was missing was the top_line in my template. I assume this will no longer work with next release, because the top_line is no longer in the current master.

@adiroiban
Copy link
Member

adiroiban commented Jun 2, 2022

Yes. The top_line is no longer part of the public API.

There is missing documentation for towncrier template design API and no commitment from towncrier devs to keep backward compatibility.

res = jinja_template.render(
render_title=render_title,
sections=data,
definitions=definitions,
underlines=underlines,
versiondata=versiondata,
top_underline=top_underline,
get_indent=get_indent, # simplify indentation in the jinja template.
)


The main issue is that towncrier lacks some dev love ... so there is no much we can do now.

It is too late to fix the change now.

@adiroiban
Copy link
Member

I think that this can be closed.

Somehow a fix would be to write documentation for what is public API available inside the templates.

@timwsuqld
Copy link

We are having this issue too. The fix that @Zlopez had of adding things to the template, will that continue working, or is there another workaround we'll need in the next release?

@adiroiban
Copy link
Member

Hi,

The available variables are documented here https://towncrier.readthedocs.io/en/latest/configuration.html

@timwsuqld what is the content of your template, what is the expected result, and what is the actual result?

More details about the issue would help :)

top_line template variable is no longer supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants