setup.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. from distutils.spawn import find_executable
  2. import os.path as osp
  3. from setuptools.command.develop import develop as DevelopCommand
  4. from setuptools.command.install import install as InstallCommand
  5. from setuptools import find_packages
  6. from setuptools import setup
  7. import shlex
  8. import subprocess
  9. import sys
  10. PY3 = sys.version_info[0] == 3
  11. PY2 = sys.version_info[0] == 2
  12. assert PY3 or PY2
  13. version = '2.11.0'
  14. install_requires = [
  15. 'matplotlib',
  16. 'numpy',
  17. 'Pillow>=2.8.0',
  18. 'PyYAML',
  19. ]
  20. try:
  21. import PyQt5 # NOQA
  22. PYQT_VERSION = 5
  23. except ImportError:
  24. try:
  25. import PyQt4 # NOQA
  26. PYQT_VERSION = 4
  27. except ImportError:
  28. if PY2:
  29. sys.stderr.write(
  30. 'Please install PyQt4 or PyQt5 for Python2.\n'
  31. 'Note that PyQt5 can be installed via pip for Python3.')
  32. sys.exit(1)
  33. assert PY3
  34. # PyQt5 can be installed via pip for Python3
  35. install_requires.append('pyqt5')
  36. PYQT_VERSION = 5
  37. if sys.argv[1] == 'release':
  38. commands = [
  39. 'git tag v{:s}'.format(version),
  40. 'git push origin master --tag',
  41. 'python setup.py sdist',
  42. 'twine upload dist/labelme-{:s}.tar.gz'.format(version),
  43. ]
  44. sys.exit(sum(subprocess.call(shlex.split(cmd)) for cmd in commands))
  45. here = osp.dirname(osp.abspath(__file__))
  46. def customize(command_subclass):
  47. orig_run = command_subclass.run
  48. def customized_run(self):
  49. pyrcc = 'pyrcc{:d}'.format(PYQT_VERSION)
  50. if find_executable(pyrcc) is None:
  51. sys.stderr.write('Please install {:s} command.\n'.format(pyrcc))
  52. sys.stderr.write('(See https://github.com/wkentaro/labelme.git)\n')
  53. sys.exit(1)
  54. package_dir = osp.join(here, 'labelme')
  55. src = 'resources.qrc'
  56. dst = 'resources.py'
  57. cmd = '{pyrcc} -o {dst} {src}'.format(pyrcc=pyrcc, src=src, dst=dst)
  58. print('+ {:s}'.format(cmd))
  59. subprocess.call(shlex.split(cmd), cwd=package_dir)
  60. orig_run(self)
  61. command_subclass.run = customized_run
  62. return command_subclass
  63. @customize
  64. class CustomDevelopCommand(DevelopCommand):
  65. pass
  66. @customize
  67. class CustomInstallCommand(InstallCommand):
  68. pass
  69. setup(
  70. name='labelme',
  71. version=version,
  72. packages=find_packages(),
  73. cmdclass={
  74. 'develop': CustomDevelopCommand,
  75. 'install': CustomInstallCommand,
  76. },
  77. description='Image Polygonal Annotation with Python.',
  78. long_description=open('README.md').read(),
  79. long_description_content_type='text/markdown',
  80. author='Kentaro Wada',
  81. author_email='www.kentaro.wada@gmail.com',
  82. url='https://github.com/wkentaro/labelme',
  83. install_requires=install_requires,
  84. license='GPLv3',
  85. keywords='Image Annotation, Machine Learning',
  86. classifiers=[
  87. 'Development Status :: 5 - Production/Stable',
  88. 'Intended Audience :: Developers',
  89. 'License :: OSI Approved :: MIT License',
  90. 'Operating System :: POSIX',
  91. 'Topic :: Internet :: WWW/HTTP',
  92. ],
  93. package_data={'labelme': ['icons/*', 'resources.qrc']},
  94. entry_points={
  95. 'console_scripts': [
  96. 'labelme=labelme.app:main',
  97. 'labelme_draw_json=labelme.cli.draw_json:main',
  98. 'labelme_json_to_dataset=labelme.cli.json_to_dataset:main',
  99. 'labelme_on_docker=labelme.cli.on_docker:main',
  100. ],
  101. },
  102. )