setup.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. else:
  35. sha = 'unknown'
  36. return sha
  37. def write_version_py():
  38. content = """# GENERATED VERSION FILE
  39. # TIME: {}
  40. __version__ = '{}'
  41. __gitsha__ = '{}'
  42. version_info = ({})
  43. """
  44. sha = get_hash()
  45. with open('VERSION', 'r') as f:
  46. SHORT_VERSION = f.read().strip()
  47. VERSION_INFO = ', '.join([x if x.isdigit() else f'"{x}"' for x in SHORT_VERSION.split('.')])
  48. version_file_str = content.format(time.asctime(), SHORT_VERSION, sha, VERSION_INFO)
  49. with open(version_file, 'w') as f:
  50. f.write(version_file_str)
  51. def get_version():
  52. with open(version_file, 'r') as f:
  53. exec(compile(f.read(), version_file, 'exec'))
  54. return locals()['__version__']
  55. def get_requirements(filename='requirements.txt'):
  56. here = os.path.dirname(os.path.realpath(__file__))
  57. with open(os.path.join(here, filename), 'r') as f:
  58. requires = [line.replace('\n', '') for line in f.readlines()]
  59. return requires
  60. if __name__ == '__main__':
  61. write_version_py()
  62. setup(
  63. name='realesrgan',
  64. version=get_version(),
  65. description='Real-ESRGAN aims at developing Practical Algorithms for General Image Restoration',
  66. long_description=readme(),
  67. long_description_content_type='text/markdown',
  68. author='Xintao Wang',
  69. author_email='xintao.wang@outlook.com',
  70. keywords='computer vision, pytorch, image restoration, super-resolution, esrgan, real-esrgan',
  71. url='https://github.com/xinntao/Real-ESRGAN',
  72. include_package_data=True,
  73. packages=find_packages(exclude=('options', 'datasets', 'experiments', 'results', 'tb_logger', 'wandb')),
  74. classifiers=[
  75. 'Development Status :: 4 - Beta',
  76. 'License :: OSI Approved :: Apache Software License',
  77. 'Operating System :: OS Independent',
  78. 'Programming Language :: Python :: 3',
  79. 'Programming Language :: Python :: 3.7',
  80. 'Programming Language :: Python :: 3.8',
  81. ],
  82. license='BSD-3-Clause License',
  83. setup_requires=['cython', 'numpy'],
  84. install_requires=get_requirements(),
  85. zip_safe=False)