setup.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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",
  26. "matplotlib<3.3", # for PyInstaller
  27. "natsort>=7.1.0",
  28. "numpy",
  29. "Pillow>=2.8",
  30. "PyYAML",
  31. "qtpy!=1.11.2",
  32. "termcolor",
  33. ]
  34. # Find python binding for qt with priority:
  35. # PyQt5 -> PySide2
  36. # and PyQt5 is automatically installed on Python3.
  37. QT_BINDING = None
  38. try:
  39. import PyQt5 # NOQA
  40. QT_BINDING = "pyqt5"
  41. except ImportError:
  42. pass
  43. if QT_BINDING is None:
  44. try:
  45. import PySide2 # NOQA
  46. QT_BINDING = "pyside2"
  47. except ImportError:
  48. pass
  49. if QT_BINDING is None:
  50. # PyQt5 can be installed via pip for Python3
  51. # 5.15.3, 5.15.4 won't work with PyInstaller
  52. install_requires.append("PyQt5!=5.15.3,!=5.15.4")
  53. QT_BINDING = "pyqt5"
  54. del QT_BINDING
  55. if os.name == "nt": # Windows
  56. install_requires.append("colorama")
  57. return install_requires
  58. def get_long_description():
  59. with open("README.md") as f:
  60. long_description = f.read()
  61. try:
  62. import github2pypi
  63. return github2pypi.replace_url(
  64. slug="wkentaro/labelme", content=long_description
  65. )
  66. except Exception:
  67. return long_description
  68. def main():
  69. version = get_version()
  70. if sys.argv[1] == "release":
  71. if not distutils.spawn.find_executable("twine"):
  72. print(
  73. "Please install twine:\n\n\tpip install twine\n",
  74. file=sys.stderr,
  75. )
  76. sys.exit(1)
  77. commands = [
  78. "git push origin main",
  79. "git tag v{:s}".format(version),
  80. "git push origin --tags",
  81. "python setup.py sdist",
  82. "twine upload dist/labelme-{:s}.tar.gz".format(version),
  83. ]
  84. for cmd in commands:
  85. print("+ {:s}".format(cmd))
  86. subprocess.check_call(shlex.split(cmd))
  87. sys.exit(0)
  88. setup(
  89. name="labelme",
  90. version=version,
  91. packages=find_packages(exclude=["github2pypi"]),
  92. description="Image Polygonal Annotation with Python",
  93. long_description=get_long_description(),
  94. long_description_content_type="text/markdown",
  95. author="Kentaro Wada",
  96. author_email="www.kentaro.wada@gmail.com",
  97. url="https://github.com/wkentaro/labelme",
  98. install_requires=get_install_requires(),
  99. license="GPLv3",
  100. keywords="Image Annotation, Machine Learning",
  101. classifiers=[
  102. "Development Status :: 5 - Production/Stable",
  103. "Intended Audience :: Developers",
  104. "Intended Audience :: Science/Research",
  105. "Natural Language :: English",
  106. "Operating System :: OS Independent",
  107. "Programming Language :: Python",
  108. "Programming Language :: Python :: 3.5",
  109. "Programming Language :: Python :: 3.6",
  110. "Programming Language :: Python :: 3.7",
  111. "Programming Language :: Python :: 3.8",
  112. "Programming Language :: Python :: 3.9",
  113. "Programming Language :: Python :: 3 :: Only",
  114. ],
  115. package_data={"labelme": ["icons/*", "config/*.yaml"]},
  116. entry_points={
  117. "console_scripts": [
  118. "labelme=labelme.__main__:main",
  119. "labelme_draw_json=labelme.cli.draw_json:main",
  120. "labelme_draw_label_png=labelme.cli.draw_label_png:main",
  121. "labelme_json_to_dataset=labelme.cli.json_to_dataset:main",
  122. "labelme_on_docker=labelme.cli.on_docker:main",
  123. ],
  124. },
  125. )
  126. if __name__ == "__main__":
  127. main()