copier icon indicating copy to clipboard operation
copier copied to clipboard

Replace `git` subprocess by `pygit2`

Open astrojuanlu opened this issue 2 years ago • 9 comments

Is your feature request related to a problem? Please describe. Now copier relies on git being installed in the system:

https://github.com/copier-org/copier/blob/47f3d59c27094e6f8ef0bc71acc74d88cbf6bb78/README.md?plain=1#L25

However, it would be nice if all the dependencies could be installed with pip without having to reach for the system package manager. This would be useful for folks that don't have admin access to their systems, but can pip install to their user locations.

Describe the solution you'd like Replace subprocess calls to git through plumbum:

https://github.com/copier-org/copier/blob/47f3d59c27094e6f8ef0bc71acc74d88cbf6bb78/copier/main.py#L801-L811

with pygit2, the Python bindings for libgit2, which ship precompiled binary wheels for plenty of platforms:

https://pypi.org/project/pygit2/1.11.1/#files

As a side effect, this will also probably be faster (but I don't have data to back this up).

Describe alternatives you've considered Could not think of other alternatives.

Additional context This was rejected for cookiecutter as early as 2016: https://github.com/cookiecutter/cookiecutter/issues/846#issuecomment-258049634

In Kedro we are trying to remove our dependency with system git https://github.com/kedro-org/kedro/issues/2051 which prompted me to open this issue.

astrojuanlu avatar Mar 21 '23 08:03 astrojuanlu

I like the idea of removing the prerequisite of having Git installed. But I stumbled over one caveat that is a blocker for me:

Binary wheels for Windows are available, but they don’t have support for ssh.

— https://www.pygit2.org/install.html#quick-install (under "Caveats")

I don't use Windows, but I know many who do, and supporting SSH is quite important in our environment.

sisp avatar Mar 21 '23 13:03 sisp

But perhaps dulwich could be an alternative worth looking into. I have no experience with dulwich, but, e.g., DVC uses it in their scmrepo library as one of the possible Git library backends.

dulwich uses a dual license:

License: Apache License, version 2 or GNU General Public License, version 2 or later.

I'm no laywer, but since both Apache v2+ and GPL v2+ are possible, I think it should be fine (mainly looking at Apache v2+ here).

WDYT, @astrojuanlu?

sisp avatar Mar 21 '23 13:03 sisp

I'd suggest that we implement this with a fallback to the git system exec, and maybe an option to prefer the system exec over the Python lib/bindng, since they might differ in features/behavior.

pawamoy avatar Mar 21 '23 17:03 pawamoy

I havw no experience with either, but @pawamoy suggestion looks sensible enough!

astrojuanlu avatar Mar 21 '23 21:03 astrojuanlu

Just to be sure: is this issue open for pull requests then? Or is there more discussion needed?

astrojuanlu avatar Mar 26 '23 14:03 astrojuanlu

I think this can be split in 2.

The 1st thing is to not require git. Copier can work with gitless templates. They have less features, but they work. Git should only be required when using a gitful template.

If you want a gitful template, I can't imagine why would you not have git installed, so that could be the real fix here.

If there are reasons why that can happen and still dulwitch works for us (copier uses git deeply and intensely), then replacing git is the 2nd part of the story.

FWIW if we're about letting users use gitful templates without git, another option is to support templates in zip files.

Also we can bundle git propagated in the nix package, so installing copier with nix just works out of the box.

yajo avatar Apr 01 '23 12:04 yajo

The 1st thing is to not require git. Copier can work with gitless templates. They have less features, but they work. Git should only be required when using a gitful template.

Related to #312.

sisp avatar Apr 01 '23 13:04 sisp

For reference, part (1) of @yajo's comment above (gh-312) was implemented in gh-1074 👍🏽

astrojuanlu avatar Aug 28 '23 17:08 astrojuanlu

Maybe still there's work to do. See https://github.com/copier-org/copier/issues/1304.

yajo avatar Aug 29 '23 14:08 yajo