setup.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.10.4'
  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',
  41. 'twine upload dist/labelme-{:s}.tar.gz'.format(version),
  42. ]
  43. sys.exit(sum(subprocess.call(shlex.split(cmd)) for cmd in commands))
  44. here = osp.dirname(osp.abspath(__file__))
  45. def customize(command_subclass):
  46. orig_run = command_subclass.run
  47. def customized_run(self):
  48. pyrcc = 'pyrcc{:d}'.format(PYQT_VERSION)
  49. if find_executable(pyrcc) is None:
  50. sys.stderr.write('Please install {:s} command.\n'.format(pyrcc))
  51. sys.stderr.write('(See https://github.com/wkentaro/labelme.git)\n')
  52. sys.exit(1)
  53. package_dir = osp.join(here, 'labelme')
  54. src = 'resources.qrc'
  55. dst = 'resources.py'
  56. cmd = '{pyrcc} -o {dst} {src}'.format(pyrcc=pyrcc, src=src, dst=dst)
  57. print('+ {:s}'.format(cmd))
  58. subprocess.call(shlex.split(cmd), cwd=package_dir)
  59. orig_run(self)
  60. command_subclass.run = customized_run
  61. return command_subclass
  62. @customize
  63. class CustomDevelopCommand(DevelopCommand):
  64. pass
  65. @customize
  66. class CustomInstallCommand(InstallCommand):
  67. pass
  68. setup(
  69. name='labelme',
  70. version=version,
  71. packages=find_packages(),
  72. cmdclass={
  73. 'develop': CustomDevelopCommand,
  74. 'install': CustomInstallCommand,
  75. },
  76. description='Image Polygonal Annotation with Python.',
  77. long_description=open('README.md').read(),
  78. long_description_content_type='text/markdown',
  79. author='Kentaro Wada',
  80. author_email='www.kentaro.wada@gmail.com',
  81. url='https://github.com/wkentaro/labelme',
  82. install_requires=install_requires,
  83. license='GPLv3',
  84. keywords='Image Annotation, Machine Learning',
  85. classifiers=[
  86. 'Development Status :: 5 - Production/Stable',
  87. 'Intended Audience :: Developers',
  88. 'License :: OSI Approved :: MIT License',
  89. 'Operating System :: POSIX',
  90. 'Topic :: Internet :: WWW/HTTP',
  91. ],
  92. package_data={'labelme': ['icons/*', 'resources.qrc']},
  93. entry_points={
  94. 'console_scripts': [
  95. 'labelme=labelme.app:main',
  96. 'labelme_draw_json=labelme.cli.draw_json:main',
  97. 'labelme_json_to_dataset=labelme.cli.json_to_dataset:main',
  98. 'labelme_on_docker=labelme.cli.on_docker:main',
  99. ],
  100. },
  101. )