special-case --prompt . to the cwd (#2220)
Co-authored-by: Bernát Gábor <gaborjbernat@gmail.com>
This commit is contained in:
parent
4188ac6e72
commit
6bfc29e1a3
5 changed files with 26 additions and 3 deletions
|
|
@ -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:
|
||||
|
|
|
|||
1
docs/changelog/2220.feature.rst
Normal file
1
docs/changelog/2220.feature.rst
Normal file
|
|
@ -0,0 +1 @@
|
|||
Special-case ``--prompt .`` to the name of the current directory - by :user:`rkm`.
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import os
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
from six import add_metaclass
|
||||
|
|
@ -14,7 +15,7 @@ class Activator(object):
|
|||
|
||||
: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):
|
||||
|
|
|
|||
|
|
@ -43,7 +43,10 @@ class ActivationSelector(ComponentBuilder):
|
|||
"--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():
|
||||
|
|
|
|||
18
tests/unit/activation/test_activator.py
Normal file
18
tests/unit/activation/test_activator.py
Normal file
|
|
@ -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"
|
||||
Loading…
Reference in a new issue