Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

special-case --prompt . to the cwd #2220

Merged
merged 3 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. "
"A value of '.' will be replaced with the name of the current 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"