setup.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/env python
  2. import semver as package
  3. from glob import glob
  4. from os import remove
  5. from os.path import dirname, join
  6. from setuptools import setup
  7. from setuptools.command.test import test as TestCommand
  8. from shlex import split
  9. from shutil import rmtree
  10. class Tox(TestCommand):
  11. user_options = [('tox-args=', 'a', "Arguments to pass to tox")]
  12. def initialize_options(self):
  13. TestCommand.initialize_options(self)
  14. self.tox_args = None
  15. def finalize_options(self):
  16. TestCommand.finalize_options(self)
  17. self.test_args = []
  18. self.test_suite = True
  19. def run_tests(self):
  20. from tox import cmdline
  21. args = self.tox_args
  22. if args:
  23. args = split(self.tox_args)
  24. errno = cmdline(args=args)
  25. exit(errno)
  26. class Clean(TestCommand):
  27. def run(self):
  28. delete_in_root = [
  29. 'build',
  30. '.cache',
  31. 'dist',
  32. '.eggs',
  33. '*.egg-info',
  34. '.tox',
  35. ]
  36. delete_everywhere = [
  37. '__pycache__',
  38. '*.pyc',
  39. ]
  40. for candidate in delete_in_root:
  41. rmtree_glob(candidate)
  42. for visible_dir in glob('[A-Za-z0-9]*'):
  43. for candidate in delete_everywhere:
  44. rmtree_glob(join(visible_dir, candidate))
  45. rmtree_glob(join(visible_dir, '*', candidate))
  46. def rmtree_glob(file_glob):
  47. for fobj in glob(file_glob):
  48. try:
  49. rmtree(fobj)
  50. print('%s/ removed ...' % fobj)
  51. except OSError:
  52. try:
  53. remove(fobj)
  54. print('%s removed ...' % fobj)
  55. except OSError:
  56. pass
  57. def read_file(filename):
  58. with open(join(dirname(__file__), filename)) as f:
  59. return f.read()
  60. setup(
  61. name=package.__name__,
  62. version=package.__version__,
  63. description=package.__doc__.strip(),
  64. long_description=read_file('README.rst'),
  65. author=package.__author__,
  66. author_email=package.__author_email__,
  67. url='https://github.com/k-bx/python-semver',
  68. download_url='https://github.com/k-bx/python-semver/downloads',
  69. py_modules=[package.__name__],
  70. include_package_data=True,
  71. license='BSD',
  72. classifiers=[
  73. 'Environment :: Web Environment',
  74. 'Intended Audience :: Developers',
  75. 'License :: OSI Approved :: BSD License',
  76. 'Operating System :: OS Independent',
  77. 'Programming Language :: Python',
  78. 'Programming Language :: Python :: 2',
  79. 'Programming Language :: Python :: 2.6',
  80. 'Programming Language :: Python :: 2.7',
  81. 'Programming Language :: Python :: 3',
  82. 'Programming Language :: Python :: 3.2',
  83. 'Programming Language :: Python :: 3.3',
  84. 'Programming Language :: Python :: 3.4',
  85. 'Programming Language :: Python :: 3.5',
  86. 'Topic :: Software Development :: Libraries :: Python Modules',
  87. ],
  88. tests_require=['tox', 'virtualenv<14.0.0'],
  89. cmdclass={
  90. 'clean': Clean,
  91. 'test': Tox,
  92. },
  93. )