cookiecutter-data-science icon indicating copy to clipboard operation
cookiecutter-data-science copied to clipboard

Initialize Git repository on creation

Open mattayes opened this issue 9 years ago • 7 comments

Could we add a post-generate hook to run git init after repository creation? It's not a make-or-break, just a nice convenience.

mattayes avatar Oct 25 '16 21:10 mattayes

This is a cool idea. Two potential concerns here:

  1. Git-centricity. Even though this project uses git+Github as the VCS, we actually don't make assumptions about what version control the data science project will be using.
  2. Platform compatibility. Even if we're not directly calling out using subprocess or the like (not to mention assuming a binary called git is on the system path), then even using a Python git wrapper I fear we are assuming libgit is installed.

I'm inclined to give this a discussion label for a while and see if people feel strongly.

isms avatar Oct 26 '16 02:10 isms

That all makes total sense. I think you're right, it's wrong to assume everyone is going to use Git.

It might be nice to give users a choice of which VCS they want to use (or do nothing if no input is provied) and then roll from there. That removes the Git-centricity at the cost of having to handle at least some of the more common options (Git, Mercurial, Subversion, etc.).

To address the platform compatibility issue, we could add some exception handling for missing installations:

# Bad pseudocode
try:
    setup_vcs(vcs)
except ExceptionThatNeedsToBeHandled:
    print('{0} binary not found. Is {0} installed?'.format(vcs))

What do you think?

mattayes avatar Oct 26 '16 04:10 mattayes

For those interested, I'm doing this in my fork of the cookiecutter with the following bash script

I then added a command to the Makefile:

## Push to GitHub repo
push: 
	git add -A
	git commit -m 'Make Git update'
	git push

Nice, I like it @ConstantinoSchillebeeckx!

@isms What do you think about a plug-and-play way to initialize a version control system?

mattayes avatar Feb 06 '17 05:02 mattayes

@mattayes Cool idea - what do you think an implementation might look like?

isms avatar Feb 06 '17 17:02 isms

Also, just a note here, I've been holding off on optional features while I watch: https://github.com/audreyr/cookiecutter/pull/848

Unfortunately, that issue is currently stalled because the cookiecutter project needs sponsorship.

For things like VCS where we want options and may have fields that are conditional on your choice, it's pretty tough to manage with the current cookiecutter workflow, which doesn't really do branching. I was hoping that the PR referenced above would get pulled in for these kinds of features, but that's not super likely.

The one thing we could look at is doing is conditional files using this kind of syntax: https://github.com/audreyr/cookiecutter/issues/723

We'd need to map out the files that would conditionally added if you chose git as your VCS (e.g., the bash to set up a repo).

pjbull avatar Feb 06 '17 18:02 pjbull

Thanks @pjbull for the context. It's too bad audreyr/cookiecutter#848 is held up.

My thought is we provide a general API:

class VCS(object):
    ...
    def initialize(self):
        <creates the repo>

Then a (very rough) Git implementation:

import git

class GitVCS(VCS):
    def initialize(self, dir):
        r = git.Repo.init(repo_dir)
        <potentially add initial commit>

We would ask folks which VCS they want (if any), then run the appropriate VCS subclass.

mattayes avatar Feb 08 '17 05:02 mattayes