Skip to content

Commit

Permalink
special-case --prompt . to the cwd (#2220)
Browse files Browse the repository at this point in the history
Co-authored-by: Bernát Gábor <[email protected]>
  • Loading branch information
rkm and gaborbernat authored Oct 23, 2021
1 parent 4188ac6 commit 6bfc29e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
rev: v1.11.0
hooks:
- id: blacken-docs
additional_dependencies: [black==20.8b1]
additional_dependencies: [black==21.9b0]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/2220.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Special-case ``--prompt .`` to the name of the current directory - by :user:`rkm`.
3 changes: 2 additions & 1 deletion src/virtualenv/activation/activator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import, unicode_literals

import os
from abc import ABCMeta, abstractmethod

from six import add_metaclass
Expand All @@ -14,7 +15,7 @@ def __init__(self, options):
:param options: the parsed options as defined within :meth:`add_parser_arguments`
"""
self.flag_prompt = options.prompt
self.flag_prompt = os.path.basename(os.getcwd()) if options.prompt == "." else options.prompt

@classmethod
def supports(cls, interpreter):
Expand Down
5 changes: 4 additions & 1 deletion src/virtualenv/run/plugin/activators.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def handle_selected_arg_parse(self, options):
"--prompt",
dest="prompt",
metavar="prompt",
help="provides an alternative prompt prefix for this environment",
help=(
"provides an alternative prompt prefix for this environment "
"(value of . means name of the current working directory)"
),
default=None,
)
for activator in self.active.values():
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/activation/test_activator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import absolute_import, unicode_literals

from argparse import Namespace

from virtualenv.activation.activator import Activator


def test_activator_prompt_cwd(monkeypatch, tmp_path):
class FakeActivator(Activator):
def generate(self, creator):
raise NotImplementedError

cwd = tmp_path / "magic"
cwd.mkdir()
monkeypatch.chdir(cwd)

activator = FakeActivator(Namespace(prompt="."))
assert activator.flag_prompt == "magic"

0 comments on commit 6bfc29e

Please sign in to comment.