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

Replace GitPython with pygit2 #2120

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

mgorny
Copy link

@mgorny mgorny commented Nov 6, 2024

Checklist

  • Added a news entry
  • Regenerated schema JSON if schema altered (python conda_smithy/schema.py)

Replace the use of GitPython package with pygit2. The latter seems to have better git support, in particular it supports the newer index versions 3 and 4. Since it is backed by the libgit2 library that is also used by Cargo, it seems to have the best chances of being updated for compatibility with new git versions.

Admittedly, the API feels very low-level. In particular, it is necessary to explicitly request writing changes to index back, and explicitly reread it when it's modified externally (e.g. via another pygit2.Repository instance, as in tests). On the plus side, it does not invoke git at all -- everything is done by the library.

Fixes #2116


So far focused on feedstock_io.py and its tests. I need to figure out how to test the changes to other files properly, given that the tests mock the entire git.Repo.clone_from call.

@mgorny mgorny requested a review from a team as a code owner November 6, 2024 16:16
@mgorny mgorny marked this pull request as draft November 6, 2024 16:16
@mgorny mgorny force-pushed the pygit2 branch 2 times, most recently from f6dadb8 to e90a067 Compare November 6, 2024 16:21
Comment on lines +12 to +17
if search_parent_directories:
path = pygit2.discover_repository(path)
if path is not None:
repo = pygit2.Repository(
path, pygit2.enums.RepositoryOpenFlag.NO_SEARCH
)
Copy link
Author

Choose a reason for hiding this comment

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

FWICS we never call it with search_parent_directories=False. If we were to remove that kwarg, we could just remove NO_SEARCH (or we could change flags based on the arg value — but I've figured doing it more explicitly is more readable).

Replace the use of GitPython package with pygit2.  The latter seems
to have better git support, in particular it supports the newer index
versions 3 and 4.  Since it is backed by the libgit2 library that is
also used by Cargo, it seems to have the best chances of being updated
for compatibility with new git versions.

Admittedly, the API feels very low-level.  In particular, it is
necessary to explicitly request writing changes to index back,
and explicitly reread it when it's modified externally (e.g. via another
`pygit2.Repository` instance, as in tests).  On the plus side, it does
not invoke `git` at all -- everything is done by the library.

Fixes conda-forge#2116
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.

conda smithy rerender -c auto failing with AssertionError on git repositories with index v3
1 participant