You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

172 lines
5.7 KiB

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