3
0

setup.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import re
  2. from setuptools import find_packages, setup # type: ignore
  3. def readme():
  4. with open('README.md', encoding='utf-8') as f:
  5. content = f.read()
  6. return content
  7. def get_version():
  8. version_file = 'mim/version.py'
  9. with open(version_file) as f:
  10. exec(compile(f.read(), version_file, 'exec'))
  11. return locals()['__version__']
  12. def parse_requirements(fname='requirements/runtime.txt', with_version=True):
  13. """Parse the package dependencies listed in a requirements file but strips
  14. specific versioning information.
  15. Args:
  16. fname (str): path to requirements file
  17. with_version (bool, default=False): if True include version specs
  18. Returns:
  19. List[str]: list of requirements items
  20. CommandLine:
  21. python -c "import setup; print(setup.parse_requirements())"
  22. """
  23. import sys
  24. from os.path import exists
  25. require_fpath = fname
  26. def parse_line(line):
  27. """Parse information from a line in a requirements text file."""
  28. if line.startswith('-r '):
  29. # Allow specifying requirements in other files
  30. target = line.split(' ')[1]
  31. for info in parse_require_file(target):
  32. yield info
  33. else:
  34. info = {'line': line}
  35. if line.startswith('-e '):
  36. info['package'] = line.split('#egg=')[1]
  37. else:
  38. # Remove versioning from the package
  39. pat = '(' + '|'.join(['>=', '==', '>']) + ')'
  40. parts = re.split(pat, line, maxsplit=1)
  41. parts = [p.strip() for p in parts]
  42. info['package'] = parts[0]
  43. if len(parts) > 1:
  44. op, rest = parts[1:]
  45. if ';' in rest:
  46. # Handle platform specific dependencies
  47. # http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-platform-specific-dependencies
  48. version, platform_deps = map(str.strip,
  49. rest.split(';'))
  50. info['platform_deps'] = platform_deps
  51. else:
  52. version = rest # NOQA
  53. info['version'] = (op, version)
  54. yield info
  55. def parse_require_file(fpath):
  56. with open(fpath) as f:
  57. for line in f.readlines():
  58. line = line.strip()
  59. if line and not line.startswith('#'):
  60. yield from parse_line(line)
  61. def gen_packages_items():
  62. if exists(require_fpath):
  63. for info in parse_require_file(require_fpath):
  64. parts = [info['package']]
  65. if with_version and 'version' in info:
  66. parts.extend(info['version'])
  67. if not sys.version.startswith('3.4'):
  68. # apparently package_deps are broken in 3.4
  69. platform_deps = info.get('platform_deps')
  70. if platform_deps is not None:
  71. parts.append(';' + platform_deps)
  72. item = ''.join(parts)
  73. yield item
  74. packages = list(gen_packages_items())
  75. return packages
  76. setup(
  77. name='openmim',
  78. version=get_version(),
  79. description='MIM Installs OpenMMLab packages',
  80. long_description=readme(),
  81. long_description_content_type='text/markdown',
  82. url='https://github.com/open-mmlab/mim',
  83. author='MIM Authors',
  84. author_email='openmmlab@gmail.com',
  85. packages=find_packages(),
  86. include_package_data=True,
  87. python_requires='>=3.6',
  88. install_requires=parse_requirements('requirements/install.txt'),
  89. extras_require={
  90. 'all': parse_requirements('requirements.txt'),
  91. 'tests': parse_requirements('requirements/tests.txt'),
  92. },
  93. entry_points='''
  94. [console_scripts]
  95. mim=mim.cli:cli
  96. ''',
  97. )