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

Set a environment variable for venv prompt #79509

Open
batisteo mannequin opened this issue Nov 27, 2018 · 10 comments
Open

Set a environment variable for venv prompt #79509

batisteo mannequin opened this issue Nov 27, 2018 · 10 comments
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@batisteo
Copy link
Mannequin

batisteo mannequin commented Nov 27, 2018

BPO 35328
Nosy @brettcannon, @vsajip, @asottile, @lysnikolaou, @ZackerySpytz, @tirkarthi, @batisteo, @mafredri
PRs
  • bpo-35328: Set VIRTUAL_ENV_PROMPT at venv activation #10745
  • bpo-35328: Set VIRTUAL_ENV_PROMPT at venv activation (GH-21587) #21587
  • bpo-35328: Always set VIRTUAL_ENV_PROMPT at venv activation #22324
  • 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 = None
    created_at = <Date 2018-11-27.16:12:29.700>
    labels = ['type-feature', 'library', '3.10']
    title = 'Set a environment variable for venv prompt'
    updated_at = <Date 2020-09-21.18:58:02.565>
    user = 'https://github.com/batisteo'

    bugs.python.org fields:

    activity = <Date 2020-09-21.18:58:02.565>
    actor = 'brett.cannon'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2018-11-27.16:12:29.700>
    creator = 'batisteo'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35328
    keywords = ['patch']
    message_count = 10.0
    messages = ['330533', '330542', '330548', '333043', '342860', '343325', '343327', '343328', '374481', '377175']
    nosy_count = 8.0
    nosy_names = ['brett.cannon', 'vinay.sajip', 'Anthony Sottile', 'lys.nikolaou', 'ZackerySpytz', 'xtreak', 'batisteo', 'mafredri']
    pr_nums = ['10745', '21587', '22324']
    priority = 'normal'
    resolution = None
    stage = 'resolved'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue35328'
    versions = ['Python 3.10']

    @batisteo
    Copy link
    Mannequin Author

    batisteo mannequin commented Nov 27, 2018

    When creating a new virtual env with python3 -m venv .venv --prompt env, the prompt information is only used to set a temporary PS1.

    This information is lost when using custom prompt, for example with ZSH.

    I propose to set VIRTUAL_ENV_PROMPT=VENV_PROMPT when activating the newly created venv, to be used by tools and other shells.

    @batisteo batisteo mannequin added 3.7 (EOL) end of life 3.8 only security fixes labels Nov 27, 2018
    @asottile
    Copy link
    Mannequin

    asottile mannequin commented Nov 27, 2018

    The current prompt works fine for me on zsh -- what's the bug here?

    zsh $ virtualenv venv --prompt '(wat)'
    Using real prefix '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7'
    New python executable in /private/tmp/venv/bin/python3.7
    Also creating executable in /private/tmp/venv/bin/python
    Installing setuptools, pip, wheel...done.
    zsh $ . venv/bin/activate
    (wat)zsh $

    @batisteo
    Copy link
    Mannequin Author

    batisteo mannequin commented Nov 27, 2018

    How the venv prompt name would be displayed in a project like Powerline?

    Or in VS Code? https://i.ibb.co/JHYrnk2/Screenshot-from-2018-11-27-19-41-47.png

    Or in my custom prompt? https://gist.github.com/batisteo/c5c9bd87a344cdbfb7a6401648c118a2#file-batisteo-zsh-theme-L194

    @tirkarthi
    Copy link
    Member

    bpo-34439 seems like a similar proposal. I am adding @vinay.sajip. Since this seems like a new feature I have removed 3.7 from the version list.

    @tirkarthi tirkarthi added stdlib Python modules in the Lib dir type-feature A feature request or enhancement and removed 3.7 (EOL) end of life labels Jan 5, 2019
    @lysnikolaou
    Copy link
    Contributor

    Is anybody still working on this?

    @brettcannon
    Copy link
    Member

    @lys.nikolaou it looks like there was an initial PR, but it only updated things for Bash and not for all the other shells that we support for virtual environments.

    @lysnikolaou
    Copy link
    Contributor

    @brettcannon, yeah I saw that, but there hasn't been any progress since November. I'm still interested in this though. What would the correct workflow be? Pushing commits to the same PR or opening a new one with a co-author?

    @brettcannon
    Copy link
    Member

    You can open a new PR with co-author or basing off of their fork if it's still around.

    @vsajip vsajip added 3.9 only security fixes and removed 3.8 only security fixes labels Oct 31, 2019
    @vsajip
    Copy link
    Member

    vsajip commented Jul 28, 2020

    New changeset c82dda1 by Zackery Spytz in branch 'master':
    bpo-35328: Set VIRTUAL_ENV_PROMPT at venv activation (GH-21587)
    c82dda1

    @vsajip vsajip closed this as completed Sep 9, 2020
    @mafredri
    Copy link
    Mannequin

    mafredri mannequin commented Sep 19, 2020

    I believe #65786 does not fully address this issue because VIRTUAL_ENV_PROMPT is being conditionally set only if VIRTUAL_ENV_DISABLE_PROMPT is unset. Shell prompts must set VIRTUAL_ENV_DISABLE_PROMPT to non-empty to prevent venv from hijacking PS1. I'm one of the maintainers of the Pure prompt for zsh, and it would be great if VIRTUAL_ENV_PROMPT could always be set, just as VIRTUAL_ENV is too.

    @brettcannon brettcannon added 3.10 only security fixes and removed 3.9 only security fixes labels Sep 21, 2020
    @brettcannon brettcannon reopened this Sep 21, 2020
    @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.10 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants