Skip to content

Instantly share code, notes, and snippets.

@jmkacz
Created September 10, 2013 13:43
Show Gist options
  • Save jmkacz/6509589 to your computer and use it in GitHub Desktop.
Save jmkacz/6509589 to your computer and use it in GitHub Desktop.
discovering scripts for a python package
# Show the information for the installed package, within the virtualenv.
(test)jon-mbp:tmp jon$ pip show --files diamond
---
Name: diamond
Version: 3.3.437
Location: /private/tmp/test/lib/python2.7/site-packages
Requires: ConfigObj, psutil
Files:
... snip ...
../diamond/__init__.py
../../../../share/diamond/LICENSE
../../../../etc/diamond/diamond.conf.example
./
dependency_links.txt
PKG-INFO
requires.txt
SOURCES.txt
top_level.txt
../../../../bin/diamond
../../../../bin/diamond-setup
# /private/tmp/test/lib/python2.7/site-packages/diamond-3.3.437-py2.7.egg-info is the actual base path, relative to the files
# listed. Because of this, select files that only begin with "../".
../diamond/__init__.py
../../../../share/diamond/LICENSE
../../../../etc/diamond/diamond.conf.example
../../../../bin/diamond
../../../../bin/diamond-setup
# Remove the leading "../".
diamond/__init__.py
../../../share/diamond/LICENSE
../../../etc/diamond/diamond.conf.example
../../../bin/diamond
../../../bin/diamond-setup
# Join the listed "location" with each file.
/private/tmp/test/lib/python2.7/site-packages/diamond/__init__.py
/private/tmp/test/lib/python2.7/site-packages/../../../share/diamond/LICENSE
/private/tmp/test/lib/python2.7/site-packages/../../../etc/diamond/diamond.conf.example
/private/tmp/test/lib/python2.7/site-packages/../../../bin/diamond
/private/tmp/test/lib/python2.7/site-packages/../../../bin/diamond-setup
# Call os.path.realpath, on each file.
/private/tmp/test/lib/python2.7/site-packages/diamond/__init__.py
/private/tmp/test/share/diamond/LICENSE
/private/tmp/test/etc/diamond/diamond.conf.example
/private/tmp/test/bin/diamond
/private/tmp/test/bin/diamond-setup
# Since we're operating in a virtualenv, and we know its location, and we care about the scripts under bin, we can filter for
# files that start with /private/tmp/test/bin/.
/private/tmp/test/bin/diamond
/private/tmp/test/bin/diamond-setup
# Now that we have the list of scripts, we can symlink them into /usr/local/bin. What should be the behavior if the link exists?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment