Skip to content

Commit 041695b

Browse files
matteiusoz123
authored andcommitted
Restore this patch in hopes it fixes the windows 3.8 build.
1 parent 2fe293c commit 041695b

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

tests/integration/conftest.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import errno
12
import functools
23
import json
34
import logging
45
import os
6+
import shutil
7+
from shutil import rmtree as _rmtree
58
import sys
69
import warnings
710
from pathlib import Path
@@ -10,19 +13,17 @@
1013

1114
import pytest
1215
import requests
13-
1416
from pipenv.utils.processes import subprocess_run
1517
from pipenv.vendor import tomlkit
1618
from pipenv.vendor.requirementslib.utils import temp_environ
19+
from pipenv.vendor.requirementslib.models.setup_info import handle_remove_readonly
1720

1821
log = logging.getLogger(__name__)
1922
warnings.simplefilter("default", category=ResourceWarning)
2023

2124

2225
HAS_WARNED_GITHUB = False
2326

24-
DEFAULT_PRIVATE_PYPI_SERVER = "http://localhost:8080/simple"
25-
2627

2728
def try_internet(url="http://httpbin.org/ip", timeout=1.5):
2829
resp = requests.get(url, timeout=timeout)
@@ -281,26 +282,48 @@ def lockfile_path(self):
281282
return os.sep.join([self.path, 'Pipfile.lock'])
282283

283284

285+
# Windows python3.8 fails without this patch. Additional details: https://bugs.python.org/issue42796
286+
def _rmtree_func(path, ignore_errors=True, onerror=None):
287+
shutil_rmtree = _rmtree
288+
if onerror is None:
289+
onerror = handle_remove_readonly
290+
try:
291+
shutil_rmtree(path, ignore_errors=ignore_errors, onerror=onerror)
292+
except (OSError, FileNotFoundError, PermissionError) as exc:
293+
# Ignore removal failures where the file doesn't exist
294+
if exc.errno != errno.ENOENT:
295+
raise
296+
284297
@pytest.fixture()
285-
def pipenv_instance_pypi(capfdbinary):
286-
with temp_environ():
298+
def pipenv_instance_pypi(capfdbinary, monkeypatch):
299+
with temp_environ(), monkeypatch.context() as m:
300+
m.setattr(shutil, "rmtree", _rmtree_func)
301+
original_umask = os.umask(0o007)
287302
os.environ["PIPENV_NOSPIN"] = "1"
288303
os.environ["CI"] = "1"
289304
os.environ["PIPENV_DONT_USE_PYENV"] = "1"
290305
warnings.simplefilter("ignore", category=ResourceWarning)
291306
warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*<ssl.SSLSocket.*>")
292-
yield functools.partial(_PipenvInstance, capfd=capfdbinary, index_url="https://pypi.org/simple")
307+
try:
308+
yield functools.partial(_PipenvInstance, capfd=capfdbinary, index_url="https://pypi.org/simple")
309+
finally:
310+
os.umask(original_umask)
293311

294312

295313
@pytest.fixture()
296-
def pipenv_instance_private_pypi(capfdbinary):
297-
with temp_environ():
314+
def pipenv_instance_private_pypi(capfdbinary, monkeypatch):
315+
with temp_environ(), monkeypatch.context() as m:
316+
m.setattr(shutil, "rmtree", _rmtree_func)
317+
original_umask = os.umask(0o007)
298318
os.environ["PIPENV_NOSPIN"] = "1"
299319
os.environ["CI"] = "1"
300320
os.environ["PIPENV_DONT_USE_PYENV"] = "1"
301321
warnings.simplefilter("ignore", category=ResourceWarning)
302322
warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*<ssl.SSLSocket.*>")
303-
yield functools.partial(_PipenvInstance, capfd=capfdbinary, index_url="http://localhost:8080/simple")
323+
try:
324+
yield functools.partial(_PipenvInstance, capfd=capfdbinary, index_url="http://localhost:8080/simple")
325+
finally:
326+
os.umask(original_umask)
304327

305328

306329
@pytest.fixture()

0 commit comments

Comments
 (0)