Skip to content

Implement Mercurial support#699

Merged
adiroiban merged 11 commits intotwisted:trunkfrom
cdevienne:alternate-vcs
Apr 16, 2025
Merged

Implement Mercurial support#699
adiroiban merged 11 commits intotwisted:trunkfrom
cdevienne:alternate-vcs

Conversation

@cdevienne
Copy link
Copy Markdown
Contributor

Description

Fixes #394

Add support for mercurial repositories.

The _vcs module import _git only if a '.git' file is found in the current
directory. Otherwise, it provides implementations that operates on the
local files only.
@cdevienne cdevienne requested a review from a team as a code owner April 14, 2025 16:59
@cdevienne cdevienne force-pushed the alternate-vcs branch 2 times, most recently from 7a5649d to 16b7895 Compare April 14, 2025 17:29
@adiroiban
Copy link
Copy Markdown
Member

Thanks, Christophe for the PR.

I would love to see support for HG in towncrier

In order to merge this PR, it's critical to have all the tests succesfully executed and all new code to be covered by tests.

We still support Python 3.8 and Python 3.9

We can remove support for 3.8 ... but in a separate PR.

And if supporting Python 3.9 is too much effort, we can also consider removing support for Python 3.9

mypy checkes are part of our standard tests

src/towncrier/_hg.py:18: error: Function is missing a return type annotation  [no-untyped-def]
src/towncrier/_hg.py:42: error: Returning Any from function declared to return "bool"  [no-any-return]
src/towncrier/_vcs.py:6: error: Function is missing a return type annotation  [no-untyped-def]
src/towncrier/_vcs.py:26: error: Returning Any from function declared to return "str | None"  [no-any-return]
src/towncrier/_vcs.py:30: error: Returning Any from function declared to return "None"  [no-any-return]
src/towncrier/_vcs.py:34: error: Returning Any from function declared to return "None"  [no-any-return]
src/towncrier/_vcs.py:38: error: Returning Any from function declared to return "list[str]"  [no-any-return]
src/towncrier/_vcs.py:44: error: Returning Any from function declared to return "list[str]"  [no-any-return]
Found 8 errors in 2 files (checked [19](https://github.com/twisted/towncrier/actions/runs/14451901365/job/40526351238?pr=699#step:7:20) source files)

@cdevienne
Copy link
Copy Markdown
Contributor Author

yep, I am working on getting the tests to pass. The type checking part is a little more problematic for me, but I will find a way.

@adiroiban
Copy link
Copy Markdown
Member

Thanks for following up with the tests

Just a reminder... if supporting Python 3.8 is too hard, we can remove support for it.

The type checking part is a little more problematic for me, but I will find a way.

Don't worry too much. Just ask for help and we can see how we can fix the mypy part.

Thanks again!

@cdevienne
Copy link
Copy Markdown
Contributor Author

I think the tests and typing are good now, but the tests on Windows fail for an unknown reason.
My guess is that I broke something in the _git module, but I have no idea what.

Since I have no easy access to a windows computer, I would be glad if someone could have a look. Thanks!

Comment thread src/towncrier/_vcs.py Outdated
Comment thread src/towncrier/newsfragments/394.feature.rst Outdated
Comment thread pyproject.toml
Comment thread src/towncrier/_hg.py Outdated
Comment thread src/towncrier/test/test_hg.py Outdated
@adiroiban
Copy link
Copy Markdown
Member

Thanks for the PR... I only did a quick review.
The code looks good.

I hope you can fix the Windows issue and then we can get a report for the code coverage.

Having good test coverage for the Mergurial code is the only way to guarantee that we will not break hg support in future releases

Thanks again! Great job here!

@adiroiban
Copy link
Copy Markdown
Member

You can get access to GitHub VMs using tmate
This should work even on Windows

@cdevienne
Copy link
Copy Markdown
Contributor Author

I made a good guess and voilà, the tests pass on all platforms!

I will follow your review recommendations shortly, and it should be good.

@cdevienne
Copy link
Copy Markdown
Contributor Author

I added comments to match your review recommendations (thanks!).

Note that the mercurial tests only test the _hg module itself. No full stack scenario run on a mercurial repository. So the tests are good as long as no change is done to the _vcs API.

One thing I will do is adding a test for _vcs that agnostically tests all the possible vcs, which will ensure all the provided vcs are up-to-date.

Then we should be good for merging.

Comment thread src/towncrier/test/test_novcs.py
Comment thread src/towncrier/test/test_novcs.py
Comment thread src/towncrier/test/test_novcs.py
Comment thread src/towncrier/_vcs.py
@adiroiban
Copy link
Copy Markdown
Member

adiroiban commented Apr 16, 2025

Just asking

Do we want to support using towncrier without a VCS ?
Does is make sense to have towncrier without a VCS?
Is this a real use case?


It would be nice to have at least a few end to end tests for hg.

The towncrier project doesn't have a big team of developers so most probably when changes are made in a PR, people will not manually run hg tests to check for regressions.

As an initial support I think that the test coverage in this PR is good enough ... is not perfect... but towncrier is a dev tool, so we should be fine.

If defects are found in hg people can follow up with PR to improve the support for hg


I added a review from Copilot, just as a double check...and to test how good AI can be.

thanks again for the updates

@adiroiban adiroiban requested a review from Copilot April 16, 2025 09:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 11 out of 12 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • src/towncrier/newsfragments/394.feature.rst: Language not supported
Comments suppressed due to low confidence (1)

src/towncrier/_git.py:31

  • The removal of the try-except block around the check_output call in remove_files may cause the function to fail in non-Git repositories. Consider reintroducing exception handling (for example, using a try-except block to catch CalledProcessError) to ensure graceful failure.
git_fragments = check_output(["git", "ls-files"] + fragment_filenames, encoding="utf-8").split("\n")

@cdevienne
Copy link
Copy Markdown
Contributor Author

In real life the 'without a VCS' case is more likely to be a 'with unsupported VCS', or testing towncrier in a non-versioned directory before adopting it. In the later case I find it more friendly not to throw errors at a potential adopter's face.

I added the test I mentioned. On my side it's all good. Thanks for the time spent on my contribution!

This test is runned on all the known vcs, so they all remain up-to-date.
@cdevienne
Copy link
Copy Markdown
Contributor Author

Oh and of course don't hesitate to ping me if some mercurial related issues come up.

@adiroiban
Copy link
Copy Markdown
Member

Thanks for the update.
Let's get this merged and hopefully we will also have a new release soon.

People can then use towncrier with hg and if needed we can receive improvements on the current code

I think that the current code is a solid foundation.

@adiroiban adiroiban merged commit f080db6 into twisted:trunk Apr 16, 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.

Support for other VCS (e.g. Mercurial)

3 participants