setup.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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<3.3", # for PyInstaller
  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. import github2pypi
  59. return github2pypi.replace_url(
  60. slug="wkentaro/labelme", content=long_description
  61. )
  62. except Exception:
  63. return long_description
  64. def main():
  65. version = get_version()
  66. if sys.argv[1] == "release":
  67. if not distutils.spawn.find_executable("twine"):
  68. print(
  69. "Please install twine:\n\n\tpip install twine\n",
  70. file=sys.stderr,
  71. )
  72. sys.exit(1)
  73. commands = [
  74. "git push origin main",
  75. "git tag v{:s}".format(version),
  76. "git push origin --tags",
  77. "python setup.py sdist",
  78. "twine upload dist/labelme-{:s}.tar.gz".format(version),
  79. ]
  80. for cmd in commands:
  81. print("+ {:s}".format(cmd))
  82. subprocess.check_call(shlex.split(cmd))
  83. sys.exit(0)
  84. setup(
  85. name="labelme",
  86. version=version,
  87. packages=find_packages(exclude=["github2pypi"]),
  88. description="Image Polygonal Annotation with Python",
  89. long_description=get_long_description(),
  90. long_description_content_type="text/markdown",
  91. author="Kentaro Wada",
  92. author_email="www.kentaro.wada@gmail.com",
  93. url="https://github.com/wkentaro/labelme",
  94. install_requires=get_install_requires(),
  95. license="GPLv3",
  96. keywords="Image Annotation, Machine Learning",
  97. classifiers=[
  98. "Development Status :: 5 - Production/Stable",
  99. "Intended Audience :: Developers",
  100. "Intended Audience :: Science/Research",
  101. "Natural Language :: English",
  102. "Operating System :: OS Independent",
  103. "Programming Language :: Python",
  104. "Programming Language :: Python :: 3.5",
  105. "Programming Language :: Python :: 3.6",
  106. "Programming Language :: Python :: 3.7",
  107. "Programming Language :: Python :: 3.8",
  108. "Programming Language :: Python :: 3.9",
  109. "Programming Language :: Python :: 3 :: Only",
  110. ],
  111. package_data={"labelme": ["icons/*", "config/*.yaml"]},
  112. entry_points={
  113. "console_scripts": [
  114. "labelme=labelme.__main__:main",
  115. "labelme_draw_json=labelme.cli.draw_json:main",
  116. "labelme_draw_label_png=labelme.cli.draw_label_png:main",
  117. "labelme_json_to_dataset=labelme.cli.json_to_dataset:main",
  118. "labelme_on_docker=labelme.cli.on_docker:main",
  119. ],
  120. },
  121. )
  122. if __name__ == "__main__":
  123. main()