diff options
author | Ruairidh MacLeod <ruairidh@rkm.dev> | 2021-10-23 11:16:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-23 11:16:41 +0100 |
commit | 6bfc29e1a3d621e3f622a0d0395ff261ce0f3973 (patch) | |
tree | e291a741d83dcdab7a114a1f58da6b1ed9229044 | |
parent | 4188ac6e72d3b731595c83d46d1c0eb76fe4f6eb (diff) | |
download | virtualenv-6bfc29e1a3d621e3f622a0d0395ff261ce0f3973.tar.gz |
special-case `--prompt .` to the cwd (#2220)
Co-authored-by: Bernát Gábor <gaborjbernat@gmail.com>
-rw-r--r-- | .pre-commit-config.yaml | 2 | ||||
-rw-r--r-- | docs/changelog/2220.feature.rst | 1 | ||||
-rw-r--r-- | src/virtualenv/activation/activator.py | 3 | ||||
-rw-r--r-- | src/virtualenv/run/plugin/activators.py | 5 | ||||
-rw-r--r-- | tests/unit/activation/test_activator.py | 18 |
5 files changed, 26 insertions, 3 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b14317e..a9ba679 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/docs/changelog/2220.feature.rst b/docs/changelog/2220.feature.rst new file mode 100644 index 0000000..2bdc768 --- /dev/null +++ b/docs/changelog/2220.feature.rst @@ -0,0 +1 @@ +Special-case ``--prompt .`` to the name of the current directory - by :user:`rkm`. diff --git a/src/virtualenv/activation/activator.py b/src/virtualenv/activation/activator.py index 587ac10..80d7e47 100644 --- a/src/virtualenv/activation/activator.py +++ b/src/virtualenv/activation/activator.py @@ -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): diff --git a/src/virtualenv/run/plugin/activators.py b/src/virtualenv/run/plugin/activators.py index dea2827..8180981 100644 --- a/src/virtualenv/run/plugin/activators.py +++ b/src/virtualenv/run/plugin/activators.py @@ -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(): diff --git a/tests/unit/activation/test_activator.py b/tests/unit/activation/test_activator.py new file mode 100644 index 0000000..4a8a51c --- /dev/null +++ b/tests/unit/activation/test_activator.py @@ -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" |