setup.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. from __future__ import print_function
  2. import distutils.spawn
  3. import os
  4. import re
  5. import shlex
  6. import subprocess
  7. import sys
  8. from setuptools import find_packages
  9. from setuptools import setup
  10. def get_version():
  11. filename = "labelme/__init__.py"
  12. with open(filename) as f:
  13. match = re.search(
  14. r"""^__version__ = ['"]([^'"]*)['"]""", f.read(), re.M
  15. )
  16. if not match:
  17. raise RuntimeError("{} doesn't contain __version__".format(filename))
  18. version = match.groups()[0]
  19. return version
  20. def get_install_requires():
  21. PY3 = sys.version_info[0] == 3
  22. PY2 = sys.version_info[0] == 2
  23. assert PY3 or PY2
  24. install_requires = [
  25. "imgviz>=0.11.0",
  26. "matplotlib",
  27. "numpy",
  28. "Pillow>=2.8.0",
  29. "PyYAML",
  30. "qtpy",
  31. "termcolor",
  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 os.name == "nt": # Windows
  66. install_requires.append("colorama")
  67. return install_requires
  68. def get_long_description():
  69. with open("README.md") as f:
  70. long_description = f.read()
  71. try:
  72. import github2pypi
  73. return github2pypi.replace_url(
  74. slug="wkentaro/labelme", content=long_description
  75. )
  76. except Exception:
  77. return long_description
  78. def main():
  79. version = get_version()
  80. if sys.argv[1] == "release":
  81. if not distutils.spawn.find_executable("twine"):
  82. print(
  83. "Please install twine:\n\n\tpip install twine\n",
  84. file=sys.stderr,
  85. )
  86. sys.exit(1)
  87. commands = [
  88. "python tests/docs_tests/man_tests/test_labelme_1.py",
  89. "git tag v{:s}".format(version),
  90. "git push origin master --tag",
  91. "python setup.py sdist",
  92. "twine upload dist/labelme-{:s}.tar.gz".format(version),
  93. ]
  94. for cmd in commands:
  95. subprocess.check_call(shlex.split(cmd))
  96. sys.exit(0)
  97. setup(
  98. name="labelme",
  99. version=version,
  100. packages=find_packages(exclude=["github2pypi"]),
  101. description="Image Polygonal Annotation with Python",
  102. long_description=get_long_description(),
  103. long_description_content_type="text/markdown",
  104. author="Kentaro Wada",
  105. author_email="www.kentaro.wada@gmail.com",
  106. url="https://github.com/wkentaro/labelme",
  107. install_requires=get_install_requires(),
  108. license="GPLv3",
  109. keywords="Image Annotation, Machine Learning",
  110. classifiers=[
  111. "Development Status :: 5 - Production/Stable",
  112. "Intended Audience :: Developers",
  113. "Natural Language :: English",
  114. "Programming Language :: Python",
  115. "Programming Language :: Python :: 2.7",
  116. "Programming Language :: Python :: 3.5",
  117. "Programming Language :: Python :: 3.6",
  118. "Programming Language :: Python :: 3.7",
  119. "Programming Language :: Python :: Implementation :: CPython",
  120. "Programming Language :: Python :: Implementation :: PyPy",
  121. ],
  122. package_data={"labelme": ["icons/*", "config/*.yaml"]},
  123. entry_points={
  124. "console_scripts": [
  125. "labelme=labelme.__main__:main",
  126. "labelme_draw_json=labelme.cli.draw_json:main",
  127. "labelme_draw_label_png=labelme.cli.draw_label_png:main",
  128. "labelme_json_to_dataset=labelme.cli.json_to_dataset:main",
  129. "labelme_on_docker=labelme.cli.on_docker:main",
  130. ],
  131. },
  132. data_files=[("share/man/man1", ["docs/man/labelme.1"])],
  133. )
  134. if __name__ == "__main__":
  135. main()