setup.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/usr/bin/env python
  2. # Copyright (c) EasyFL. All rights reserved.
  3. from setuptools import find_packages, setup
  4. VERSION_FILE = 'easyfl/version.py'
  5. def readme():
  6. with open('README.md', encoding='utf-8') as f:
  7. content = f.read()
  8. return content
  9. def get_version():
  10. with open(VERSION_FILE, 'r') as f:
  11. exec(compile(f.read(), VERSION_FILE, 'exec'))
  12. return locals()['__version__']
  13. def parse_requirements(fname='requirements.txt', with_version=True):
  14. """Parse the package dependencies listed in a requirements file but strips
  15. specific versioning information.
  16. Args:
  17. fname (str): path to requirements file
  18. with_version (bool, default=False): if True include version specs
  19. Returns:
  20. List[str]: list of requirements items
  21. CommandLine:
  22. python -c "import setup; print(setup.parse_requirements())"
  23. """
  24. import re
  25. import sys
  26. from os.path import exists
  27. require_fpath = fname
  28. def parse_line(line):
  29. """Parse information from a line in a requirements text file."""
  30. if line.startswith('-r '):
  31. # Allow specifying requirements in other files
  32. target = line.split(' ')[1]
  33. for info in parse_require_file(target):
  34. yield info
  35. else:
  36. info = {'line': line}
  37. if line.startswith('-e '):
  38. info['package'] = line.split('#egg=')[1]
  39. elif '@git+' in line:
  40. info['package'] = line
  41. else:
  42. # Remove versioning from the package
  43. pat = '(' + '|'.join(['>=', '==', '>']) + ')'
  44. parts = re.split(pat, line, maxsplit=1)
  45. parts = [p.strip() for p in parts]
  46. info['package'] = parts[0]
  47. if len(parts) > 1:
  48. op, rest = parts[1:]
  49. if ';' in rest:
  50. # Handle platform specific dependencies
  51. # http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-platform-specific-dependencies
  52. version, platform_deps = map(str.strip,
  53. rest.split(';'))
  54. info['platform_deps'] = platform_deps
  55. else:
  56. version = rest # NOQA
  57. info['version'] = (op, version)
  58. yield info
  59. def parse_require_file(fpath):
  60. with open(fpath, 'r') as f:
  61. for line in f.readlines():
  62. line = line.strip()
  63. if line and not line.startswith('#'):
  64. for info in parse_line(line):
  65. yield info
  66. def gen_packages_items():
  67. if exists(require_fpath):
  68. for info in parse_require_file(require_fpath):
  69. parts = [info['package']]
  70. if with_version and 'version' in info:
  71. parts.extend(info['version'])
  72. if not sys.version.startswith('3.4'):
  73. # apparently package_deps are broken in 3.4
  74. platform_deps = info.get('platform_deps')
  75. if platform_deps is not None:
  76. parts.append(';' + platform_deps)
  77. item = ''.join(parts)
  78. yield item
  79. packages = list(gen_packages_items())
  80. return packages
  81. if __name__ == '__main__':
  82. setup(
  83. name='easyfl',
  84. version=get_version(),
  85. description='A low-code federated learning platform for dummies',
  86. long_description=readme(),
  87. long_description_content_type='text/markdown',
  88. author='EasyFL Contributors',
  89. author_email='easyfl.ai@gmail.com',
  90. keywords=['federated learning', 'machine learning', 'distributed machine learning', 'computer vision'],
  91. url='https://github.com/EasyFL-AI/EasyFL',
  92. download_url='https://github.com/EasyFL-AI/EasyFL/archive/refs/tags/v0.1.0.tar.gz',
  93. packages=find_packages(),
  94. data_files=[('requirements', ['requirements/runtime.txt']), ('easyfl', ['easyfl/config.yaml'])],
  95. include_package_data=True,
  96. classifiers=[
  97. 'Development Status :: 3 - Alpha',
  98. # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
  99. 'License :: OSI Approved :: Apache Software License',
  100. 'Topic :: Software Development :: Build Tools',
  101. 'Operating System :: OS Independent',
  102. 'Programming Language :: Python :: 3',
  103. 'Programming Language :: Python :: 3.6',
  104. 'Programming Language :: Python :: 3.7',
  105. 'Programming Language :: Python :: 3.8',
  106. 'Programming Language :: Python :: 3.9',
  107. ],
  108. license='Apache License 2.0',
  109. install_requires=parse_requirements('requirements/runtime.txt'),
  110. extras_require={
  111. 'all': parse_requirements('requirements.txt'),
  112. },
  113. ext_modules=[],
  114. zip_safe=False)