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

Allowed fallback usage of project.name for name and package if pyproject.toml exists #687

Merged
merged 6 commits into from
Feb 25, 2025

Conversation

zerothi
Copy link
Contributor

@zerothi zerothi commented Feb 20, 2025

Description

Fixes #685

Checklist

  • Make sure changes are covered by existing or new tests.
  • For at least one Python version, make sure test pass on your local environment.
  • Create a file in src/towncrier/newsfragments/. Briefly describe your
    changes, with information useful to end users. Your change will be included in the public release notes.
  • Make sure all GitHub Actions checks are green (they are automatically checking all of the above).
  • Ensure docs/tutorial.rst is still up-to-date.
  • If you add new CLI arguments (or change the meaning of existing ones), make sure docs/cli.rst reflects those changes.
  • If you add new configuration options (or change the meaning of existing ones), make sure docs/configuration.rst reflects those changes.

This fallback will only work if the pyproject.toml file
is present.
However, it will work for any combination of pyproject.toml
or towncrier.toml configuration files.

Note, that project.name is a required field in pyproject.toml
files. Hence, the minimal requirement for using towncrier
in python project is a no-op!

Signed-off-by: Nick Papior <nickpapior@gmail.com>
Signed-off-by: Nick Papior <nickpapior@gmail.com>
@zerothi zerothi requested a review from a team as a code owner February 20, 2025 08:59
Signed-off-by: Nick Papior <nickpapior@gmail.com>
Due to the lifting of minimal configuration in python projects
the entry is not required any more.

Signed-off-by: Nick Papior <nickpapior@gmail.com>
@zerothi
Copy link
Contributor Author

zerothi commented Feb 20, 2025

So this drastically changes the requirement of having a tool.towncrier section, however, I think this is ok given the circumstances. If you want to use towncrier, then you'll likely put something anyway, in particular if you are not using a python project.

So unless that is a big objection, I think this is a more or less complete PR that catches undefined name|package. Do you want a test for the last thing not covered?

@zerothi
Copy link
Contributor Author

zerothi commented Feb 20, 2025

One thing, you said I should use the metadata, but I am inclined not to. That would only work for Python projects, and so the path would be something like:

project_name = pyproject_config["project"]["name"]
project_name = importlib.metadata.metadata(project_name)["Name"]

is this more in line with what you want?

Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

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

Many thanks for the PR.

I am quite busy these days and I don't have much time for side-projects.

I tried to do a quick review.


Can you update the PR title to provide a summary of what is done here?

Do you want a test for the last thing not covered?

If this is a functionality that is documented, then we need automated tests.

If the functionality is not documented and has no tests, then this is an "accidental" feature and it might break any time in the future.


One thing, you said I should use the metadata, but I am inclined not to. That would only work for Python projects, and so the path would be something like:

I am ok with the current implementation.
No need to extract the package name from importlib.metadata


As long as we don't break backward compatility, anyting should be ok

Do have a test that proves that if we have

[project]
name = "Dull Pants"
[tool.towncrier]
name = "Fancy Pants"
package = fancy_pants

the config will prefer the value from [tool.towncrier] ?

Thanks again

@@ -112,22 +112,6 @@ def test_template_extended(self):

self.assertEqual(config.template, ("towncrier.templates", "default.rst"))

def test_missing(self):
Copy link
Member

Choose a reason for hiding this comment

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

why was this test removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because now towncrier does not need any tool.towncrier section for Python projects using pyproject.toml files.

A pyproject.toml file requires the name field, and hence everything can be used without problems.

The removed test checked that it broke when tool.towncrier was not present, simply because it is not required.

@@ -194,6 +178,42 @@ def test_towncrier_toml_preferred(self):
config = load_config(project_dir)
self.assertEqual(config.package, "a")

def test_pyproject_name_fallback_both(self):
"""
Towncrier will fallback to the [project.name] value in pyproject.toml.
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 small suggestion to help understand the scope of this test.

Suggested change
Towncrier will fallback to the [project.name] value in pyproject.toml.
To obtain the name of the project, when there is no dedicated [tool.towncrier] section in pyproject.toml, it will fallback to the `name` option from the [project] section.

Just asking. Is towncrier usable without a configuration section ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. When it is a Python project with a pyproject.toml file, then a configuration file / setting is not required.

@zerothi zerothi changed the title 685 name Allowed fallback usage of project.name for name and package if pyproject.toml exists Feb 22, 2025
Signed-off-by: Nick Papior <nickpapior@gmail.com>
Signed-off-by: Nick Papior <nickpapior@gmail.com>
@zerothi
Copy link
Contributor Author

zerothi commented Feb 24, 2025

As long as we don't break backward compatility, anyting should be ok

Do have a test that proves that if we have

done!

I think everything is done, let me know if there is something that needs clarification.

Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

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

Looks good. Great work! Thanks again for the PR.

@adiroiban adiroiban merged commit cd14c9c into twisted:trunk Feb 25, 2025
16 checks passed
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.

Default name should refer to pyproject.toml.project.name
2 participants