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

Add PowerShell snippets for postinstall #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tats-u
Copy link

@tats-u tats-u commented Jul 16, 2022

#66

This PR allows Windows users to activate poery command without forcing them to google how to do it.

@vercel
Copy link

vercel bot commented Jul 16, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
install-python-poetry-org ✅ Ready (Inspect) Visit Preview Jul 17, 2022 at 9:54AM (UTC)

@tats-u
Copy link
Author

tats-u commented Jul 17, 2022

Poetry (1.1.14) is installed now. Great!
To get started you need Poetry's bin directory (C:\Users\runneradmin\AppData\Roaming\Python\Scripts) in your `PATH`
environment variable.
You can choose and execute one of the following commands in PowerShell:
A. Appends the bin directory to your user environment variable `PATH`:
```
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";C:\Users\runneradmin\AppData\Roaming\Python\Scripts", "User")
```
B. Tries to appends the bin directory to PATH every when you run PowerShell (>=6 recommended):
```
echo 'if (-not (Get-Command poetry -ErrorAction Ignore)) { $env:Path += ";C:\Users\runneradmin\AppData\Roaming\Python\Scripts" }' | Out-File -Append $PROFILE
```
Alternatively, you can call Poetry explicitly with `C:\Users\runneradmin\AppData\Roaming\Python\Scripts\poetry`.
You can test that everything is set up by executing:
`poetry --version`

@johnthagen
Copy link
Contributor

johnthagen commented Jul 24, 2022

For reviewers, here is a useful StackOverflow answer on the subject: https://stackoverflow.com/a/2571200

Copy link
Contributor

@johnthagen johnthagen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Disclaimer, not a Poetry dev]

First off, thank you for making this PR. I think this is an important step to easing new Windows users into Poetry.

My personal feedback is that we should try to keep this simpler. The installer already prints quite a lot of text and having multiple Powershell commands I think could overwhelm the target audience.

If we look at the Unix variant of this for inspiration, it is very simple:

POST_MESSAGE_CONFIGURE_UNIX = """
Add `export PATH="{poetry_home_bin}:$PATH"` to your shell configuration file.
"""

I would recommend we shorten this message to:

POST_MESSAGE_CONFIGURE_WINDOWS = """
Execute the following in Powershell:

[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";{poetry_home_bin}", "User")
"""

@johnthagen
Copy link
Contributor

johnthagen commented Jul 24, 2022

I tested Option A in this PR in a clean Windows 10 VM, and it worked as expected. 🚀

@tats-u
Copy link
Author

tats-u commented Jul 24, 2022

Unix OSes have no choice other than editing profile files for their shells, so how to activate Poetry can be kept simple.

In contrast of this, Windows has the built-in manager of environment variables.
PowerShell and CMD have profiles like shells for Unix.
This is why 2 option can be provided for Windows.

@johnthagen
Copy link
Contributor

@neersighted Would you be willing to review this PR? I personally think it would be important before the upcoming 1.2 final release. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants