setup.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2014-2017 Peter Bittner <django@bittner.it>
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. from os.path import abspath, dirname, join
  17. from setuptools import setup, find_packages
  18. from setuptools.command.test import test as TestCommand # noqa: disable=N812
  19. import organice as package
  20. import sys
  21. CLASSIFIERS = [
  22. 'Development Status :: 3 - Alpha',
  23. 'Environment :: Web Environment',
  24. 'Framework :: Django',
  25. 'Intended Audience :: Developers',
  26. 'License :: OSI Approved :: Apache Software License',
  27. 'Operating System :: OS Independent',
  28. 'Programming Language :: Python',
  29. 'Programming Language :: Python :: 2',
  30. 'Programming Language :: Python :: 2.7',
  31. 'Programming Language :: Python :: 3',
  32. 'Programming Language :: Python :: 3.4',
  33. 'Programming Language :: Python :: 3.5',
  34. 'Programming Language :: Python :: 3.6',
  35. 'Topic :: Office/Business :: Groupware',
  36. ]
  37. class PyTest(TestCommand):
  38. user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
  39. def initialize_options(self):
  40. TestCommand.initialize_options(self)
  41. self.pytest_args = []
  42. def finalize_options(self):
  43. TestCommand.finalize_options(self)
  44. self.test_args = []
  45. self.test_suite = True
  46. def run_tests(self):
  47. import pytest
  48. errno = pytest.main(self.pytest_args)
  49. sys.exit(errno)
  50. def read_file(*pathname):
  51. """Read the contents of a file located relative to setup.py"""
  52. with open(join(abspath(dirname(__file__)), *pathname)) as thefile:
  53. return thefile.read()
  54. def replace_last(s, old, new, maxtimes=1):
  55. """Replace the last (n) occurence(s) of an expression in a string"""
  56. tokens = s.rsplit(old, maxtimes)
  57. return new.join(tokens)
  58. # Parse requirements.txt for both package (PyPI) and source (VCS) dependencies
  59. DEPENDENCY_LINKS = []
  60. INSTALL_REQUIRES = [line for line in read_file('requirements.txt').splitlines()
  61. if line and not line.strip().startswith('#')]
  62. for index, line in enumerate(INSTALL_REQUIRES):
  63. if '#egg=' in line:
  64. DEPENDENCY_LINKS += [line]
  65. pkg_name_version = replace_last(line.split('#egg=')[1], '-', '==')
  66. INSTALL_REQUIRES[index] = pkg_name_version
  67. setup(
  68. name='django-organice',
  69. version=package.__version__,
  70. author=package.__author__,
  71. author_email=package.__author_email__,
  72. maintainer=package.__maintainer__,
  73. maintainer_email=package.__maintainer_email__,
  74. url=package.__url__,
  75. license=package.__license__,
  76. description=package.__doc__.strip(),
  77. long_description='\n'.join([
  78. read_file('README.rst'),
  79. read_file('CHANGELOG.rst')
  80. ]),
  81. keywords='cms collaboration blog newsletter django python',
  82. classifiers=CLASSIFIERS,
  83. dependency_links=DEPENDENCY_LINKS,
  84. install_requires=INSTALL_REQUIRES,
  85. packages=find_packages(exclude=['docs', 'tests']),
  86. include_package_data=True,
  87. zip_safe=False,
  88. tests_require=['pytest'],
  89. cmdclass={'test': PyTest},
  90. entry_points={
  91. 'console_scripts': [
  92. 'organice-setup = organice.bin.organice_setup:startproject',
  93. ],
  94. },
  95. )