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

Support shell command in windows #363

Merged
merged 5 commits into from Jul 18, 2023
Merged

Conversation

aisk
Copy link
Contributor

@aisk aisk commented Jul 13, 2023

The main change is detecting the OSs and shells, and when it's MS's shells (cmd.exe / powershell), using ; as path seprator. And when it's windows OS, using venv/Scripts instead of venv/bin as venv_bin (pypa/virtualenv@993ba13).

There is no simple way to detect which shell is been used, this PR try to iterate parent processes which name is cmd.exe / powershell.exe / pwsh.exe to determine the shell if no SHELL environment variable present.

Tested on:

  • cmd.exe
  • powershell
  • git bash (mingw)

Add a new dependency sysinfo for get parrent pid and process name. There are some candidates:

The sysinfo is a little too heavy, I think psutil is more suitable if it support windows, but for now it's ok to use sysinfo. Or maybe we can use winapi to call the native library directly?

@@ -36,14 +76,29 @@ pub fn execute(cmd: Args) -> Result<(), Error> {
.context("failed to sync ahead of shell")?;

let venv_path = pyproject.venv_path();
let venv_bin = venv_path.join("bin");
let venv_bin = if env::consts::OS == "windows" {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it should be determined in runtime instead of compile time, so using env::consts::OS == "windows" instead of cfg!(windows).

Maybe we will using binaries build in windows and runs on linux (wine?).

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this conditional - bin vs Scripts - is also done once already in rye/src/consts.rs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, thanks for the review!

@mitsuhiko mitsuhiko merged commit df417ea into astral-sh:main Jul 18, 2023
6 checks passed
@aisk aisk deleted the windows-shell branch July 19, 2023 08:19
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.

None yet

3 participants