|
| 1 | +#!/usr/bin/env python |
| 2 | +""" |
| 3 | +python-dnn uses python (and theano) to implement major Deep Learing Networks. |
| 4 | +It currently supports: |
| 5 | + CNN |
| 6 | + SDA |
| 7 | + DBN |
| 8 | + A general DNN Finetune kit with maxout and dropout. |
| 9 | +""" |
| 10 | + |
| 11 | +from setuptools import setup, find_packages,Command |
| 12 | +import subprocess |
| 13 | +import os |
| 14 | + |
| 15 | + |
| 16 | +DOCLINES = __doc__.split("\n") |
| 17 | + |
| 18 | + |
| 19 | +CLASSIFIERS = """\ |
| 20 | +Development Status :: 4 - Beta |
| 21 | +Intended Audience :: Science/Research |
| 22 | +Intended Audience :: Developers |
| 23 | +License :: Apache v2.0 License |
| 24 | +Programming Language :: C |
| 25 | +Programming Language :: Python |
| 26 | +Topic :: Software Development |
| 27 | +Topic :: Scientific/Engineering |
| 28 | +Operating System :: POSIX |
| 29 | +
|
| 30 | +""" |
| 31 | + |
| 32 | +MAJOR = 1 |
| 33 | +MINOR = 0 |
| 34 | +MICRO = 1 |
| 35 | +ISRELEASED = True |
| 36 | +VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +class CleanCommand(Command): |
| 42 | + """Custom clean command to tidy up the project root.""" |
| 43 | + user_options = [] |
| 44 | + def initialize_options(self): |
| 45 | + pass |
| 46 | + def finalize_options(self): |
| 47 | + pass |
| 48 | + def run(self): |
| 49 | + os.system('rm -vrf ./build ./dist ./*.pyc ./*.tgz ./*.egg-info ./src/pythonDnn/version.py ./src/*.egg-info') |
| 50 | + |
| 51 | + |
| 52 | +# Return the git revision as a string |
| 53 | +def git_version(): |
| 54 | + def _minimal_ext_cmd(cmd): |
| 55 | + # construct minimal environment |
| 56 | + env = {} |
| 57 | + for k in ['SYSTEMROOT', 'PATH']: |
| 58 | + v = os.environ.get(k) |
| 59 | + if v is not None: |
| 60 | + env[k] = v |
| 61 | + env['LANGUAGE'] = 'C' |
| 62 | + env['LANG'] = 'C' |
| 63 | + env['LC_ALL'] = 'C' |
| 64 | + out = subprocess.Popen(cmd, stdout = subprocess.PIPE, env=env).communicate()[0] |
| 65 | + return out |
| 66 | + |
| 67 | + try: |
| 68 | + out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD']) |
| 69 | + GIT_REVISION = out.strip().decode('ascii') |
| 70 | + except OSError: |
| 71 | + GIT_REVISION = "Unknown" |
| 72 | + |
| 73 | + return GIT_REVISION |
| 74 | + |
| 75 | + |
| 76 | +def get_version_info(): |
| 77 | + # Adding the git rev number needs to be done inside |
| 78 | + # write_version_py(), otherwise the import of scipy.version messes |
| 79 | + # up the build under Python 3. |
| 80 | + FULLVERSION = VERSION |
| 81 | + if os.path.exists('.git'): |
| 82 | + GIT_REVISION = git_version() |
| 83 | + else: |
| 84 | + GIT_REVISION = "Unknown" |
| 85 | + |
| 86 | + if not ISRELEASED: |
| 87 | + FULLVERSION += '.dev-' + GIT_REVISION[:7] |
| 88 | + |
| 89 | + return FULLVERSION, GIT_REVISION |
| 90 | + |
| 91 | + |
| 92 | +def write_version_py(filename='src/pythonDnn/version.py'): |
| 93 | + cnt = """ |
| 94 | +# THIS FILE IS GENERATED FROM SCIPY SETUP.PY |
| 95 | +short_version = '%(version)s' |
| 96 | +version = '%(version)s' |
| 97 | +full_version = '%(full_version)s' |
| 98 | +git_revision = '%(git_revision)s' |
| 99 | +release = %(isrelease)s |
| 100 | +
|
| 101 | +if not release: |
| 102 | + version = full_version |
| 103 | +""" |
| 104 | + FULLVERSION, GIT_REVISION = get_version_info() |
| 105 | + |
| 106 | + a = open(filename, 'w') |
| 107 | + try: |
| 108 | + a.write(cnt % {'version': VERSION, |
| 109 | + 'full_version' : FULLVERSION, |
| 110 | + 'git_revision' : GIT_REVISION, |
| 111 | + 'isrelease': str(ISRELEASED)}) |
| 112 | + finally: |
| 113 | + a.close() |
| 114 | + |
| 115 | +if __name__ == '__main__': |
| 116 | + # Rewrite the version file every time |
| 117 | + write_version_py() |
| 118 | + |
| 119 | + try: |
| 120 | + import theano |
| 121 | + requires=[] |
| 122 | + except ImportError: |
| 123 | + requires=['theano>=0.7.0'] |
| 124 | + |
| 125 | + metadata = dict( |
| 126 | + name = 'pythonDnn', |
| 127 | + maintainer = "pythonDnn", |
| 128 | + maintainer_email = "pythonDnn@ex.org", |
| 129 | + description = DOCLINES[0], |
| 130 | + long_description = "\n".join(DOCLINES[2:]), |
| 131 | + url = "https://github.com/IITM-DONLAB/python-dnn", |
| 132 | + download_url = "https://github.com/IITM-DONLAB/python-dnn/zipball/master", |
| 133 | + license = 'Apache v2.0 License', |
| 134 | + packages = [ |
| 135 | + 'pythonDnn.io_modules', 'pythonDnn.layers', 'pythonDnn.models', |
| 136 | + 'pythonDnn.run', 'pythonDnn.utils'], |
| 137 | + package_dir = {'': 'src'}, |
| 138 | + install_requires = requires, |
| 139 | + zip_safe=False, |
| 140 | + cmdclass={'clean': CleanCommand,}, |
| 141 | + ) |
| 142 | + FULLVERSION, GIT_REVISION = get_version_info() |
| 143 | + metadata['version'] = FULLVERSION |
| 144 | + setup(**metadata) |
0 commit comments