Skip to content

Commit c286aad

Browse files
gunandrose4umalfet
andauthored
Add script for generate sdist package for Windows platform in PyPI (pytorch#559)
* Add script to generate a mock torch source distributed package for Windows on PyPI * Resolve review comments * Resolve review comments * Resolve review comments * Resolve review comments * Rename bash file name to a more meaningful one * Resolve review comments * Update packaging/windows/build_pypi_pkg_download_proxy/setup.py Co-authored-by: Joe Zhu <[email protected]> Co-authored-by: Nikita Shulga <[email protected]>
1 parent a865203 commit c286aad

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
TORCH_VER=$1
5+
SETUP_FILE="setup.py"
6+
REPLACE_KEYWORD="{{GENERATE_TORCH_PKG_VER}}"
7+
8+
mkdir torch
9+
cp $SETUP_FILE torch/
10+
cd torch
11+
sed -i "s/$REPLACE_KEYWORD/$TORCH_VER/g" $SETUP_FILE
12+
python $SETUP_FILE sdist
13+
14+
echo "Generate package under torch/dist"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
author_email='[email protected]',
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

Comments
 (0)