-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Replace poetry shell
command with poetry env activate
#9763
base: main
Are you sure you want to change the base?
Conversation
Deploy preview for website ready! ✅ Preview Built with commit 12b301e. |
|
||
class EnvActivateCommand(Command): | ||
name = "env activate" | ||
description = "Print the command to activate a virtual environment" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description = "Print the command to activate a virtual environment" | |
description = "Print the command to activate a virtual environment." |
@staticmethod | ||
def quote(command: str, shell: str) -> str: | ||
if shell in ["powershell", "pwsh"] or WINDOWS: | ||
return "{}".format(command.replace("'", "''")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this should handle paths with '
? However, it does not seem to work (on Windows) and it also does not work for paths with spaces (which is far more common and thereby more important).
On Windows, for cmd
you just have to put the command in double quotes (f'"{command}"'
) and for Powershell you need something like f'& "{command}"'
.
@pytest.mark.parametrize( | ||
"shell, command, ext", | ||
( | ||
("pwsh", ".", "Activate.ps1"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
("pwsh", ".", "Activate.ps1"), | |
("cmd", ".", "activate"), | |
("pwsh", ".", "Activate.ps1"), |
"Discovered shell doesn't have an activator in virtual environment" | ||
) | ||
|
||
def get_activate_command(self, env: Env) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def get_activate_command(self, env: Env) -> str: | |
def _get_activate_command(self, env: Env) -> str: |
I'd add an underscore to make clear it is internal.
return "" | ||
|
||
@staticmethod | ||
def quote(command: str, shell: str) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def quote(command: str, shell: str) -> str: | |
def _quote(command: str, shell: str) -> str: |
I'd add an underscore to make clear it's internal
@@ -648,29 +648,6 @@ poetry run my-script | |||
|
|||
Note that this command has no option. | |||
|
|||
## shell |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, we should not remove it (now) but write that it has been outsourced into a plugin and we recommend to use env activate
instead. (We did not remove export
from the docs. I hope this will save us some support requests because some people will look here.)
`poetry env activate` command prints the activate command to the console. This way you won't leave the current shell. | ||
You can then feed the output to `eval` to activate the environment. This way is the closest to manually activating the environment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would restructure the text a bit and do not refer to eval
but "the eval command of your shell" (or similar). Proposal:
`poetry env activate` command prints the activate command to the console. This way you won't leave the current shell. | |
You can then feed the output to `eval` to activate the environment. This way is the closest to manually activating the environment. | |
The `poetry env activate` command prints the activate command of the virtual environment to the console. | |
You can run the output command manually or feed it to the eval command of your shell to activate the environment. | |
This way you won't leave the current shell. |
{{% note %}} | ||
Looking for `poetry shell`? It was moved to a plugin: [`poetry-plugin-shell`](https://github.com/python-poetry/poetry-plugin-shell) | ||
{{% /note %}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd either put this at the beginning or the end and not between the text and the examples how to feed the output to the eval command of different shells.
|
||
```bash | ||
$ eval $(poetry env activate) | ||
(test-project-for-test) $ # Virtualenv entered |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is missing for fish
and powershell
.
Pull Request Check List
Resolves: personal grudge towards
poetry shell