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

Allow towncrier to traverse back up directories looking for the configuration file #601

Merged
merged 9 commits into from
May 22, 2024

Conversation

SmileyChris
Copy link
Contributor

Description

Fixes #433

Checklist

  • Make sure changes are covered by existing or new tests.
  • For at least one Python version, make sure local test run is green.
  • Create a file in src/towncrier/newsfragments/. Describe your
    change and include important information. 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.

@SmileyChris SmileyChris requested a review from a team as a code owner May 22, 2024 00:08
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 changes.

They look good.

I left a few minor inline comments.

The major comment is about the missing test for the case in which the config file was not found, even when traversing the whole tree.

I think that we should have such a test before merging this.

Thanks again!

@@ -67,7 +67,7 @@ def load_config_from_options(
) -> tuple[str, Config]:
if config_path is None:
if directory is None:
directory = os.getcwd()
return traverse_for_config(None)
Copy link
Member

Choose a reason for hiding this comment

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

I think that this should be private.

I know that this is from _settings.load , but I think that we should make it explicit that we don't want to expose this as a public API.

Also, there are a lot of branches here,
so I think that it would help to add an explicit comment for this branch.

With the missing docstring for the load_config_from_options it's a bit hard to understand the purpose of this function.

Can we have something like this.

It lools like a bit of duplication between
traverse_for_config and these following lines

base_directory = os.path.abspath(directory)
config = load_config(base_directory)

maybe have something like this

    if config_path is None:
        return _traverse_for_config(directory)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think there's any assumption that non underscored methods become automatically part of a public API is there? If people want to shoot themselves in the foot, let em 🤠

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a docstring and some comments to explain the different branches (I don't like the complexity of the towncrier's loading, but I'm not going to rewrite it just for this addition)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I see what you're getting at with the branching logic now. I've simplified it (and added another test).

src/towncrier/_settings/load.py Show resolved Hide resolved
src/towncrier/test/test_build.py Outdated Show resolved Hide resolved
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.

Thanks for the updates.

All good.

@SmileyChris SmileyChris enabled auto-merge (squash) May 22, 2024 23:04
@adiroiban
Copy link
Member

Thanks for the cleanup for load_config_from_options. Much appreciated.

@SmileyChris SmileyChris merged commit 1c3b87b into twisted:trunk May 22, 2024
16 checks passed
@SmileyChris SmileyChris deleted the traverse-config branch May 24, 2024 02:36
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.

Add support for calling towncrier from sub-directories not only from the repo root.
2 participants