setup.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env python
  2. from setuptools import find_packages, setup
  3. import os
  4. import subprocess
  5. import time
  6. version_file = 'realesrgan/version.py'
  7. def readme():
  8. with open('README.md', encoding='utf-8') as f:
  9. content = f.read()
  10. return content
  11. def get_git_hash():
  12. def _minimal_ext_cmd(cmd):
  13. # construct minimal environment
  14. env = {}
  15. for k in ['SYSTEMROOT', 'PATH', 'HOME']:
  16. v = os.environ.get(k)
  17. if v is not None:
  18. env[k] = v
  19. # LANGUAGE is used on win32
  20. env['LANGUAGE'] = 'C'
  21. env['LANG'] = 'C'
  22. env['LC_ALL'] = 'C'
  23. out = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env).communicate()[0]
  24. return out
  25. try:
  26. out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
  27. sha = out.strip().decode('ascii')
  28. except OSError:
  29. sha = 'unknown'
  30. return sha
  31. def get_hash():
  32. if os.path.exists('.git'):
  33. sha = get_git_hash()[:7]
  34. elif os.path.exists(version_file):
  35. try:
  36. from facexlib.version import __version__
  37. sha = __version__.split('+')[-1]
  38. except ImportError:
  39. raise ImportError('Unable to get git version')
  40. else:
  41. sha = 'unknown'
  42. return sha
  43. def write_version_py():
  44. content = """# GENERATED VERSION FILE
  45. # TIME: {}
  46. __version__ = '{}'
  47. __gitsha__ = '{}'
  48. version_info = ({})
  49. """
  50. sha = get_hash()
  51. with open('VERSION', 'r') as f:
  52. SHORT_VERSION = f.read().strip()
  53. VERSION_INFO = ', '.join([x if x.isdigit() else f'"{x}"' for x in SHORT_VERSION.split('.')])
  54. version_file_str = content.format(time.asctime(), SHORT_VERSION, sha, VERSION_INFO)
  55. with open(version_file, 'w') as f:
  56. f.write(version_file_str)
  57. def get_version():
  58. with open(version_file, 'r') as f:
  59. exec(compile(f.read(), version_file, 'exec'))
  60. return locals()['__version__']
  61. def get_requirements(filename='requirements.txt'):
  62. here = os.path.dirname(os.path.realpath(__file__))
  63. with open(os.path.join(here, filename), 'r') as f:
  64. requires = [line.replace('\n', '') for line in f.readlines()]
  65. return requires
  66. if __name__ == '__main__':
  67. write_version_py()
  68. setup(
  69. name='realesrgan',
  70. version=get_version(),
  71. description='Real-ESRGAN aims at developing Practical Algorithms for General Image Restoration',
  72. long_description=readme(),
  73. long_description_content_type='text/markdown',
  74. author='Xintao Wang',
  75. author_email='xintao.wang@outlook.com',
  76. keywords='computer vision, pytorch, image restoration, super-resolution, esrgan, real-esrgan',
  77. url='https://github.com/xinntao/Real-ESRGAN',
  78. include_package_data=True,
  79. packages=find_packages(exclude=('options', 'datasets', 'experiments', 'results', 'tb_logger', 'wandb')),
  80. classifiers=[
  81. 'Development Status :: 4 - Beta',
  82. 'License :: OSI Approved :: Apache Software License',
  83. 'Operating System :: OS Independent',
  84. 'Programming Language :: Python :: 3',
  85. 'Programming Language :: Python :: 3.7',
  86. 'Programming Language :: Python :: 3.8',
  87. ],
  88. license='BSD-3-Clause License',
  89. setup_requires=['cython', 'numpy'],
  90. install_requires=get_requirements(),
  91. zip_safe=False)