|
| 1 | +import sys |
| 2 | +import subprocess |
| 3 | + |
| 4 | +import setuptools.command.install |
| 5 | +from setuptools import find_packages, setup |
| 6 | +import wheel.bdist_wheel |
| 7 | + |
| 8 | +pkg_name = "torch" |
| 9 | +pkg_ver = "{{GENERATE_TORCH_PKG_VER}}" |
| 10 | +torch_download_url = "https://download.pytorch.org/whl/torch_stable.html" |
| 11 | + |
| 12 | +python_min_version = (3, 6, 1) |
| 13 | +python_min_version_str = '.'.join((str(num) for num in python_min_version)) |
| 14 | + |
| 15 | +install_requires = [ |
| 16 | + 'pip', |
| 17 | +] |
| 18 | + |
| 19 | +class install_torch(setuptools.command.install.install): |
| 20 | + def run(self): |
| 21 | + if sys.platform == 'win32' and sys.maxsize.bit_length() == 31: |
| 22 | + raise UserWarning("We don't support Python x86." \ |
| 23 | + "Please install Python x64 instead.") |
| 24 | + |
| 25 | + raise UserWarning( |
| 26 | + f"Can not download torch binary from {torch_download_url}." \ |
| 27 | + f"Please visit {torch_download_url} for more details." |
| 28 | + ) |
| 29 | + |
| 30 | +class bdist_wheel(wheel.bdist_wheel.bdist_wheel): |
| 31 | + def run(self): |
| 32 | + if sys.platform == 'win32' and sys.maxsize.bit_length() != 31: |
| 33 | + subprocess.check_call( |
| 34 | + [sys.executable, '-m', 'pip', 'download', |
| 35 | + f'{pkg_name}==={pkg_ver}', '-f', torch_download_url, |
| 36 | + '--platform', 'win_amd64', '--only-binary=:all:', |
| 37 | + '--no-deps', '-d', self.dist_dir]) |
| 38 | + else: |
| 39 | + raise UserWarning("Cannot find a binary package of PyTorch for your Python environment.") |
| 40 | + |
| 41 | +setup( |
| 42 | + name=pkg_name, |
| 43 | + version=pkg_ver, |
| 44 | + description=("Tensors and Dynamic neural networks in " |
| 45 | + "Python with strong GPU acceleration"), |
| 46 | + cmdclass={ |
| 47 | + 'bdist_wheel': bdist_wheel, |
| 48 | + 'install': install_torch, |
| 49 | + }, |
| 50 | + packages=find_packages(), |
| 51 | + url='https://pytorch.org/', |
| 52 | + download_url='https://github.com/pytorch/pytorch/tags', |
| 53 | + author='PyTorch Team', |
| 54 | + |
| 55 | + python_requires='>={}'.format(python_min_version_str), |
| 56 | + install_requires=install_requires, |
| 57 | + # PyPI package information. |
| 58 | + classifiers=[ |
| 59 | + 'Development Status :: 5 - Production/Stable', |
| 60 | + 'Intended Audience :: Developers', |
| 61 | + 'Intended Audience :: Education', |
| 62 | + 'Intended Audience :: Science/Research', |
| 63 | + 'License :: OSI Approved :: BSD License', |
| 64 | + 'Topic :: Scientific/Engineering', |
| 65 | + 'Topic :: Scientific/Engineering :: Mathematics', |
| 66 | + 'Topic :: Scientific/Engineering :: Artificial Intelligence', |
| 67 | + 'Topic :: Software Development', |
| 68 | + 'Topic :: Software Development :: Libraries', |
| 69 | + 'Topic :: Software Development :: Libraries :: Python Modules', |
| 70 | + 'Programming Language :: C++', |
| 71 | + 'Programming Language :: Python :: 3', |
| 72 | + ], |
| 73 | + license='BSD-3', |
| 74 | + keywords='pytorch machine learning', |
| 75 | +) |
0 commit comments