Skip to content

Commit 91c50b3

Browse files
phmccartybryteise
authored andcommitted
Avoid using a keyring when calling pip
Instruct pip to not use a keyring by setting an environment variable (PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring). As far as I know, there is no need to use a keyring for any of the pip commands autospec runs. Some users have encountered timeouts similar to the report from pypa/pip#7883, which describes this environment variable setting as a workaround. Signed-off-by: Patrick McCarty <[email protected]>
1 parent 4f90794 commit 91c50b3

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

autospec/pypidata.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
#!/usr/bin/env python3
22

33
import json
4+
import os
45
import subprocess
56
import sys
67
import tempfile
78

89

10+
def pip_env():
11+
"""Generate a copy of os.environ appropriate for pip."""
12+
env = os.environ.copy()
13+
env["PYTHON_KEYRING_BACKEND"] = "keyring.backends.null.Keyring"
14+
return env
15+
16+
917
def pip_search(name):
1018
"""Run a pip search for name and return True if found."""
1119
with tempfile.TemporaryFile() as tfile:
1220
proc = subprocess.run(["pip", "search", name], stdout=tfile.fileno(),
13-
stderr=subprocess.DEVNULL)
21+
stderr=subprocess.DEVNULL, env=pip_env())
1422
if proc.returncode:
1523
return False
1624
tfile.seek(0)
@@ -48,13 +56,15 @@ def get_pypi_metadata(name):
4856
if proc.returncode != 0:
4957
return ""
5058
proc = subprocess.run(f"source bin/activate && pip install {name}", cwd=tdir, shell=True,
51-
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
59+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
60+
env=pip_env())
5261
if proc.returncode != 0:
5362
return ""
5463
with tempfile.TemporaryFile() as tfile:
5564
proc = subprocess.run(f"source bin/activate &> /dev/null && pip show {name}",
5665
cwd=tdir, shell=True,
57-
stdout=tfile.fileno(), stderr=subprocess.DEVNULL)
66+
stdout=tfile.fileno(), stderr=subprocess.DEVNULL,
67+
env=pip_env())
5868
if proc.returncode != 0:
5969
return ""
6070
tfile.seek(0)

0 commit comments

Comments
 (0)