setup.py 2.29 KB
Newer Older
1 2 3 4 5
'''A setuptools based setup module.

https://packaging.python.org/en/latest/distributing.html
'''
from setuptools import setup, find_packages
Michael Salim's avatar
Michael Salim committed
6 7
from setuptools.command.install import install
from setuptools.command.develop import develop
8 9
from codecs import open
from os import path
Michael Salim's avatar
Michael Salim committed
10
import os
11
import time
Michael Salim's avatar
Michael Salim committed
12 13

def auto_setup_db():
14 15
    here = path.abspath(path.dirname(__file__))
    default_db_path = os.path.join(here , 'default_balsamdb')
Michael Salim's avatar
Michael Salim committed
16 17 18 19 20 21
    try:
        os.mkdir(default_db_path, mode=0o755)
    except OSError:
        from shutil import rmtree
        rmtree(default_db_path)
        os.mkdir(default_db_path, mode=0o755)
22 23 24 25
    time.sleep(1)
    cwd = os.getcwd()
    os.chdir(default_db_path)
    with open("dbwriter_address", 'w') as fp:
26
        fp.write('{"db_type": "sqlite3"}')
27
    os.chdir(cwd)
28

Michael Salim's avatar
Michael Salim committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
    import django
    os.environ['DJANGO_SETTINGS_MODULE'] = 'balsam.django_config.settings'
    django.setup()
    from django.core.management import call_command
    call_command('makemigrations',interactive=False,verbosity=2)
    call_command('migrate',interactive=False,verbosity=2)


class PostInstallCommand(install):
    '''Post-installation for installation mode'''
    def run(self):
        auto_setup_db()
        install.run(self)


class PostDevelopCommand(develop):
    '''Post-installation for installation mode'''
    def run(self):
        auto_setup_db()
        develop.run(self)

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

here = path.abspath(path.dirname(__file__))

with open(path.join(here, 'README.md'), encoding='utf-8') as f:
    long_description = f.read()

setup(
    name='balsam',
    version='0.1',
    description='HPC Edge service and workflow management',
    long_description=long_description,
    
    url='', # Home page
    author='',
    author_email='',

    classifiers = [],

    keywords='',

70
    packages=find_packages(exclude=['docs','__pycache__','data','experiments','log',]),
71

72
    install_requires=['django', 'django-concurrency', 'pyzmq'],
73 74 75 76 77 78 79 80 81 82 83

    include_package_data=True,

    # Register command-line tools here
    entry_points={
        'console_scripts': [
            'balsam = balsam.scripts.cli:main',
            'balsam-test = run_tests:main'
        ],
        'gui_scripts': [],
    },
Michael Salim's avatar
Michael Salim committed
84 85 86 87 88 89

    # Balsam DB auto-setup post installation
    cmdclass={
        'develop': PostDevelopCommand,
        'install': PostInstallCommand,
    },
90
)