Mercurial > hg > MakeItSo
comparison makeitso/python_package/{{package}}/{{main}}.py @ 210:ab726b2f3143
arbitrary python requirements, the bad way
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Wed, 25 Mar 2015 12:09:15 -0700 |
| parents | 04c5464355b8 |
| children | b4a3e8bbe095 |
comparison
equal
deleted
inserted
replaced
| 209:ee752ac566f1 | 210:ab726b2f3143 |
|---|---|
| 9 import argparse | 9 import argparse |
| 10 import os | 10 import os |
| 11 import subprocess | 11 import subprocess |
| 12 import sys | 12 import sys |
| 13 import time | 13 import time |
| 14 | |
| 15 # python requirements | |
| 16 # (key, value) = (module, PyPI name) | |
| 17 requirements = () | |
| 18 for module, package in requirements: | |
| 19 try: | |
| 20 globals()[module] = __import__(module) | |
| 21 except ImportError: | |
| 22 # install requirement and try again | |
| 23 subprocess.check_call(['pip', 'install', package]) | |
| 24 args = [sys.executable] + sys.argv | |
| 25 os.execl(sys.executable, *args) | |
| 14 | 26 |
| 15 # module globals | 27 # module globals |
| 16 __all__ = ['main', 'Parser'] | 28 __all__ = ['main', 'Parser'] |
| 17 here = os.path.dirname(os.path.realpath(__file__)) | 29 here = os.path.dirname(os.path.realpath(__file__)) |
| 18 string = (str, unicode) | 30 string = (str, unicode) |
