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

Git advice for online documentation #7

Open
DamienIrving opened this issue Apr 16, 2021 · 0 comments
Open

Git advice for online documentation #7

DamienIrving opened this issue Apr 16, 2021 · 0 comments

Comments

@DamienIrving
Copy link
Owner

DamienIrving commented Apr 16, 2021

It might be worth adding some notes to the online documentation to explain how to automate adding some git information to command logs.

  1. Install gitpython
$ conda install gitpython
  1. Use sys.path[0] (which returns the directory your script is in) to get the repository directory. (If your script isn't in the top level directory of the repo, you might need to use something like repo_dir = '/'.join(script_dir.split('/')[:-1])):
import sys
repo_dir = sys.path[0]
import git

print(repo_dir)
/Users/damien/Desktop/data-carpentry
  1. Now access information like the git hash and code url:
repo = git.Repo(repo_dir)
hash = str(repo.heads[0].commit)
print(hash)
b7f46dafe58cd3be5118766816a3fc190f21a50b
code_url = repo.remotes[0].url.split('.git')[0]
print(code_url)
https://github.com/DamienIrving/data-carpentry
  1. Add that information to the new log:
import cmdline_provenance as cmdprov

cmdprov.new_log(code_url=code_url, extra_notes=[f'Git hash: {hash}'])
Fri Apr 16 11:56:38 2021: /Users/damien/opt/anaconda3/envs/pyaos-lesson/bin/jupyter notebook /Users/damien/Desktop/data-carpentry/Untitled.ipynb (https://github.com/DamienIrving/data-carpentry)
Extra notes:
Git hash: b7f46dafe58cd3be5118766816a3fc190f21a50b
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

No branches or pull requests

1 participant