Skip to content

Commit

Permalink
Prevent elpy-config from hanging when we can't connect to pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
galaunay committed Mar 22, 2020
1 parent 782e93d commit 1454956
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions elpy.el
Original file line number Diff line number Diff line change
Expand Up @@ -598,21 +598,31 @@ virtualenv.

(defvar elpy-config--get-config "import json
import sys
from distutils.version import LooseVersion
import warnings
warnings.filterwarnings('ignore', category=FutureWarning)
try:
import urllib2 as urllib
except ImportError:
import urllib.request as urllib
from distutils.version import LooseVersion
# Check if we can connect to pypi quickly enough
try:
response = urllib.urlopen('https://pypi.org/pypi/numpy/json',
timeout=1)
CAN_CONNECT = True
except:
CAN_CONNECT = False
def latest(package, version=None):
if not CAN_CONNECT:
return None
try:
response = urllib.urlopen('https://pypi.org/pypi/{package}/json'.format(package=package)).read()
response = urllib.urlopen('https://pypi.org/pypi/{package}/json'.format(package=package),
timeout=2).read()
latest = json.loads(response)['info']['version']
if version is None or LooseVersion(version) < LooseVersion(latest):
return latest
Expand Down

0 comments on commit 1454956

Please sign in to comment.