setup.py 4.5 KB

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