Skip to content

Instantly share code, notes, and snippets.

@aodag
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aodag/11261788 to your computer and use it in GitHub Desktop.
Save aodag/11261788 to your computer and use it in GitHub Desktop.
多分なにかある
#!/usr/bin/env python3.3
import sys
import os
import re
import argparse
import distlib.wheel
import subprocess
import distlib.metadata
import distlib.locators
def wheelinfo(dir):
for f in os.listdir(dir):
_, ext = os.path.splitext(f)
if ext != '.whl':
continue
whl = distlib.wheel.Wheel(os.path.join(dir, f))
if not whl.is_compatible():
continue
yield ("{whl.name}=={whl.version}".format(whl=whl))
def cmd_freeze(args):
for w in sorted(wheelinfo(args.dir)):
print(w)
def cmd_develop(args):
wheelhouse = 'wheelhouse'
output = subprocess.check_output("{python} setup.py egg_info".format(python=sys.executable).split())
output = output.decode('utf-8')
matched = re.search(r'(\w*\.egg-info/requires.txt)', output, re.MULTILINE)
locator = distlib.locators.DirectoryLocator(wheelhouse)
requires_txt = matched.groups()[0]
with open(requires_txt) as f:
for line in f:
line = line.strip()
dist = locator.locate(line)
if dist:
print(dist)
continue
subprocess.check_call("pip wheel --pre -f wheelhouse {0}".format(line).split())
subprocess.check_call("pip install --pre -f wheelhouse -r {0}".format(requires_txt).split())
def main():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
freeze_parser = subparsers.add_parser('freeze')
freeze_parser.add_argument('dir')
freeze_parser.set_defaults(func=cmd_freeze)
develop_parser = subparsers.add_parser('develop')
develop_parser.set_defaults(func=cmd_develop)
args = parser.parse_args()
if hasattr(args, "func"):
args.func(args)
if __name__ == '__main__':
main()
@aodag
Copy link
Author

aodag commented Apr 27, 2014

requires.txt に extras_requireのセクションがあると落ちる

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment