setup.py 3.2 KB

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