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.
 
 
 

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