Skip to content

Commit

Permalink
Revert "also disallow altsep beside pathsep inside paths" (#1598)
Browse files Browse the repository at this point in the history
* Revert "also disallow altsep beside pathsep inside paths"

This reverts commit 524d95e.

* Test Creator.validate_dest replaces os.altsep by os.sep
  • Loading branch information
vphilippon authored Feb 13, 2020
1 parent 52e4213 commit eb80439
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/changelog/1582.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow the use of ``/`` as pathname component separator on Windows - by ``vphilippon``
11 changes: 5 additions & 6 deletions src/virtualenv/create/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
14 changes: 10 additions & 4 deletions tests/unit/create/test_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -299,6 +298,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
Expand Down

0 comments on commit eb80439

Please sign in to comment.