Mercurial > hg > MakeItSo
diff 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 |
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__))