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

fix: make compatible with towncrier>=24.7 #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bennyrowland
Copy link

@webknjaz this is a first pass at solving this problem, feel free to suggest alternative approaches to tackling the issue. Ultimately it is very simple to solve for only new Towncrier, but maintaining backwards compatibility is more difficult. In the end I opted to basically have side by side implementations of the key lookup_towncrier_fragments() function. This means that there is a little bit more duplicated code between the two versions than there needs to be, but it also means that when/if support for pre 24.7 Towncrier is dropped it will be easy to just delete the older function. I can change this if you prefer a single function.

I also renamed get_towncrier_config() to get_towncrier_config_as_dict() to make way for a new version of get_towncrier_config() returning the new dataclass Config object. This breaks backwards compatibility and I could have implemented a new get_towncrier_config_as_dataclass() function instead, but given the very small chance that any other dependent code is using that function I thought it was nicer to keep the main function name providing the current API. Again, happy to change if you prefer the other way.

These changes solve #92 on my system (Windows, Py3.12) but there are no existing tests of this functionality and I haven't yet added any. If you approve of the general implementation of the fix then I can add some tests to go along with it (any suggestions about how you would like those to look would also be welcome).

original commit msg below:
towncrier 24.7 changed the way that its find_fragments() function works to accept a Config dataclass instead of specific components of the config. This commit adds a new version of lookup_towncrier_fragments() to use the new API and chooses which one to use based on the version of towncrier obtained from importlib.metadata. It also slightly changes the way that towncrier config can be obtained: the previous get_towncrier_config() function (which returned a dict) is now renamed as get_towncrier_config_as_dict() and get_towncrier_config() returns the new Config dataclass object for towncrier versions above 22.12.0rc1 and raises NotImplementedError for older versions. This API change should be ok as get_towncrier_config() was only called in one place before.

@bennyrowland
Copy link
Author

I also realised too late that I hadn't installed the pre-commit hooks before making my last commit, so have added a few more style fixes that hopefully mean some more of the linting checks will also pass. I have some issues getting everything to pass on my local (Windows) system which seem to be related to unicode encoding problems (I have also had to rename the tox package_env variable to remove the non-ascii characters to get tox to run properly).

My time to work on this is a bit sporadic, but I do still want to get it sorted out, so please just let me know what you would like done to make this mergeable and I will get it done sooner or later :-)

.pre-commit-config.yaml Outdated Show resolved Hide resolved
setup.cfg Outdated Show resolved Hide resolved
@webknjaz
Copy link
Member

webknjaz commented Dec 3, 2024

I also realised too late that I hadn't installed the pre-commit hooks before making my last commit, so have added a few more style fixes that hopefully mean some more of the linting checks will also pass.

Yeah, it's fine to rely on pre-commit.ci for this too.

I have some issues getting everything to pass on my local (Windows) system which seem to be related to unicode encoding problems (I have also had to rename the tox package_env variable to remove the non-ascii characters to get tox to run properly).

I suppose you're talking about these hacks 2189e24 / b84a3fa, eh?

My time to work on this is a bit sporadic, but I do still want to get it sorted out, so please just let me know what you would like done to make this mergeable and I will get it done sooner or later :-)

Thanks for the research and the time you've spent thus far! I've left a few comments (including the PR split). And on top of that, I imagine that the GHA matrix will need updating.

GHA didn't start. Apparently, the workflow got auto-disabled because it has a cron trigger, and they do that periodically. I'm planning to refactor that eventually. I'll close+reopen this PR to trigger the CI run.

I may also find time to do something myself. If that'll be the case, I'll make sure to drop a note here with the updates. Thanks again!

@webknjaz webknjaz closed this Dec 3, 2024
@webknjaz webknjaz reopened this Dec 3, 2024
@webknjaz
Copy link
Member

webknjaz commented Dec 3, 2024

Additionally, the RTD config is outdated. This is something to address separately. Here's my preferred variant: https://github.com/ansible/awx-plugins/blob/ec1523d/.readthedocs.yaml. It needs to be copied with minimum (ideally zero) changes if somebody gets to it before me.

@webknjaz webknjaz added bug Something isn't working enhancement New feature or request labels Dec 3, 2024
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 64.80%. Comparing base (7f57120) to head (d60f568).

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #96      +/-   ##
==========================================
- Coverage   65.93%   64.80%   -1.14%     
==========================================
  Files          12       12              
  Lines         229      233       +4     
  Branches       10       10              
==========================================
  Hits          151      151              
- Misses         77       81       +4     
  Partials        1        1              



# used for towncrier version 24.7 and above
def _lookup_towncrier_fragments_post24_7( # noqa: WPS210
Copy link
Member

Choose a reason for hiding this comment

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

(this needs to be communicated somehow)

Suggested change
def _lookup_towncrier_fragments_post24_7( # noqa: WPS210
def _lookup_towncrier_fragments_post24_7_inclusive( # noqa: WPS210

@webknjaz
Copy link
Member

webknjaz commented Dec 3, 2024

Oh, and it'd be nice to have some tests added if possible.

@webknjaz webknjaz force-pushed the 92_towncrier24_7_compat branch 4 times, most recently from 0c1de45 to 2996d03 Compare December 22, 2024 14:12
@webknjaz webknjaz self-assigned this Dec 22, 2024
@webknjaz
Copy link
Member

I dropped a huge portion of support matrix from the CI, metadata and code. And rebased this, making the patch smaller.

I see some duplication in the fragment lookup split, so I'd like to see how to reduce the divergence. And I also want to attempt dropping the use of packaging in favor of feature checks if possible. Finally, I want to look into adding some more test coverage.

@webknjaz webknjaz force-pushed the 92_towncrier24_7_compat branch from 2996d03 to 5193d7e Compare December 23, 2024 06:05
)
return set()

fragment_dir = towncrier_config.directory or 'newsfragments'
Copy link
Member

Choose a reason for hiding this comment

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

It occurred to me that this is probably going to yield weird behavior with an empty string in the directory attribute.

@webknjaz webknjaz force-pushed the 92_towncrier24_7_compat branch 2 times, most recently from 2e8f17f to aef5188 Compare December 23, 2024 13:43
@webknjaz
Copy link
Member

@bennyrowland I've reshuffled stuff, dropped the packaging dep and incorporated my change from #94, combining it with your commit.

I'll still need to fix up a few CI things and look into testing before merging.

Towncrier 24.7 changed the way that its `find_fragments()` function
works to accept a `Config` dataclass instead of specific components of
the config.

Co-Authored-By: Ben Rowland <ben.rowland@hallmarq.net>

Closes sphinx-contrib#94
Resolves sphinx-contrib#92
@webknjaz webknjaz force-pushed the 92_towncrier24_7_compat branch from 53c29c8 to d60f568 Compare December 27, 2024 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants