setup.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import distutils.spawn
  2. import os
  3. import re
  4. import shlex
  5. import subprocess
  6. import sys
  7. from setuptools import find_packages
  8. from setuptools import setup
  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. install_requires = [
  21. "imgviz>=0.11",
  22. "matplotlib",
  23. "natsort>=7.1.0",
  24. "numpy",
  25. "Pillow>=2.8",
  26. "PyYAML",
  27. "qtpy!=1.11.2",
  28. "termcolor",
  29. ]
  30. # Find python binding for qt with priority:
  31. # PyQt5 -> PySide2
  32. # and PyQt5 is automatically installed on Python3.
  33. QT_BINDING = None
  34. try:
  35. import PyQt5 # NOQA
  36. QT_BINDING = "pyqt5"
  37. except ImportError:
  38. pass
  39. if QT_BINDING is None:
  40. try:
  41. import PySide2 # NOQA
  42. QT_BINDING = "pyside2"
  43. except ImportError:
  44. pass
  45. if QT_BINDING is None:
  46. # PyQt5 can be installed via pip for Python3
  47. # 5.15.3, 5.15.4 won't work with PyInstaller
  48. install_requires.append("PyQt5!=5.15.3,!=5.15.4")
  49. QT_BINDING = "pyqt5"
  50. del QT_BINDING
  51. if os.name == "nt": # Windows
  52. install_requires.append("colorama")
  53. return install_requires
  54. def get_long_description():
  55. with open("README.md") as f:
  56. long_description = f.read()
  57. try:
  58. # when this package is being released
  59. import github2pypi
  60. return github2pypi.replace_url(
  61. slug="wkentaro/labelme", content=long_description, branch="main"
  62. )
  63. except ImportError:
  64. # when this package is being installed
  65. return long_description
  66. def main():
  67. version = get_version()
  68. if sys.argv[1] == "release":
  69. try:
  70. import github2pypi # NOQA
  71. except ImportError:
  72. print(
  73. "Please install github2pypi\n\n\tpip install github2pypi\n",
  74. file=sys.stderr,
  75. )
  76. sys.exit(1)
  77. if not distutils.spawn.find_executable("twine"):
  78. print(
  79. "Please install twine:\n\n\tpip install twine\n",
  80. file=sys.stderr,
  81. )
  82. sys.exit(1)
  83. commands = [
  84. "git push origin main",
  85. "git tag v{:s}".format(version),
  86. "git push origin --tags",
  87. "python setup.py sdist",
  88. "twine upload dist/labelme-{:s}.tar.gz".format(version),
  89. ]
  90. for cmd in commands:
  91. print("+ {:s}".format(cmd))
  92. subprocess.check_call(shlex.split(cmd))
  93. sys.exit(0)
  94. setup(
  95. name="labelme",
  96. version=version,
  97. packages=find_packages(),
  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. "Intended Audience :: Science/Research",
  111. "Natural Language :: English",
  112. "Operating System :: OS Independent",
  113. "Programming Language :: Python",
  114. "Programming Language :: Python :: 3.5",
  115. "Programming Language :: Python :: 3.6",
  116. "Programming Language :: Python :: 3.7",
  117. "Programming Language :: Python :: 3.8",
  118. "Programming Language :: Python :: 3.9",
  119. "Programming Language :: Python :: 3 :: Only",
  120. ],
  121. package_data={"labelme": ["icons/*", "config/*.yaml"]},
  122. entry_points={
  123. "console_scripts": [
  124. "labelme=labelme.__main__:main",
  125. "labelme_draw_json=labelme.cli.draw_json:main",
  126. "labelme_draw_label_png=labelme.cli.draw_label_png:main",
  127. "labelme_json_to_dataset=labelme.cli.json_to_dataset:main",
  128. "labelme_on_docker=labelme.cli.on_docker:main",
  129. ],
  130. },
  131. )
  132. if __name__ == "__main__":
  133. main()