How to find out which commit was used when installing pip package from git?

If I installed the package from git using https://pip.pypa.io/en/stable/reference/pip_install/#git does the particular commit that was registered somewhere?

+6
source share
3 answers

You can use the idea of ​​knittl to find the closest commit - the only modification below is the fact that you are comparing the git tree with the installed package, and not the git repository:

Since there may not be a git repository directory structure for the installed package, create a new directory for the git repo. I use html5lib for an example:

 mkdir ~/tmp/html5lib cd ~/tmp/html5lib/ git init 

Now select the git tree:

 git remote add foreign https://github.com/html5lib/html5lib-python git fetch foreign 

Copy the installed package in git repo:

 rsync -a ~/.virtualenvs/muffy/lib/python3.4/site-packages/html5lib ~/tmp/html5lib/ 

Run git diff to compare the current state of the repo (with the installed package code) with each revision in the git tree:

 for REV in $(git rev-list --all); do echo $(git diff --shortstat foreign/master $REV) $REV ; done | sort -n 

This is sorted by the number of modified files, then the number of inserts, and then deletion. The result will look something like this:

 1 file changed, 3 insertions(+), 1 deletion(-) 17499b9763a090f7715af49555d21fe4b558958b 2 files changed, 10 insertions(+), 8 deletions(-) ec674a97243e76da43f06abfd0a891308f1ff801 3 files changed, 17 insertions(+), 12 deletions(-) 1a28d721091a2c433c6e8471d14cbb75afd70d1c 4 files changed, 18 insertions(+), 13 deletions(-) ff6111cd82191a2eb963d6d662c6da8fa2e7ddde 6 files changed, 19 insertions(+), 19 deletions(-) ea0fafdbff732b1272140b696d6948054ed1d6d2 

The last item on each line is associated with a git commit.

If the git story is very long, you want to change git rev-list --all to a range of commits. For example, use git rev-list tag1..tag2 to search between two tags. If you know roughly when the package was installed, you may have a good guess about which tags to use. Use git tag to show possible tag names. See documents for more options.

+3
source

One possible alternative is to use pip install --editable . In this case, pip clones the repository to $PREFIX/src/$egg_name (where $PREFIX is your virtualenv directory or the current working directory), and then simply creates an egg-link on an egg-link pointing to this path. This way, you can easily check the current version of the cloned repo.

On the other hand, a package installed in this way may have a file structure different from that established in the usual way. So in some cases this will not work.

+2
source

This is not true. If you just want to find out, find the commit at the head of the installed branch. If you want to set a specific commit name commit. For instance:

 pip install git+https://github.com/sqlobject/ sqlobject.git@623a5802 #egg=sqlobject 
+1
source

Source: https://habr.com/ru/post/1270868/


All Articles