Skip to content

Commit 079cd4e

Browse files
Ailing Zhangfacebook-github-bot
authored andcommitted
Remove requests as dependency (#26083)
Summary: local build is slow... test in CI... Pull Request resolved: #26083 Differential Revision: D17346949 Pulled By: ailzhang fbshipit-source-id: f552d1a4be55ad4e2bd915af7c5a2c1b6667c446
1 parent 07e7c7e commit 079cd4e

File tree

5 files changed

+10
-30
lines changed

5 files changed

+10
-30
lines changed

.jenkins/caffe2/test.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ if [[ "$BUILD_ENVIRONMENT" == *py3* ]]; then
104104
export LANG=C.UTF-8
105105
fi
106106

107-
if [[ "$BUILD_ENVIRONMENT" == *py2* ]]; then
108-
pip install --user requests
109-
fi
110-
111107
pip install --user pytest-sugar
112108
"$PYTHON" \
113109
-m pytest \

.jenkins/pytorch/test.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ if [[ "$BUILD_ENVIRONMENT" != *ppc64le* ]]; then
5656
pip_install --user mypy || true
5757
fi
5858

59-
pip_install --user requests
60-
6159
# faulthandler become built-in since 3.3
6260
if [[ ! $(python -c "import sys; print(int(sys.version_info >= (3, 3)))") == "1" ]]; then
6361
pip_install --user faulthandler

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ If you are building for NVIDIA's Jetson platforms (Jetson Nano, TX1, TX2, AGX Xa
169169

170170
Common
171171
```
172-
conda install numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing requests
172+
conda install numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing
173173
```
174174

175175
On Linux

setup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,6 @@ def check_file(f):
352352
if sys.version_info <= (2, 7):
353353
install_requires += ['future']
354354

355-
if sys.version_info[0] == 2:
356-
install_requires += ['requests']
357-
358355
missing_pydep = '''
359356
Missing build dependency: Unable to `import {importname}`.
360357
Please install it via `conda install {module}` or `pip install {module}`

torch/hub.py

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
if sys.version_info[0] == 2:
1414
from urlparse import urlparse
15-
import requests
15+
from urllib2 import urlopen # noqa f811
1616
else:
1717
from urllib.request import urlopen
1818
from urllib.parse import urlparse # noqa: F401
@@ -95,10 +95,7 @@ def _download_archive_zip(url, filename):
9595
sys.stderr.write('Downloading: \"{}\" to {}\n'.format(url, filename))
9696
# We use a different API for python2 since urllib(2) doesn't recognize the CA
9797
# certificates in older Python
98-
if sys.version_info[0] == 2:
99-
response = requests.get(url, stream=True).raw
100-
else:
101-
response = urlopen(url)
98+
response = urlopen(url)
10299
with open(filename, 'wb') as f:
103100
while True:
104101
data = response.read(READ_DATA_CHUNK)
@@ -376,22 +373,14 @@ def _download_url_to_file(url, dst, hash_prefix, progress):
376373
file_size = None
377374
# We use a different API for python2 since urllib(2) doesn't recognize the CA
378375
# certificates in older Python
379-
if sys.version_info[0] == 2:
380-
response = requests.get(url, stream=True)
381-
382-
content_length = response.headers['Content-Length']
383-
file_size = int(content_length)
384-
u = response.raw
376+
u = urlopen(url)
377+
meta = u.info()
378+
if hasattr(meta, 'getheaders'):
379+
content_length = meta.getheaders("Content-Length")
385380
else:
386-
u = urlopen(url)
387-
388-
meta = u.info()
389-
if hasattr(meta, 'getheaders'):
390-
content_length = meta.getheaders("Content-Length")
391-
else:
392-
content_length = meta.get_all("Content-Length")
393-
if content_length is not None and len(content_length) > 0:
394-
file_size = int(content_length[0])
381+
content_length = meta.get_all("Content-Length")
382+
if content_length is not None and len(content_length) > 0:
383+
file_size = int(content_length[0])
395384

396385
# We deliberately save it in a temp file and move it after
397386
# download is complete. This prevents a local working checkpoint

0 commit comments

Comments
 (0)