Skip to content

Commit

Permalink
Cleanup temporary folder created for cert file extracted from wheel (b…
Browse files Browse the repository at this point in the history
…azelbuild#150)

The piptool run is not properly sandboxed and the temporary folder
created during extraction of cacert.pem does not get cleaned on
exit. This leads to accumulation in /tmp and may result in out of
space errors over long a period of time.
  • Loading branch information
Kaizer Sogiawala committed Dec 27, 2018
1 parent e6399b6 commit 8e0c31d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions rules_python/piptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ def extract_packages(package_names):
def pip_main(argv):
# Extract the certificates from the PAR following the example of get-pip.py
# https://github.com/pypa/get-pip/blob/430ba37776ae2ad89/template.py#L164-L168
cert_path = os.path.join(tempfile.mkdtemp(), "cacert.pem")
cert_tmpdir = tempfile.mkdtemp()
cert_path = os.path.join(cert_tmpdir, "cacert.pem")
with open(cert_path, "wb") as cert:
cert.write(pkgutil.get_data("pip._vendor.requests", "cacert.pem"))
argv = ["--disable-pip-version-check", "--cert", cert_path] + argv
return pip.main(argv)
result = pip.main(argv)
shutil.rmtree(cert_tmpdir, ignore_errors=True)
return result

from rules_python.whl import Wheel

Expand Down

0 comments on commit 8e0c31d

Please sign in to comment.