Skip to content

Generate PEP 621 authors in the app pyproject.toml - #282

Open
garvitshrma wants to merge 3 commits into
beeware:mainfrom
garvitshrma:pep621-authors
Open

garvitshrma wants to merge 3 commits into
beeware:mainfrom
garvitshrma:pep621-authors

Conversation

@garvitshrma

@garvitshrma garvitshrma commented Nov 17, 2026 •

Copy link
Copy Markdown

The generated pyproject.toml now uses a PEP 621 authors list instead of the deprecated author and author_email settings.
Companion to beeware/briefcase#3131. Refs #1235.
I have now named author as copyright_holder, which completely removes author

PR Checklist:

  • I will abide by the BeeWare Code of Conduct
  • I have read and have followed the CONTRIBUTING.md file
  • This PR was generated or assisted using an AI tool

Assisted-by: Claude Opus 5

@garvitshrma
garvitshrma marked this pull request as draft November 17, 2026 20:07

@freakboy3742 freakboy3742 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of tweaks needed to this template - I suspect it's passing CI because it's running against the mainline briefcase, so it's defaulting to using "author = 'Jane Developer'" in the template context, and that's not showing up because that's the default here as well.

license-files = ["LICENSE"]
author = "{{ cookiecutter.author|escape_toml }}"
author_email = "{{ cookiecutter.author_email }}"
{{ cookiecutter.authors }}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this will work - it will output:

[{"name": "Alice", "email": "alice@example.com"},{"name": "Bob", "email": "bob@example.com"}]

Which (a) isn't pleasant to read, and (b) isn't valid toml.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

authors isn't a list - it's a pre-rendered TOML block passed as a string, built by
authors_toml() in beeware/briefcase#3131 (src/briefcase/commands/new.py) at line 44 to 50. Two authors
produce:

authors = [
    {name = "Alice", email = "alice@example.com"},
    {name = "Bob", email = "bob@example.com"},
]

It has to be a string because cookiecutter 2.7.1 can't carry a list of dicts through its
context - a list is treated as a choice variable, so "authors": [{...}] overridden with a
list raises TypeError: unhashable type: 'dict'.

Comment thread cookiecutter.json Outdated
"description": "An app that does lots of stuff",
"author": "Jane Developer",
"author_email": "jane@example.com",
"copyright_holder": "Jane Developer",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this value coming from? Why not use "name of first author", or "comma separated name of all authors"?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s the default used when the template is rendered without Briefcase. Same role as "Project Awesome" on the line above.
When Briefcase renders the template it passes its own value, which wins over this default. That value comes from copyright_holder() in briefcase/commands/new.py:

return ", ".join(author["name"] for author in authors if author.get("name"))

it's all authors comma separated.

@garvitshrma
garvitshrma marked this pull request as ready for review November 19, 2026 22:23

@freakboy3742 freakboy3742 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I reviewed this without noticing the corresponding Briefcase changes - apologies for the crossed wires.

The approach you've taken is a creative fix; but it's not really the right fix. We shouldn't be passing pre-rendered output into a template - a template should accept data, and then use that data to generate output.

I think the issue that has tripped you up here is that you can't use a "list of dicts" as the value in a Cookiecutter template, and the natural form for authors as a cookiecutter key is a list of dicts. I'm guessing you've hit that limitation, and sought a workaround by pre-rendering the two values that need a list-of-dicts.

However, you can use a dictionary as a cookiecutter value. That's the better fix here - and it also gives us an entry to future PEP 621 work.

If we add a pep621 key to cookiecutter.json, we can accept authors in the "natural" form - and also provide a hook for any future PEP621 keys:

"pep621": {
    "authors": [
        {"name": "Jane Developer", "email": "jane@example.com"}
    ]
},

You can then access cookiecutter.pep621.authors in the template.

Now - rendering the copyright holder and the TOML inline table form of an author might be slightly complicated to do in a Jinja template - but at that point, we can add a cookiecutter filter to help with the rendering process. The escape_toml that you moved in the Briefcase PR is an example of that - it allows you to say {{ value|escape_toml }} in a template, and know that the value will be a valid TOML string. We could add a toml_inline_table and lexical_join filters - the former turning a dictionary into a one line TOML inline table; and lexical join doing the "join all the parts of this list with a comma, except for the last one which is joined with an 'and'".

I hope that explanation makes sense; let me know if you need any more details.

@garvitshrma

Copy link
Copy Markdown
Author

Made changes to accept the data instead of pre rendered output.
PR 3131 is also updated.
cokiecutter.json now carries a pep621 with the authors in their natural form.

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

Successfully merging this pull request may close these issues.

2 participants