#!/usr/bin/env python3
#
#

import sys, site, os

sys.path.insert(0, os.getcwd())

try:
    from setuptools.command.easy_install import main
    import pkg_resources
except ImportError as ex: print("setuptools is needed to use nest: %s" % str(ex)) ;  os._exit(1)

os.popen("python3 setup.py sdist").readlines()

installdir = os.path.join(os.getcwd(), 'run')
os.environ['PYTHONPATH'] = installdir
sys.path.insert(0, installdir)
sys.path.insert(0, installdir + os.sep + 'bin')

if not os.path.isdir(installdir):
    os.mkdir(installdir)

tlist = []
for fn in os.listdir("dist"):
    if fn.endswith(".tar.gz"):
        tlist.append(fn)

slist = sorted(tlist)
fname = slist[-1]
print(fname)
runstring = '--install-dir %s -a -U %s' % (installdir, os.path.join("dist", fname))
main(runstring.split())
