Skip to content

venv: activate.csh fails in a non-interactive shell #154399

Description

@serhiy-storchaka

Bug report

source bin/activate.csh fails in a non-interactive shell, because it saves the prompt unconditionally:

set _OLD_VIRTUAL_PROMPT="$prompt"

prompt is only set in interactive shells, and csh fails on an undefined variable:

prompt: Undefined variable.

The activation is incomplete in both implementations, but the effect differs:

  • with csh (OpenBSD) the error is fatal and the script exits with status 1;
  • with tcsh (FreeBSD, NetBSD, DragonFly BSD) it only aborts sourcing and the exit status stays 0, so the failure is silent. PATH and VIRTUAL_ENV are set, because they come earlier in the file, but the pydoc alias and rehash at the end are skipped, and _OLD_VIRTUAL_PROMPT is never saved.

test_venv.test_special_chars_csh fails on OpenBSD for this reason. It passes on tcsh platforms because it only checks what is set before the failing line.

The prompt is not needed in a non-interactive shell, so the block can be guarded with if ($?prompt). The deactivate alias already handles an unset _OLD_VIRTUAL_PROMPT: it is invoked that way at activation, before the variable is set.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-venvRelated to the venv moduletype-bugAn unexpected behavior, bug, or error

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions