From 8dc6919875271c1cecc07701c6dc0411e67e0258 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Sat, 28 Dec 2019 18:36:19 -0500 Subject: [PATCH] Fix mypy checks on Windows Previously we were making unguarded calls to non-Windows-only APIs. Mypy only automatically excludes these from platform-specific checks when inside conditions. --- src/pip/_internal/utils/compat.py | 13 +++++++------ src/pip/_internal/utils/filesystem.py | 3 ++- src/pip/_internal/utils/glibc.py | 3 +++ tests/unit/test_utils.py | 2 ++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pip/_internal/utils/compat.py b/src/pip/_internal/utils/compat.py index d347b73d98d..6efa52ad2b8 100644 --- a/src/pip/_internal/utils/compat.py +++ b/src/pip/_internal/utils/compat.py @@ -257,12 +257,13 @@ def ioctl_GWINSZ(fd): return cr cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2) if not cr: - try: - fd = os.open(os.ctermid(), os.O_RDONLY) - cr = ioctl_GWINSZ(fd) - os.close(fd) - except Exception: - pass + if sys.platform != "win32": + try: + fd = os.open(os.ctermid(), os.O_RDONLY) + cr = ioctl_GWINSZ(fd) + os.close(fd) + except Exception: + pass if not cr: cr = (os.environ.get('LINES', 25), os.environ.get('COLUMNS', 80)) return int(cr[1]), int(cr[0]) diff --git a/src/pip/_internal/utils/filesystem.py b/src/pip/_internal/utils/filesystem.py index bce2058bcf1..7e1e3c8c7a5 100644 --- a/src/pip/_internal/utils/filesystem.py +++ b/src/pip/_internal/utils/filesystem.py @@ -4,6 +4,7 @@ import random import shutil import stat +import sys from contextlib import contextmanager from tempfile import NamedTemporaryFile @@ -29,7 +30,7 @@ def check_path_owner(path): # type: (str) -> bool # If we don't have a way to check the effective uid of this process, then # we'll just assume that we own the directory. - if not hasattr(os, "geteuid"): + if sys.platform == "win32" or not hasattr(os, "geteuid"): return True previous = None diff --git a/src/pip/_internal/utils/glibc.py b/src/pip/_internal/utils/glibc.py index 544b4c2792b..42b1d3919a3 100644 --- a/src/pip/_internal/utils/glibc.py +++ b/src/pip/_internal/utils/glibc.py @@ -5,6 +5,7 @@ import os import re +import sys import warnings from pip._internal.utils.typing import MYPY_CHECK_RUNNING @@ -26,6 +27,8 @@ def glibc_version_string_confstr(): # to be broken or missing. This strategy is used in the standard library # platform module: # https://github.com/python/cpython/blob/fcf1d003bf4f0100c9d0921ff3d70e1127ca1b71/Lib/platform.py#L175-L183 + if sys.platform == "win32": + return None try: # os.confstr("CS_GNU_LIBC_VERSION") returns a string like "glibc 2.17": _, version = os.confstr("CS_GNU_LIBC_VERSION").split() diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index 65b1a9a3ff6..64c8aabf505 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -570,12 +570,14 @@ def test_manylinux_check_glibc_version(self): # Didn't find the warning we were expecting assert False + @pytest.mark.skipif("sys.platform == 'win32'") def test_glibc_version_string(self, monkeypatch): monkeypatch.setattr( os, "confstr", lambda x: "glibc 2.20", raising=False, ) assert glibc_version_string() == "2.20" + @pytest.mark.skipif("sys.platform == 'win32'") def test_glibc_version_string_confstr(self, monkeypatch): monkeypatch.setattr( os, "confstr", lambda x: "glibc 2.20", raising=False,