From 364f8be3da74cf47049ef0d01371277b2820f584 Mon Sep 17 00:00:00 2001 From: Vincent Philippon Date: Wed, 12 Feb 2020 13:17:18 -0500 Subject: [PATCH 1/2] Revert "also disallow altsep beside pathsep inside paths" This reverts commit 524d95e782d810243cf9cd344a88711591c94efc. --- src/virtualenv/create/creator.py | 11 +++++------ tests/unit/create/test_creator.py | 7 +++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/virtualenv/create/creator.py b/src/virtualenv/create/creator.py index cf46804e6..805b7e17f 100644 --- a/src/virtualenv/create/creator.py +++ b/src/virtualenv/create/creator.py @@ -117,12 +117,11 @@ def non_write_able(dest, value): encoding, "".join(refused.keys()), raw_value ) ) - for char in (i for i in (os.pathsep, os.altsep) if i is not None): - if char in raw_value: - raise ArgumentTypeError( - "destination {!r} must not contain the path separator ({}) as this would break " - "the activation scripts".format(raw_value, char) - ) + if os.pathsep in raw_value: + raise ArgumentTypeError( + "destination {!r} must not contain the path separator ({}) as this would break " + "the activation scripts".format(raw_value, os.pathsep) + ) value = Path(raw_value) if value.exists() and value.is_file(): diff --git a/tests/unit/create/test_creator.py b/tests/unit/create/test_creator.py index 6af52062e..604aa1f62 100644 --- a/tests/unit/create/test_creator.py +++ b/tests/unit/create/test_creator.py @@ -25,13 +25,12 @@ CURRENT = PythonInfo.current_system() -@pytest.mark.parametrize("sep", [i for i in (os.pathsep, os.altsep) if i is not None]) -def test_os_path_sep_not_allowed(tmp_path, capsys, sep): - target = "{}{}".format(str(tmp_path / "a"), "{}b".format(sep)) +def test_os_path_sep_not_allowed(tmp_path, capsys): + target = str(tmp_path / "a{}b".format(os.pathsep)) err = _non_success_exit_code(capsys, target) msg = ( "destination {!r} must not contain the path separator ({}) as this" - " would break the activation scripts".format(target, sep) + " would break the activation scripts".format(target, os.pathsep) ) assert msg in err, err From 6a33df0086e5bce6583bb370df97efd7d51c1077 Mon Sep 17 00:00:00 2001 From: Vincent Philippon Date: Thu, 13 Feb 2020 12:26:51 -0500 Subject: [PATCH 2/2] Test Creator.validate_dest replaces os.altsep by os.sep --- docs/changelog/1582.bugfix.rst | 1 + tests/unit/create/test_creator.py | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 docs/changelog/1582.bugfix.rst diff --git a/docs/changelog/1582.bugfix.rst b/docs/changelog/1582.bugfix.rst new file mode 100644 index 000000000..f89784535 --- /dev/null +++ b/docs/changelog/1582.bugfix.rst @@ -0,0 +1 @@ +Allow the use of ``/`` as pathname component separator on Windows - by ``vphilippon`` diff --git a/tests/unit/create/test_creator.py b/tests/unit/create/test_creator.py index 604aa1f62..bd69ea4aa 100644 --- a/tests/unit/create/test_creator.py +++ b/tests/unit/create/test_creator.py @@ -300,6 +300,13 @@ def test_creator_input_passed_is_abs(tmp_path, monkeypatch): assert str(result) == str(tmp_path / "venv") +@pytest.mark.skipif(os.altsep is None, reason="OS does not have an altsep") +def test_creator_replaces_altsep_in_dest(tmp_path): + dest = str(tmp_path / "venv{}foobar") + result = Creator.validate_dest(dest.format(os.altsep)) + assert str(result) == dest.format(os.sep) + + def test_create_long_path(current_fastest, tmp_path): if sys.platform == "darwin": max_shebang_length = 512