|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | -# Copyright (C) 2016 SYLEAM (<http://www.syleam.fr>) |
3 | | -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
4 | | - |
5 | | -from distutils.core import setup |
6 | | - |
7 | | -setup( |
8 | | - name='zpl2', |
9 | | - version='1.0', |
10 | | - author='Sylvain Garancher', |
11 | | - author_email='sylvain.garancher@syleam.fr', |
12 | | - py_modules=['zpl2'], |
13 | | - license='LICENSE.txt', |
14 | | - description='Python library that generates ZPL II labels', |
15 | | - long_description=open('README.txt').read(), |
16 | | -) |
| 2 | +# Copyright 2016-TODAY LasLabs Inc. |
| 3 | +# License MIT (https://opensource.org/licenses/MIT). |
| 4 | + |
| 5 | +from setuptools import Command, setup |
| 6 | +from setuptools import find_packages |
| 7 | +from unittest import TestLoader, TextTestRunner |
| 8 | + |
| 9 | +from os import environ, path |
| 10 | + |
| 11 | + |
| 12 | +PROJECT = 'python-zpl2' |
| 13 | +SHORT_DESC = 'Python library that generates ZPL II labels' |
| 14 | +README_FILE = 'README.rst' |
| 15 | + |
| 16 | +CLASSIFIERS = [ |
| 17 | + 'Development Status :: 4 - Beta', |
| 18 | + 'Environment :: Console', |
| 19 | + 'Intended Audience :: Developers', |
| 20 | + 'License :: OSI Approved :: AGPL-3 License', |
| 21 | + 'Programming Language :: Python', |
| 22 | + 'Topic :: Software Development :: Libraries :: Python Modules', |
| 23 | +] |
| 24 | + |
| 25 | +version = environ.get('RELEASE') or environ.get('VERSION') or '0.0.0' |
| 26 | + |
| 27 | +if environ.get('TRAVIS_BUILD_NUMBER'): |
| 28 | + version += 'b%s' % environ.get('TRAVIS_BUILD_NUMBER') |
| 29 | + |
| 30 | + |
| 31 | +setup_vals = { |
| 32 | + 'name': PROJECT, |
| 33 | + 'author': 'Sylvain Garancher', |
| 34 | + 'author_email': 'sylvain.garancher@syleam.fr', |
| 35 | + 'description': SHORT_DESC, |
| 36 | + 'url': 'https://laslabs.github.io/%s' % PROJECT, |
| 37 | + 'download_url': 'https://github.com/LasLabs/%s' % PROJECT, |
| 38 | + 'license': 'MIT', |
| 39 | + 'classifiers': CLASSIFIERS, |
| 40 | + 'version': version, |
| 41 | +} |
| 42 | + |
| 43 | + |
| 44 | +if path.exists(README_FILE): |
| 45 | + with open(README_FILE) as fh: |
| 46 | + setup_vals['long_description'] = fh.read() |
| 47 | + |
| 48 | + |
| 49 | +install_requires = [] |
| 50 | +if path.exists('requirements.txt'): |
| 51 | + with open('requirements.txt') as fh: |
| 52 | + install_requires = fh.read().splitlines() |
| 53 | + |
| 54 | + |
| 55 | +class FailTestException(Exception): |
| 56 | + """ It provides a failing build """ |
| 57 | + pass |
| 58 | + |
| 59 | + |
| 60 | +class Tests(Command): |
| 61 | + |
| 62 | + user_options = [] # < For Command API compatibility |
| 63 | + |
| 64 | + def initialize_options(self, ): |
| 65 | + pass |
| 66 | + |
| 67 | + def finalize_options(self, ): |
| 68 | + pass |
| 69 | + |
| 70 | + def run(self, ): |
| 71 | + loader = TestLoader() |
| 72 | + tests = loader.discover('.', 'test_*.py') |
| 73 | + t = TextTestRunner(verbosity=1) |
| 74 | + res = t.run(tests) |
| 75 | + if not res.wasSuccessful(): |
| 76 | + raise FailTestException() |
| 77 | + |
| 78 | + |
| 79 | +if __name__ == "__main__": |
| 80 | + setup( |
| 81 | + packages=find_packages(exclude=('tests')), |
| 82 | + cmdclass={'test': Tests}, |
| 83 | + tests_require=[ |
| 84 | + 'mock', |
| 85 | + ], |
| 86 | + install_requires=install_requires, |
| 87 | + **setup_vals |
| 88 | + ) |
0 commit comments