setup.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. "numpy",
  28. "Pillow>=2.8",
  29. "PyYAML",
  30. "qtpy!=1.11.2",
  31. "termcolor",
  32. ]
  33. # Find python binding for qt with priority:
  34. # PyQt5 -> PySide2
  35. # and PyQt5 is automatically installed on Python3.
  36. QT_BINDING = None
  37. try:
  38. import PyQt5 # NOQA
  39. QT_BINDING = "pyqt5"
  40. except ImportError:
  41. pass
  42. if QT_BINDING is None:
  43. try:
  44. import PySide2 # NOQA
  45. QT_BINDING = "pyside2"
  46. except ImportError:
  47. pass
  48. if QT_BINDING is None:
  49. # PyQt5 can be installed via pip for Python3
  50. # 5.15.3, 5.15.4 won't work with PyInstaller
  51. install_requires.append("PyQt5!=5.15.3,!=5.15.4")
  52. QT_BINDING = "pyqt5"
  53. del QT_BINDING
  54. if os.name == "nt": # Windows
  55. install_requires.append("colorama")
  56. return install_requires
  57. def get_long_description():
  58. with open("README.md") as f:
  59. long_description = f.read()
  60. try:
  61. import github2pypi
  62. return github2pypi.replace_url(
  63. slug="wkentaro/labelme", content=long_description
  64. )
  65. except Exception:
  66. return long_description
  67. def main():
  68. version = get_version()
  69. if sys.argv[1] == "release":
  70. if not distutils.spawn.find_executable("twine"):
  71. print(
  72. "Please install twine:\n\n\tpip install twine\n",
  73. file=sys.stderr,
  74. )
  75. sys.exit(1)
  76. commands = [
  77. "python tests/docs_tests/man_tests/test_labelme_1.py",
  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. data_files=[("share/man/man1", ["docs/man/labelme.1"])],
  126. )
  127. if __name__ == "__main__":
  128. main()