Created
November 28, 2018 21:51
-
-
Save jaymecd/d42fcb3207cb4c4f5c1ea971a22c310f to your computer and use it in GitHub Desktop.
Get `pip freeze` packages for target directory, which was installed using `pip install -t <path>`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# RUN: pip_target_freeze.py <path> | |
from pip._vendor import pkg_resources | |
import sys | |
def find_on_path(path): | |
dists = pkg_resources.find_on_path(None, path) | |
dists = sorted(dists, key=lambda item: str(item)) | |
return dists | |
def main(): | |
path = sys.argv[1] if len(sys.argv) > 1 else '.' | |
dists = find_on_path(path) | |
for dist in dists: | |
print('{}=={}'.format(dist.project_name, dist.version)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment