See More

#!/usr/bin/env python # -*- encoding: utf-8 -*- from __future__ import absolute_import from __future__ import print_function import io from glob import glob from os.path import basename from os.path import dirname from os.path import join from os.path import splitext import re import sys from setuptools import find_packages from setuptools import setup version = '1.0.0' #### Small hack to force using a plain version number if the option #### --plain-version is passed to setup.py USE_DEFAULT_VERSION = False try: sys.argv.remove('--use-default-version') USE_DEFAULT_VERSION = True except ValueError: pass #### _sys_v0 = sys.version_info[0] py2 = _sys_v0 == 2 py3 = _sys_v0 == 3 def get_version(default=version, template='{tag}.{distance}.{commit}{dirty}', use_default=USE_DEFAULT_VERSION): """ Return a version collected from git if possible or fall back to an hard-coded default version otherwise. If `use_default` is True, always use the default version. """ if use_default: return default try: tag, distance, commit, dirty = get_git_version() if not distance and not dirty: # we are from a clean Git tag: use tag return tag distance = 'post{}'.format(distance) if dirty: time_stamp = get_time_stamp() dirty = '.dirty.' + get_time_stamp() else: dirty = '' return template.format(**locals()) except: # no git data: use default version return default def get_time_stamp(): """ Return a numeric UTC time stamp without microseconds. """ from datetime import datetime return (datetime.isoformat(datetime.utcnow()).split('.')[0] .replace('T', '').replace(':', '').replace('-', '')) def get_git_version(): """ Return version parts from Git or raise an exception. """ from subprocess import check_output, STDOUT # this may fail with exceptions cmd = 'git', 'describe', '--tags', '--long', '--dirty', version = check_output(cmd, stderr=STDOUT).strip() dirty = version.endswith('-dirty') tag, distance, commit = version.split('-')[:3] # lower tag and strip V prefix in tags tag = tag.lower().lstrip('v ').strip() # strip leading g from git describe commit commit = commit.lstrip('g').strip() return tag, int(distance), commit, dirty def read(*names, **kwargs): return io.open( join(dirname(__file__), *names), encoding=kwargs.get('encoding', 'utf8') ).read() # Accept Python3, but only when running setup.py. Released wheels should be for # Python 2 only until we completed the Python3 port if py2: python_requires= '>=2.7,<3' elif py3: python_requires= '>=3.6' else: raise Exception('Unsupported Python version.') setup( name='tracecode-toolkit', version=get_version(), license='Apache-2.0', description='Utility for trace sources and binaries codebase builds and transforms.', long_description=read('README.rst'), author='nexB Inc.', author_email='[email protected]', url='https://github.com/nexb/tracecode-toolkit', packages=find_packages('src'), package_dir={'': 'src'}, py_modules=[splitext(basename(path))[0] for path in glob('src/*.py')], include_package_data=True, zip_safe=False, classifiers=[ # complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: Apache Software License', 'Programming Language :: Python', 'Programming Language :: Python :: 2.7', 'Topic :: Utilities', ], keywords=[], install_requires=[ 'click', 'scancode-toolkit >= 3.0', 'unicodecsv', ], entry_points={ 'console_scripts': [ 'tracecode=tracecode.cli:cli', ], }, extras_require={ # eg: 'rst': ['docutils>=0.11'], } )