Last active
August 29, 2015 14:00
-
-
Save aodag/11261788 to your computer and use it in GitHub Desktop.
多分なにかある
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 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
requires.txt に extras_requireのセクションがあると落ちる