Poetry: Update prompt environment variable when opening shell

Created on 28 Nov 2019  路  5Comments  路  Source: python-poetry/poetry

  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] I have searched the documentation and believe that my question is not covered.

Feature Request


When running poetry shell you have no idea your in the virtualenv or not. Please add the virtualenv's name to the $PROMPT or $PS1 variable.

Feature

Most helpful comment

Please try the latest pre-release (Poetry version 1.0.0b8) that has this feature, in a working state.

All 5 comments

Please try the latest pre-release (Poetry version 1.0.0b8) that has this feature, in a working state.

I've tried the latest pre-release but it isn't working (on windows).
Windows Cmd:

C:\Users\...\pytestproject>poetry shell
Spawning shell within C:\Users\...\Appdata\Local\pypoetry\Cache\virtualenvs\pytestproject-vJd08mD1-py3.7
Microsoft Windows [Version 10.0.18363.476]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\...\pytestproject>

Windows Powershell:

PS C:\Users\...\pytestproject>poetry shell
Spawning shell within C:\Users\...\Appdata\Local\pypoetry\Cache\virtualenvs\pytestproject-vJd08mD1-py3.7
Microsoft Windows [Version 10.0.18363.476]
(c) 2019 Microsoft Corporation. All rights reserved.

PS C:\Users\...\pytestproject>

Cmder

C:\Users\...\pytestproject
位 poetry shell
Spawning shell within C:\Users\...\Appdata\Local\pypoetry\Cache\virtualenvs\pytestproject-vJd08mD1-py3.7
Microsoft Windows [Version 10.0.18363.476]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\...\pytestproject>

Also the cmder shell is not respected; e.g. it runs windows cmd.

Please try the latest pre-release (Poetry version 1.0.0b8) that has this feature, in a working state.

Worked great for me on MacOS/bash shell.

It doesn't seem to work on Windows 1.0.0 to respect Powershell at all:

PS C:\work\ingress> poetry shell # EXECUTED FROM POWERSHELL
Spawning shell within C:\work\ingress\.venv
Microsoft Windows [Version 10.0.18362.476]
(c) 2019 Microsoft Corporation. All rights reserved.
Clink v0.4.9 [git:2fd2c2] Copyright (c) 2012-2016 Martin Ridgers
http://mridgers.github.io/clink


C:\work\ingress> # PROMPT IN CMD.EXE

using activate directly:

PS C:\work\ingress> .\.venv\Scripts\activate # EXECUTED FROM POWERSHELL
(.venv) PS C:\work\ingress> # PROMPT IN POWERSHELL

This is for Cmder on Windows 10

This is supposed to be an automatic feature on Cmder in the next release.
https://github.com/cmderdev/cmder/blob/master/vendor/clink.lua#L30-L36
But it has not still hit the scoop yet.
Other issue is that obviously what's mentioned by @rfkortekaas
I attempted to go around by an alias poet
位 alias poet=poetry shell $t %ConEmuDir%\..\init.bat
This did & did not ~ work

C:\Prj\FinmartDelta  
位 alias poet=poetry shell $t %ConEmuDir%\..\init.bat
C:\Prj\FinmartDelta  
位 poet
Spawning shell within C:\Users\ny11559\AppData\Local\pypoetry\Cache\virtualenvs\finmartdelta-rJ3Qparu-py3.7
name=cmd        path=cmd.exe  {i attempted to put this directly in to shell.py, but failed}
Microsoft Windows [Version 10.0.18363.778]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Prj\FinmartDelta>                         {darn same thing}
C:\Prj\FinmartDelta>                         {hit return to see if I can activate it / not}
C:\Prj\FinmartDelta>poet                  {try again}
Virtual environment already activated: C:\Users\ny11559\AppData\Local\pypoetry\Cache\virtualenvs\finmartdelta-rJ3Qparu-py3.7

C:\Prj\FinmartDelta>                         {darn same thing}
C:\Prj\FinmartDelta                           {hit return again}
[finmartdelta-rJ3Qparu-py3.7] 位           {finally got what I needed}
C:\Prj\FinmartDelta  
[finmartdelta-rJ3Qparu-py3.7] 位 

Obviously, I need to do something here C:\Users\myUser.poetry\lib\poetry\utils

 shell.py                                                                                                       buffers  
42         if cls._shell is not None:                                                                                   
43             return cls._shell                                                                                        
44                                                                                                                      
45         try:                                                                                                         
46             name, path = detect_shell(os.getpid())                                                                   
47         except (RuntimeError, ShellDetectionFailure):                                                                
48             raise RuntimeError("Unable to detect the current shell.")                                                
49                                                                                                                      
50         cls._shell = cls(name, path)                                                                                 
51                                                                                                                      
52         return cls._shell                                                                                            
53                                                                                                                      
54     def activate(self, env):  # type: (VirtualEnv) -> None                                                           
55         if WINDOWS:                                                                                                  
56             return env.execute(self.path)   

{tried adding pull path to init.bat but got another error.}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ambv picture ambv  路  3Comments

Euphorbium picture Euphorbium  路  3Comments

sobolevn picture sobolevn  路  3Comments

tonysyu picture tonysyu  路  3Comments

mozartilize picture mozartilize  路  3Comments