setup.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. from __future__ import print_function
  2. import distutils.spawn
  3. import re
  4. from setuptools import find_packages
  5. from setuptools import setup
  6. import shlex
  7. import site
  8. import subprocess
  9. import sys
  10. # XXX: with pyproject.toml and without --no-use-pep517,
  11. # sitepackages are not inserted to sys.path by default.
  12. sys.path.extend(site.getsitepackages())
  13. def get_version():
  14. filename = "labelme/__init__.py"
  15. with open(filename) as f:
  16. match = re.search(
  17. r"""^__version__ = ['"]([^'"]*)['"]""", f.read(), re.M
  18. )
  19. if not match:
  20. raise RuntimeError("{} doesn't contain __version__".format(filename))
  21. version = match.groups()[0]
  22. return version
  23. def get_install_requires():
  24. PY3 = sys.version_info[0] == 3
  25. PY2 = sys.version_info[0] == 2
  26. assert PY3 or PY2
  27. install_requires = [
  28. "imgviz>=0.11.0",
  29. "matplotlib",
  30. "numpy",
  31. "Pillow>=2.8.0",
  32. "PyYAML",
  33. "qtpy",
  34. "termcolor",
  35. ]
  36. # Find python binding for qt with priority:
  37. # PyQt5 -> PySide2 -> PyQt4,
  38. # and PyQt5 is automatically installed on Python3.
  39. QT_BINDING = None
  40. try:
  41. import PyQt5 # NOQA
  42. QT_BINDING = "pyqt5"
  43. except ImportError:
  44. pass
  45. if QT_BINDING is None:
  46. try:
  47. import PySide2 # NOQA
  48. QT_BINDING = "pyside2"
  49. except ImportError:
  50. pass
  51. if QT_BINDING is None:
  52. try:
  53. import PyQt4 # NOQA
  54. QT_BINDING = "pyqt4"
  55. except ImportError:
  56. if PY2:
  57. print(
  58. "Please install PyQt5, PySide2 or PyQt4 for Python2.\n"
  59. "Note that PyQt5 can be installed via pip for Python3.",
  60. file=sys.stderr,
  61. )
  62. sys.exit(1)
  63. assert PY3
  64. # PyQt5 can be installed via pip for Python3
  65. install_requires.append("PyQt5")
  66. QT_BINDING = "pyqt5"
  67. del QT_BINDING
  68. return install_requires
  69. def get_long_description():
  70. with open("README.md") as f:
  71. long_description = f.read()
  72. try:
  73. import github2pypi
  74. return github2pypi.replace_url(
  75. slug="wkentaro/labelme", content=long_description
  76. )
  77. except Exception:
  78. return long_description
  79. def main():
  80. version = get_version()
  81. if sys.argv[1] == "release":
  82. if not distutils.spawn.find_executable("twine"):
  83. print(
  84. "Please install twine:\n\n\tpip install twine\n",
  85. file=sys.stderr,
  86. )
  87. sys.exit(1)
  88. commands = [
  89. "python tests/docs_tests/man_tests/test_labelme_1.py",
  90. "git tag v{:s}".format(version),
  91. "git push origin master --tag",
  92. "python setup.py sdist",
  93. "twine upload dist/labelme-{:s}.tar.gz".format(version),
  94. ]
  95. for cmd in commands:
  96. subprocess.check_call(shlex.split(cmd))
  97. sys.exit(0)
  98. setup(
  99. name="labelme",
  100. version=version,
  101. packages=find_packages(exclude=["github2pypi"]),
  102. description="Image Polygonal Annotation with Python",
  103. long_description=get_long_description(),
  104. long_description_content_type="text/markdown",
  105. author="Kentaro Wada",
  106. author_email="www.kentaro.wada@gmail.com",
  107. url="https://github.com/wkentaro/labelme",
  108. install_requires=get_install_requires(),
  109. license="GPLv3",
  110. keywords="Image Annotation, Machine Learning",
  111. classifiers=[
  112. "Development Status :: 5 - Production/Stable",
  113. "Intended Audience :: Developers",
  114. "Natural Language :: English",
  115. "Programming Language :: Python",
  116. "Programming Language :: Python :: 2.7",
  117. "Programming Language :: Python :: 3.5",
  118. "Programming Language :: Python :: 3.6",
  119. "Programming Language :: Python :: 3.7",
  120. "Programming Language :: Python :: Implementation :: CPython",
  121. "Programming Language :: Python :: Implementation :: PyPy",
  122. ],
  123. package_data={"labelme": ["icons/*", "config/*.yaml"]},
  124. entry_points={
  125. "console_scripts": [
  126. "labelme=labelme.__main__:main",
  127. "labelme_draw_json=labelme.cli.draw_json:main",
  128. "labelme_draw_label_png=labelme.cli.draw_label_png:main",
  129. "labelme_json_to_dataset=labelme.cli.json_to_dataset:main",
  130. "labelme_on_docker=labelme.cli.on_docker:main",
  131. ],
  132. },
  133. data_files=[("share/man/man1", ["docs/man/labelme.1"])],
  134. )
  135. if __name__ == "__main__":
  136. main()