|
1 | 1 | #!/usr/bin/env python
|
2 |
| - |
| 2 | +import logging |
3 | 3 | import os
|
4 |
| -from setuptools import setup |
| 4 | +import re |
| 5 | +import sys |
| 6 | +import subprocess |
| 7 | +import warnings |
| 8 | +import codecs |
| 9 | + |
| 10 | +from setuptools import setup, find_packages, Command |
| 11 | +from setuptools.command.test import test as TestCommand |
5 | 12 |
|
| 13 | +NAME = "wstools" |
6 | 14 | url = "https://github.com/pycontribs/wstools.git"
|
7 | 15 |
|
| 16 | +# Get the version - do not use normal import because it does break coverage |
| 17 | +base_path = os.path.dirname(__file__) |
| 18 | +fp = open(os.path.join(base_path, NAME, 'version.py')) |
| 19 | +__version__ = re.compile(r".*__version__\s*=\s*['\"](.*?)['\"]", |
| 20 | + re.S).match(fp.read()).group(1) |
| 21 | +fp.close() |
| 22 | + |
| 23 | +# this should help getting annoying warnings from inside distutils |
| 24 | +warnings.simplefilter('ignore', UserWarning) |
| 25 | + |
| 26 | + |
| 27 | +class PyTest(TestCommand): |
| 28 | + user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")] |
| 29 | + |
| 30 | + def initialize_options(self): |
| 31 | + TestCommand.initialize_options(self) |
| 32 | + self.pytest_args = [] |
| 33 | + |
| 34 | + FORMAT = '%(levelname)-10s %(message)s' |
| 35 | + logging.basicConfig(format=FORMAT) |
| 36 | + logging.getLogger().setLevel(logging.INFO) |
| 37 | + |
| 38 | + # if we have pytest-cache module we enable the test failures first mode |
| 39 | + try: |
| 40 | + import pytest_cache |
| 41 | + self.pytest_args.append("--ff") |
| 42 | + except ImportError: |
| 43 | + pass |
| 44 | + self.pytest_args.append("-s") |
| 45 | + |
| 46 | + if sys.stdout.isatty(): |
| 47 | + # when run manually we enable fail fast |
| 48 | + self.pytest_args.append("--maxfail=1") |
| 49 | + try: |
| 50 | + import coveralls |
| 51 | + self.pytest_args.append("--cov=%s" % NAME) |
| 52 | + self.pytest_args.extend(["--cov-report", "term"]) |
| 53 | + self.pytest_args.extend(["--cov-report", "xml"]) |
| 54 | + |
| 55 | + except ImportError: |
| 56 | + pass |
8 | 57 |
|
9 |
| -def read(*rnames): |
10 |
| - return "\n" + open( |
11 |
| - os.path.join('.', *rnames) |
12 |
| - ).read() |
| 58 | + def finalize_options(self): |
| 59 | + TestCommand.finalize_options(self) |
| 60 | + self.test_args = [] |
| 61 | + self.test_suite = True |
13 | 62 |
|
14 |
| -long_description = \ |
15 |
| - "WSDL parsing services package for Web Services for Python. see" + url |
| 63 | + def run_tests(self): |
| 64 | + # before running tests we need to run autopep8 |
| 65 | + try: |
| 66 | + r = subprocess.check_call( |
| 67 | + "python -m autopep8 -r --in-place wstools/ tests/", |
| 68 | + shell=True) |
| 69 | + except subprocess.CalledProcessError: |
| 70 | + logging.getLogger().warn('autopep8 is not installed so ' |
| 71 | + 'it will not be run') |
| 72 | + # import here, cause outside the eggs aren't loaded |
| 73 | + import pytest |
| 74 | + errno = pytest.main(self.pytest_args) |
| 75 | + sys.exit(errno) |
16 | 76 |
|
17 |
| -from wstools.version import __version__ |
18 | 77 |
|
19 |
| -install_requires = [ |
20 |
| - 'docutils' |
21 |
| -] |
| 78 | +class Release(Command): |
| 79 | + user_options = [] |
| 80 | + |
| 81 | + def initialize_options(self): |
| 82 | + # Command.initialize_options(self) |
| 83 | + pass |
| 84 | + |
| 85 | + def finalize_options(self): |
| 86 | + # Command.finalize_options(self) |
| 87 | + pass |
| 88 | + |
| 89 | + def run(self): |
| 90 | + import json |
| 91 | + try: |
| 92 | + from urllib.request import urlopen |
| 93 | + except ImportError: |
| 94 | + from urllib2 import urlopen |
| 95 | + response = urlopen( |
| 96 | + "http://pypi.python.org/pypi/%s/json" % NAME) |
| 97 | + data = json.load(codecs.getreader("utf-8")(response)) |
| 98 | + released_version = data['info']['version'] |
| 99 | + if released_version == __version__: |
| 100 | + raise RuntimeError( |
| 101 | + "This version was already released, remove it from PyPi if you want to release it again or increase the version number. http://pypi.python.org/pypi/%s/" % NAME) |
| 102 | + elif released_version > __version__: |
| 103 | + raise RuntimeError("Cannot release a version (%s) smaller than the PyPI current release (%s)." % ( |
| 104 | + __version__, released_version)) |
| 105 | + |
| 106 | + |
| 107 | +class PreRelease(Command): |
| 108 | + user_options = [] |
| 109 | + |
| 110 | + def initialize_options(self): |
| 111 | + # Command.initialize_options(self) |
| 112 | + pass |
| 113 | + |
| 114 | + def finalize_options(self): |
| 115 | + # Command.finalize_options(self) |
| 116 | + pass |
| 117 | + |
| 118 | + def run(self): |
| 119 | + import json |
| 120 | + try: |
| 121 | + from urllib.request import urlopen |
| 122 | + except ImportError: |
| 123 | + from urllib2 import urlopen |
| 124 | + response = urlopen( |
| 125 | + "http://pypi.python.org/pypi/%s/json" % NAME) |
| 126 | + data = json.load(codecs.getreader("utf-8")(response)) |
| 127 | + released_version = data['info']['version'] |
| 128 | + if released_version >= __version__: |
| 129 | + raise RuntimeError( |
| 130 | + "Current version of the package is equal or lower than the already published ones (PyPi). Increse version to be able to pass prerelease stage.") |
| 131 | + |
22 | 132 |
|
23 | 133 | setup(
|
24 |
| - name="wstools", |
| 134 | + name=NAME, |
25 | 135 | version=__version__,
|
26 |
| - description="wstools", |
27 |
| - maintainer="Gregory Warnes, kiorky, sorin", |
28 |
| - maintainer_email="[email protected], " |
29 |
| - |
30 |
| - url=url, |
31 |
| - long_description=long_description, |
32 |
| - packages=['wstools'], |
33 |
| - install_requires=install_requires, |
| 136 | + cmdclass={'test': PyTest, 'release': Release, 'prerelease': PreRelease}, |
| 137 | + packages=find_packages(exclude=['tests']), |
| 138 | + include_package_data=True, |
| 139 | + install_requires=['docutils','six'], |
| 140 | + |
| 141 | + license='BSD', |
| 142 | + description="WSDL parsing services package for Web Services for Python. see" + url, |
| 143 | + long_description=open("README.rst").read(), |
| 144 | + maintainer="Sorin Sbarnea", |
| 145 | + maintainer_email="[email protected]", |
| 146 | + author='Makina Corpus', |
| 147 | + |
| 148 | + provides=[NAME], |
| 149 | + url='https://github.com/pycontribs/wstools', |
| 150 | + bugtrack_url='https://github.com/pycontribs/wstools/issues', |
| 151 | + home_page='https://github.com/pycontribs/wstools', |
| 152 | + keywords='api wstools wdsl web', |
| 153 | + classifiers=[ |
| 154 | + 'Programming Language :: Python', |
| 155 | + 'Programming Language :: Python :: 2.5', |
| 156 | + 'Programming Language :: Python :: 2.6', |
| 157 | + 'Programming Language :: Python :: 2.7', |
| 158 | + 'Programming Language :: Python :: 3', |
| 159 | + 'Development Status :: 4 - Beta', |
| 160 | + 'Environment :: Other Environment', |
| 161 | + 'Intended Audience :: Developers', |
| 162 | + 'License :: OSI Approved :: BSD License', |
| 163 | + 'Operating System :: OS Independent', |
| 164 | + 'Topic :: Software Development :: Libraries :: Python Modules', |
| 165 | + 'Programming Language :: Python :: 2.6', |
| 166 | + 'Programming Language :: Python :: 2.7', |
| 167 | + 'Programming Language :: Python :: 3.3', |
| 168 | + 'Programming Language :: Python :: 3.4', |
| 169 | + 'Topic :: Internet :: WWW/HTTP', |
| 170 | + ], |
34 | 171 | )
|
0 commit comments