1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4import io 5import os 6import re 7import shutil 8import subprocess 9import sys 10import warnings 11 12from setuptools import setup 13 14pkg_name = 'pycodeexport' 15url = 'https://github.com/bjodah/' + pkg_name 16license = 'BSD' 17 18 19def _path_under_setup(*args): 20 return os.path.join(os.path.dirname(__file__), *args) 21 22release_py_path = _path_under_setup(pkg_name, '_release.py') 23 24_version_env_var = '%s_RELEASE_VERSION' % pkg_name.upper() 25RELEASE_VERSION = os.environ.get(_version_env_var, '') 26 27# http://conda.pydata.org/docs/build.html#environment-variables-set-during-the-build-process 28CONDA_BUILD = os.environ.get('CONDA_BUILD', '0') == '1' 29if CONDA_BUILD: 30 try: 31 RELEASE_VERSION = 'v' + open('__conda_version__.txt', 'rt').readline().rstrip() 32 except IOError: 33 pass 34 35if len(RELEASE_VERSION) > 1 and RELEASE_VERSION[0] == 'v': 36 TAGGED_RELEASE = True 37 __version__ = RELEASE_VERSION[1:] 38else: 39 TAGGED_RELEASE = False 40 # read __version__ attribute from _release.py: 41 exec(io.open(release_py_path, encoding='utf-8').read()) 42 if __version__.endswith('git'): 43 try: 44 _git_version = subprocess.check_output( 45 ['git', 'describe', '--dirty']).rstrip().decode('utf-8').replace('-dirty', '.dirty') 46 except subprocess.CalledProcessError: 47 warnings.warn("A git-archive is being installed - version information incomplete.") 48 else: 49 if 'develop' not in sys.argv: 50 warnings.warn("Using git to derive version: dev-branches may compete.") 51 __version__ = re.sub(r'v([0-9.]+)-(\d+)-(\w+)', r'\1.post\2+\3', _git_version) # .dev < '' < .post 52 53tests = [ 54 '%s.tests' % pkg_name, 55] 56 57 58classifiers = [ 59 "Development Status :: 3 - Alpha", 60 "Intended Audience :: Developers", 61 "License :: OSI Approved :: BSD License", 62 "Operating System :: POSIX", 63 "Programming Language :: Python", 64 "Programming Language :: C", 65 "Programming Language :: C++", 66 "Programming Language :: Cython", 67 "Programming Language :: Fortran", 68 "Topic :: Software Development :: Code Generators", 69 "Topic :: Software Development :: Compilers", 70 "Topic :: Software Development :: Libraries :: Python Modules" 71] 72 73with io.open(_path_under_setup(pkg_name, '__init__.py'), 'rt', encoding='utf-8') as f: 74 short_description = f.read().split('"""')[1].split('\n')[1] 75if not 10 < len(short_description) < 255: 76 warnings.warn("Short description from __init__.py proably not read correctly.") 77long_description = io.open(_path_under_setup('README.rst'), 78 encoding='utf-8').read() 79if not len(long_description) > 100: 80 warnings.warn("Long description from README.rst probably not read correctly.") 81_author, _author_email = io.open(_path_under_setup('AUTHORS'), 'rt', encoding='utf-8').readline().split('<') 82 83setup_kwargs = dict( 84 name=pkg_name, 85 version=__version__, # from release_py_path 86 description=short_description, 87 long_description=long_description, 88 author=_author.strip(), 89 author_email=_author_email.split('>')[0].strip(), 90 url=url, 91 license=license, 92 packages=[pkg_name] + tests, 93 classifiers=classifiers, 94 install_requires=['mako>=1.0.0', 'pycompilation>=0.4.0', 'sympy>=0.7.5', 95 'cython>=0.20.2'], 96 extras_require={ 97 'all': ['cython', 'pytest', 'numpy', 'Sphinx', 'sphinx_rtd_theme', 98 'numpydoc', 'pytest-cov', 'pytest-flakes', 'pytest-pep8'] 99 }, 100) 101 102if __name__ == '__main__': 103 try: 104 if TAGGED_RELEASE: 105 # Same commit should generate different sdist 106 # depending on tagged version (set ${pkg_name}_RELEASE_VERSION) 107 # this will ensure source distributions contain the correct version 108 shutil.move(release_py_path, release_py_path+'__temp__') 109 open(release_py_path, 'wt').write( 110 "__version__ = '{}'\n".format(__version__)) 111 setup(**setup_kwargs) 112 finally: 113 if TAGGED_RELEASE: 114 shutil.move(release_py_path+'__temp__', release_py_path) 115