1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4import io 5from itertools import chain 6import os 7import re 8import shutil 9import subprocess 10import sys 11import warnings 12from setuptools import setup 13 14pkg_name = 'pyneqsys' 15url = 'https://github.com/bjodah/' + pkg_name 16license = 'BSD' 17 18RELEASE_VERSION = os.environ.get('%s_RELEASE_VERSION' % pkg_name.upper(), '') # v* 19 20 21def _path_under_setup(*args): 22 return os.path.join(os.path.dirname(__file__), *args) 23 24release_py_path = _path_under_setup(pkg_name, '_release.py') 25 26if len(RELEASE_VERSION) > 0: 27 if RELEASE_VERSION[0] == 'v': 28 TAGGED_RELEASE = True 29 __version__ = RELEASE_VERSION[1:] 30 else: 31 raise ValueError("Ill formated version") 32else: 33 TAGGED_RELEASE = False 34 # read __version__ attribute from _release.py: 35 exec(io.open(release_py_path, encoding='utf-8').read()) 36 if __version__.endswith('git'): 37 try: 38 _git_version = subprocess.check_output( 39 ['git', 'describe', '--dirty']).rstrip().decode('utf-8').replace('-dirty', '.dirty') 40 except subprocess.CalledProcessError: 41 warnings.warn("A git-archive is being installed - version information incomplete.") 42 else: 43 if 'develop' not in sys.argv: 44 warnings.warn("Using git to derive version: dev-branches may compete.") 45 _ver_tmplt = r'\1.post\2' if os.environ.get('CONDA_BUILD', '0') == '1' else r'\1.post\2+\3' 46 __version__ = re.sub('v([0-9.]+)-(\d+)-(\S+)', _ver_tmplt, _git_version) # .dev < '' < .post 47 48classifiers = [ 49 "Development Status :: 4 - Beta", 50 'License :: OSI Approved :: BSD License', 51 'Operating System :: OS Independent', 52 'Topic :: Scientific/Engineering', 53 'Topic :: Scientific/Engineering :: Mathematics', 54] 55 56tests = [ 57 'pyneqsys.tests', 58] 59 60with io.open(_path_under_setup(pkg_name, '__init__.py'), encoding='utf-8') as f: 61 short_description = f.read().split('"""')[1].split('\n')[1] 62if not 10 < len(short_description) < 255: 63 warnings.warn("Short description from __init__.py proably not read correctly") 64long_descr = io.open(_path_under_setup('README.rst'), encoding='utf-8').read() 65if not len(long_descr) > 100: 66 warnings.warn("Long description from README.rst probably not read correctly.") 67_author, _author_email = open(_path_under_setup('AUTHORS'), 'rt').readline().split('<') 68 69extras_req = { 70 'symbolic': ['pysym', 'symcxx'], # use conda for symengine 71 'docs': ['Sphinx', 'sphinx_rtd_theme', 'numpydoc'], 72 'solvers': ['pykinsol', 'levmar', 'mpmath'], # maybe also cyipopt and pynleq2 73 'testing': ['pytest', 'pytest-cov', 'pytest-flakes', 'pytest-pep8'] 74} 75extras_req['all'] = list(chain(extras_req.values())) 76 77setup_kwargs = dict( 78 name=pkg_name, 79 version=__version__, 80 description=short_description, 81 long_description=long_descr, 82 classifiers=classifiers, 83 author=_author, 84 author_email=_author_email.split('>')[0].strip(), 85 url=url, 86 license=license, 87 packages=[pkg_name] + tests, 88 install_requires=['numpy>1.7', 'sym>=0.3.1', 'sympy>=1.3', 'scipy', 'matplotlib'], 89 extras_require=extras_req 90) 91 92if __name__ == '__main__': 93 try: 94 if TAGGED_RELEASE: 95 # Same commit should generate different sdist 96 # depending on tagged version (set PYNEQSYS_RELEASE_VERSION) 97 # this will ensure source distributions contain the correct version 98 shutil.move(release_py_path, release_py_path+'__temp__') 99 open(release_py_path, 'wt').write( 100 "__version__ = '{}'\n".format(__version__)) 101 setup(**setup_kwargs) 102 finally: 103 if TAGGED_RELEASE: 104 shutil.move(release_py_path+'__temp__', release_py_path) 105