Skip to content

Commit

Permalink
Default prompt of environment name in batch shell (#1679)
Browse files Browse the repository at this point in the history
* Default prompt of environment name in batch shell

* Handle batch prompt in activate.bat

* change test folder name to aviod bat escapes

* run activation tests with and without prompt

* test for correct prompt in batch (only, for now)

* Try to normalize path in batch tests

* update description

* Update 1679.bugfix.rst

* Update conftest.py

* Update conftest.py

Signed-off-by: Bernat Gabor <[email protected]>

* better names

Signed-off-by: Bernat Gabor <[email protected]>

Co-authored-by: Bernát Gábor <[email protected]>
  • Loading branch information
spetafree and gaborbernat authored Mar 3, 2020
1 parent 7649968 commit dd37c7d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/changelog/1679.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix Batch activation script shell prompt to display environment name by default - by :user:`spetafree`.
7 changes: 6 additions & 1 deletion src/virtualenv/activation/batch/activate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ if defined _OLD_VIRTUAL_PROMPT (
)
)
if not defined VIRTUAL_ENV_DISABLE_PROMPT (
set "PROMPT=__VIRTUAL_PROMPT__%PROMPT%"
set "ENV_PROMPT=__VIRTUAL_PROMPT__"
if NOT DEFINED ENV_PROMPT (
for %%d in ("%VIRTUAL_ENV%") do set "ENV_PROMPT=(%%~nxd) "
)
)
set "PROMPT=%ENV_PROMPT%%PROMPT%"
)

REM Don't use () to avoid problems with them in %PATH%
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/activation/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,13 @@ def raise_on_non_source_class():
return RaiseOnNonSourceCall


@pytest.fixture(scope="session")
def activation_python(tmp_path_factory, special_char_name, current_fastest):
@pytest.fixture(scope="session", params=[True, False], ids=["with_prompt", "no_prompt"])
def activation_python(request, tmp_path_factory, special_char_name, current_fastest):
dest = os.path.join(ensure_text(str(tmp_path_factory.mktemp("activation-tester-env"))), special_char_name)
session = cli_run(["--without-pip", dest, "--prompt", special_char_name, "--creator", current_fastest, "-vv"])
cmd = ["--without-pip", dest, "--creator", current_fastest, "-vv"]
if request.param:
cmd += ["--prompt", special_char_name]
session = cli_run(cmd)
pydoc_test = session.creator.purelib / "pydoc_test.py"
pydoc_test.write_text('"""This is pydoc_test.py"""')
yield session
Expand Down

0 comments on commit dd37c7d

Please sign in to comment.