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.5 KiB

  1. #!/usr/bin/env python
  2. import codecs
  3. import logging
  4. import os
  5. import re
  6. import subprocess
  7. import sys
  8. import warnings
  9. from pip.req import parse_requirements
  10. from setuptools import setup, find_packages, Command
  11. from setuptools.command.test import test as TestCommand
  12. NAME = "wstools-py3"
  13. url = "https://github.com/Synerty/wstools-py3"
  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, 'wstools', '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 urllib.request 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(
  81. "Cannot release a version (%s) smaller than the PyPI current release (%s)." % (
  82. __version__, released_version))
  83. class PreRelease(Command):
  84. user_options = []
  85. def initialize_options(self):
  86. # Command.initialize_options(self)
  87. pass
  88. def finalize_options(self):
  89. # Command.finalize_options(self)
  90. pass
  91. def run(self):
  92. import json
  93. try:
  94. from urllib.request import urlopen
  95. except ImportError:
  96. from urllib.request import urlopen
  97. response = urlopen(
  98. "http://pypi.python.org/pypi/%s/json" % NAME)
  99. data = json.load(codecs.getreader("utf-8")(response))
  100. released_version = data['info']['version']
  101. if released_version >= __version__:
  102. raise RuntimeError(
  103. "Current version of the package is equal or lower than the already published ones (PyPi). Increse version to be able to pass prerelease stage.")
  104. def get_requirements(*path):
  105. req_path = os.path.join(*path)
  106. reqs = parse_requirements(req_path, session=False)
  107. return [str(ir.req) for ir in reqs]
  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. tests_require=get_requirements(base_path, 'requirements-dev.txt'),
  115. setup_requires=['setuptools'],
  116. install_requires=get_requirements(base_path, 'requirements.txt'),
  117. license='BSD',
  118. description="WSDL parsing services package for Web Services for Python. see" + url,
  119. long_description=open("README.rst").read(),
  120. maintainer="Synerty",
  121. maintainer_email="contact@synerty.com",
  122. author='Makina Corpus',
  123. author_email='python@makina-corpus.com',
  124. provides=['wstools'],
  125. url=url,
  126. bugtrack_url='%s/issues' % url,
  127. home_page=url,
  128. keywords='api wstools wdsl web',
  129. classifiers=[
  130. 'Programming Language :: Python',
  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. )