setup.py 4.5 KB

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