setup.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. from __future__ import print_function
  2. import distutils.spawn
  3. import os.path
  4. from setuptools import find_packages
  5. from setuptools import setup
  6. import shlex
  7. import subprocess
  8. import sys
  9. PY3 = sys.version_info[0] == 3
  10. PY2 = sys.version_info[0] == 2
  11. assert PY3 or PY2
  12. here = os.path.abspath(os.path.dirname(__file__))
  13. version_file = os.path.join(here, 'labelme', '_version.py')
  14. if PY3:
  15. import importlib
  16. version = importlib.machinery.SourceFileLoader(
  17. '_version', version_file
  18. ).load_module().__version__
  19. else:
  20. assert PY2
  21. import imp
  22. version = imp.load_source('_version', version_file).__version__
  23. del here
  24. install_requires = [
  25. 'matplotlib',
  26. 'numpy',
  27. 'Pillow>=2.8.0',
  28. 'PyYAML',
  29. 'qtpy',
  30. 'termcolor',
  31. ]
  32. # Find python binding for qt with priority:
  33. # PyQt5 -> PySide2 -> PyQt4,
  34. # and PyQt5 is automatically installed on Python3.
  35. QT_BINDING = None
  36. try:
  37. import PyQt5 # NOQA
  38. QT_BINDING = 'pyqt5'
  39. except ImportError:
  40. pass
  41. if QT_BINDING is None:
  42. try:
  43. import PySide2 # NOQA
  44. QT_BINDING = 'pyside2'
  45. except ImportError:
  46. pass
  47. if QT_BINDING is None:
  48. try:
  49. import PyQt4 # NOQA
  50. QT_BINDING = 'pyqt4'
  51. except ImportError:
  52. if PY2:
  53. print(
  54. 'Please install PyQt5, PySide2 or PyQt4 for Python2.\n'
  55. 'Note that PyQt5 can be installed via pip for Python3.',
  56. file=sys.stderr,
  57. )
  58. sys.exit(1)
  59. assert PY3
  60. # PyQt5 can be installed via pip for Python3
  61. install_requires.append('PyQt5')
  62. QT_BINDING = 'pyqt5'
  63. del QT_BINDING
  64. if sys.argv[1] == 'release':
  65. if not distutils.spawn.find_executable('twine'):
  66. print(
  67. 'Please install twine:\n\n\tpip install twine\n',
  68. file=sys.stderr,
  69. )
  70. sys.exit(1)
  71. commands = [
  72. 'git tag v{:s}'.format(version),
  73. 'git push origin master --tag',
  74. 'python setup.py sdist',
  75. 'twine upload dist/labelme-{:s}.tar.gz'.format(version),
  76. ]
  77. for cmd in commands:
  78. subprocess.check_call(shlex.split(cmd))
  79. sys.exit(0)
  80. def get_long_description():
  81. with open('README.md') as f:
  82. long_description = f.read()
  83. try:
  84. import github2pypi
  85. return github2pypi.replace_url(
  86. slug='wkentaro/labelme', content=long_description
  87. )
  88. except Exception:
  89. return long_description
  90. setup(
  91. name='labelme',
  92. version=version,
  93. packages=find_packages(),
  94. description='Image Polygonal Annotation with Python',
  95. long_description=get_long_description(),
  96. long_description_content_type='text/markdown',
  97. author='Kentaro Wada',
  98. author_email='www.kentaro.wada@gmail.com',
  99. url='https://github.com/wkentaro/labelme',
  100. install_requires=install_requires,
  101. license='GPLv3',
  102. keywords='Image Annotation, Machine Learning',
  103. classifiers=[
  104. 'Development Status :: 5 - Production/Stable',
  105. 'Intended Audience :: Developers',
  106. 'Natural Language :: English',
  107. 'Programming Language :: Python',
  108. 'Programming Language :: Python :: 2',
  109. 'Programming Language :: Python :: 3',
  110. 'Programming Language :: Python :: Implementation :: CPython',
  111. 'Programming Language :: Python :: Implementation :: PyPy',
  112. ],
  113. package_data={'labelme': ['icons/*', 'config/*.yaml']},
  114. entry_points={
  115. 'console_scripts': [
  116. 'labelme=labelme.main:main',
  117. 'labelme_draw_json=labelme.cli.draw_json:main',
  118. 'labelme_draw_label_png=labelme.cli.draw_label_png:main',
  119. 'labelme_json_to_dataset=labelme.cli.json_to_dataset:main',
  120. 'labelme_on_docker=labelme.cli.on_docker:main',
  121. ],
  122. },
  123. )