Mercurial > hg > MakeItSo
changeset 210:ab726b2f3143
arbitrary python requirements, the bad way
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Wed, 25 Mar 2015 12:09:15 -0700 |
parents | ee752ac566f1 |
children | 1203898cd195 |
files | makeitso/python_package/{{package}}/{{main}}.py |
diffstat | 1 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/makeitso/python_package/{{package}}/{{main}}.py Sat Feb 28 16:08:45 2015 -0800 +++ b/makeitso/python_package/{{package}}/{{main}}.py Wed Mar 25 12:09:15 2015 -0700 @@ -12,6 +12,18 @@ import sys import time +# python requirements +# (key, value) = (module, PyPI name) +requirements = () +for module, package in requirements: + try: + globals()[module] = __import__(module) + except ImportError: + # install requirement and try again + subprocess.check_call(['pip', 'install', package]) + args = [sys.executable] + sys.argv + os.execl(sys.executable, *args) + # module globals __all__ = ['main', 'Parser'] here = os.path.dirname(os.path.realpath(__file__))