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

activate for venv containing apostrophe doesn't work in powershell #79848

Closed
csabella opened this issue Jan 5, 2019 · 4 comments
Closed

activate for venv containing apostrophe doesn't work in powershell #79848

csabella opened this issue Jan 5, 2019 · 4 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@csabella
Copy link
Contributor

csabella commented Jan 5, 2019

BPO 35667
Nosy @vsajip, @eryksun, @csabella, @tirkarthi
PRs
  • bpo-37354: Make Powershell Activate.ps1 script static to allow for signing #14967
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-09-09.10:22:37.115>
    created_at = <Date 2019-01-05.21:34:29.044>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = "activate for venv containing apostrophe doesn't work in powershell"
    updated_at = <Date 2019-09-09.10:22:37.111>
    user = 'https://github.com/csabella'

    bugs.python.org fields:

    activity = <Date 2019-09-09.10:22:37.111>
    actor = 'vinay.sajip'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-09-09.10:22:37.115>
    closer = 'vinay.sajip'
    components = ['Library (Lib)']
    creation = <Date 2019-01-05.21:34:29.044>
    creator = 'cheryl.sabella'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35667
    keywords = ['patch']
    message_count = 4.0
    messages = ['333075', '333116', '333125', '351405']
    nosy_count = 4.0
    nosy_names = ['vinay.sajip', 'eryksun', 'cheryl.sabella', 'xtreak']
    pr_nums = ['14967']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue35667'
    versions = ['Python 3.7', 'Python 3.8']

    @csabella
    Copy link
    Contributor Author

    csabella commented Jan 5, 2019

    On Windows 10, when I try to activate a venv in powershell where the name contains an apostrophe, I get the following error ("don't" is the name of the venv):

    PS N:\projects\cpython\don't\Scripts> .\activate.ps1
    At N:\projects\cpython\don't\Scripts\Activate.ps1:42 char:28
    + function global:prompt {
    + ~
    Missing closing '}' in statement block or type definition.
    At N:\projects\cpython\don't\Scripts\Activate.ps1:37 char:40
    + if (! $env:VIRTUAL_ENV_DISABLE_PROMPT) {
    + ~
    Missing closing '}' in statement block or type definition.
    At N:\projects\cpython\don't\Scripts\Activate.ps1:43 char:61
    + Write-Host -NoNewline -ForegroundColor Green '(don't) '
    + ~
    Unexpected token ')' in expression or statement.
    At N:\projects\cpython\don't\Scripts\Activate.ps1:43 char:63
    + Write-Host -NoNewline -ForegroundColor Green '(don't) '
    + ~
    The string is missing the terminator: '.
    + CategoryInfo : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : MissingEndCurlyBrace

    This works OK in Command Prompt.

    @csabella csabella added 3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 5, 2019
    @tirkarthi
    Copy link
    Member

    From the error I think the quotes are not properly escaped while doing text replacement in venv activate file template at [0] while it's generated? On linux/Mac double quotes are used and hence the error is not triggered with single quote in virtualenv name. Using double quote in virtualenv name triggers the parse error.

    $  python3.7 -m venv py37\"-bpo-35667-venv
    $  source py37\"-bpo-35667-venv/bin/activate
    py37"-bpo-35667-venv/bin/activate:57: parse error near `then'

    Looking into the py37\"-bpo-35667-venv/bin/activate script there is below line where the double quote is unbalanced :

        if [ "x(py37"-bpo-35667-venv) " != x ] ; then
    	PS1="(py37"-bpo-35667-venv) ${PS1:-}"
        else

    I tried escaping the quotes with backslash at [0] but I get a similar error. I guess it's similar case in Powershell as I can see from Activate.ps1 but I haven't tested it. I am not sure about the difference in semantics between powershell and command prompt with respect to quoting since I don't have access to Windows.

    py37\'-bpo-35667-venv/bin/Activate.ps1 file with unbalanced quote

    function global:prompt {
        Write-Host -NoNewline -ForegroundColor Green '(py37'-bpo-35667-venv) '
        _OLD_VIRTUAL_PROMPT
    }
    

    [0]

    text = text.replace('__VENV_PROMPT__', context.prompt)

    @eryksun
    Copy link
    Contributor

    eryksun commented Jan 7, 2019

    I am not sure about the difference in semantics between powershell and
    command prompt with respect to quoting since

    CMD only uses single quotes in for /f loops, in which it's either a command or a literal string (w/ the "usebackq" option). This is not a problem in activate.bat.

    Double quotes in file names generally shouldn't be a problem in Windows. As far as I know, only the named-pipe file system allows them in pipe-file names (e.g. r'\\?\pipe\"pipename"'), and for regular files they're allowed in stream names (e.g. 'filename:"streamname"'). Otherwise, double quote should be reserved in file names as the DOS_DOT wildcard character.

    @vsajip
    Copy link
    Member

    vsajip commented Sep 9, 2019

    This has reportedly been fixed by the changes made to fix bpo-37354. I'll close this, but please reopen if you find it's still a problem.

    @vsajip vsajip closed this as completed Sep 9, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants