diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 091a32c89..184d3b4b4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: hooks: - id: pyupgrade - repo: https://github.com/PyCQA/isort - rev: 5.6.3 + rev: 5.6.4 hooks: - id: isort - repo: https://github.com/ambv/black diff --git a/docs/changelog/1982.bugfix.rst b/docs/changelog/1982.bugfix.rst new file mode 100644 index 000000000..09f05b8d3 --- /dev/null +++ b/docs/changelog/1982.bugfix.rst @@ -0,0 +1 @@ +Bump embedded setuptools from ``50.3.0`` to ``50.3.1`` - by :user:`gaborbernat`. diff --git a/docs/changelog/1983.bugfix.rst b/docs/changelog/1983.bugfix.rst new file mode 100644 index 000000000..32a973f9b --- /dev/null +++ b/docs/changelog/1983.bugfix.rst @@ -0,0 +1 @@ +After importing virtualenv passing cwd to a subprocess calls breaks with ``invalid directory`` - by :user:`gaborbernat`. diff --git a/src/virtualenv/seed/wheels/embed/__init__.py b/src/virtualenv/seed/wheels/embed/__init__.py index 509f915a3..f153e0397 100644 --- a/src/virtualenv/seed/wheels/embed/__init__.py +++ b/src/virtualenv/seed/wheels/embed/__init__.py @@ -7,32 +7,32 @@ BUNDLE_SUPPORT = { "3.10": { "pip": "pip-20.2.3-py2.py3-none-any.whl", - "setuptools": "setuptools-50.3.0-py3-none-any.whl", + "setuptools": "setuptools-50.3.1-py3-none-any.whl", "wheel": "wheel-0.35.1-py2.py3-none-any.whl", }, "3.9": { "pip": "pip-20.2.3-py2.py3-none-any.whl", - "setuptools": "setuptools-50.3.0-py3-none-any.whl", + "setuptools": "setuptools-50.3.1-py3-none-any.whl", "wheel": "wheel-0.35.1-py2.py3-none-any.whl", }, "3.8": { "pip": "pip-20.2.3-py2.py3-none-any.whl", - "setuptools": "setuptools-50.3.0-py3-none-any.whl", + "setuptools": "setuptools-50.3.1-py3-none-any.whl", "wheel": "wheel-0.35.1-py2.py3-none-any.whl", }, "3.7": { "pip": "pip-20.2.3-py2.py3-none-any.whl", - "setuptools": "setuptools-50.3.0-py3-none-any.whl", + "setuptools": "setuptools-50.3.1-py3-none-any.whl", "wheel": "wheel-0.35.1-py2.py3-none-any.whl", }, "3.6": { "pip": "pip-20.2.3-py2.py3-none-any.whl", - "setuptools": "setuptools-50.3.0-py3-none-any.whl", + "setuptools": "setuptools-50.3.1-py3-none-any.whl", "wheel": "wheel-0.35.1-py2.py3-none-any.whl", }, "3.5": { "pip": "pip-20.2.3-py2.py3-none-any.whl", - "setuptools": "setuptools-50.3.0-py3-none-any.whl", + "setuptools": "setuptools-50.3.1-py3-none-any.whl", "wheel": "wheel-0.35.1-py2.py3-none-any.whl", }, "3.4": { diff --git a/src/virtualenv/seed/wheels/embed/setuptools-50.3.0-py3-none-any.whl b/src/virtualenv/seed/wheels/embed/setuptools-50.3.1-py3-none-any.whl similarity index 94% rename from src/virtualenv/seed/wheels/embed/setuptools-50.3.0-py3-none-any.whl rename to src/virtualenv/seed/wheels/embed/setuptools-50.3.1-py3-none-any.whl index af9f66f15..7b67c2ca2 100644 Binary files a/src/virtualenv/seed/wheels/embed/setuptools-50.3.0-py3-none-any.whl and b/src/virtualenv/seed/wheels/embed/setuptools-50.3.1-py3-none-any.whl differ diff --git a/src/virtualenv/util/subprocess/_win_subprocess.py b/src/virtualenv/util/subprocess/_win_subprocess.py index 33c77e312..4c4c5d029 100644 --- a/src/virtualenv/util/subprocess/_win_subprocess.py +++ b/src/virtualenv/util/subprocess/_win_subprocess.py @@ -7,7 +7,7 @@ import platform import subprocess from ctypes import Structure, WinError, byref, c_char_p, c_void_p, c_wchar, c_wchar_p, sizeof, windll -from ctypes.wintypes import BOOL, BYTE, DWORD, HANDLE, LPVOID, LPWSTR, WORD +from ctypes.wintypes import BOOL, BYTE, DWORD, HANDLE, LPCWSTR, LPVOID, LPWSTR, WORD import _subprocess @@ -63,8 +63,8 @@ def __int__(self): CreateProcessW = windll.kernel32.CreateProcessW CreateProcessW.argtypes = [ - LPCTSTR, LPTSTR, LPSECURITY_ATTRIBUTES, - LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPCTSTR, + LPCWSTR, LPWSTR, LPSECURITY_ATTRIBUTES, + LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPCWSTR, LPSTARTUPINFOW, LPPROCESS_INFORMATION, ] CreateProcessW.restype = BOOL @@ -107,13 +107,17 @@ def CreateProcess( wenv = (c_wchar * len(env))() wenv.value = env + wcwd = None + if cwd is not None: + wcwd = unicode(cwd) + pi = PROCESS_INFORMATION() creation_flags |= CREATE_UNICODE_ENVIRONMENT if CreateProcessW( executable, args, None, None, inherit_handles, creation_flags, - wenv, cwd, byref(si), byref(pi), + wenv, wcwd, byref(si), byref(pi), ): return ( DUMMY_HANDLE(pi.hProcess), DUMMY_HANDLE(pi.hThread), diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py index 351d52862..ca3f31f18 100644 --- a/tests/unit/test_util.py +++ b/tests/unit/test_util.py @@ -1,5 +1,11 @@ from __future__ import absolute_import, unicode_literals +import subprocess +import sys + +import pytest + +from virtualenv.info import IS_WIN, PY2 from virtualenv.util.subprocess import run_cmd @@ -8,3 +14,14 @@ def test_run_fail(tmp_path): assert err assert not out assert code + + +@pytest.mark.skipif(not (PY2 and IS_WIN), reason="subprocess patch only applied on Windows python2") +def test_windows_py2_cwd_works(tmp_path): + cwd = str(tmp_path) + result = subprocess.check_output( + [sys.executable, "-c", "import os; print(os.getcwd())"], + cwd=cwd, + universal_newlines=True, + ) + assert result == "{}\n".format(cwd)