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
  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
  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. r = 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
  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 again or increase the version number. http://pypi.python.org/pypi/%s/" % NAME)
  84. elif released_version > __version__:
  85. raise RuntimeError("Cannot release a version (%s) smaller than the PyPI current release (%s)." % (
  86. __version__, released_version))
  87. class PreRelease(Command):
  88. user_options = []
  89. def initialize_options(self):
  90. # Command.initialize_options(self)
  91. pass
  92. def finalize_options(self):
  93. # Command.finalize_options(self)
  94. pass
  95. def run(self):
  96. import json
  97. try:
  98. from urllib.request import urlopen
  99. except ImportError:
  100. from urllib2 import urlopen
  101. response = urlopen(
  102. "http://pypi.python.org/pypi/%s/json" % NAME)
  103. data = json.load(codecs.getreader("utf-8")(response))
  104. released_version = data['info']['version']
  105. if released_version >= __version__:
  106. raise RuntimeError(
  107. "Current version of the package is equal or lower than the already published ones (PyPi). Increse version to be able to pass prerelease stage.")
  108. setup(
  109. name=NAME,
  110. version=__version__,
  111. cmdclass={'test': PyTest, 'release': Release, 'prerelease': PreRelease},
  112. packages=find_packages(exclude=['tests']),
  113. include_package_data=True,
  114. install_requires=['docutils','six'],
  115. license='BSD',
  116. description="WSDL parsing services package for Web Services for Python. see" + url,
  117. long_description=open("README.rst").read(),
  118. maintainer="Sorin Sbarnea",
  119. maintainer_email="sorin.sbarnea@gmail.com",
  120. author='Makina Corpus',
  121. author_email='python@makina-corpus.com',
  122. provides=[NAME],
  123. url='https://github.com/pycontribs/wstools',
  124. bugtrack_url='https://github.com/pycontribs/wstools/issues',
  125. home_page='https://github.com/pycontribs/wstools',
  126. keywords='api wstools wdsl web',
  127. classifiers=[
  128. 'Programming Language :: Python',
  129. 'Programming Language :: Python :: 2.5',
  130. 'Programming Language :: Python :: 2.6',
  131. 'Programming Language :: Python :: 2.7',
  132. 'Programming Language :: Python :: 3',
  133. 'Development Status :: 4 - Beta',
  134. 'Environment :: Other Environment',
  135. 'Intended Audience :: Developers',
  136. 'License :: OSI Approved :: BSD License',
  137. 'Operating System :: OS Independent',
  138. 'Topic :: Software Development :: Libraries :: Python Modules',
  139. 'Programming Language :: Python :: 2.6',
  140. 'Programming Language :: Python :: 2.7',
  141. 'Programming Language :: Python :: 3.3',
  142. 'Programming Language :: Python :: 3.4',
  143. 'Topic :: Internet :: WWW/HTTP',
  144. ],
  145. )