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

Windows: Report installation messages to console #847

Merged
merged 22 commits into from
Sep 13, 2024

Conversation

jaimergp
Copy link
Contributor

@jaimergp jaimergp commented Aug 30, 2024

Description

Taking inspiration from the examples collected in #764 (comment), we can print directly to the attached console (which might not be the stdout stream!) and report some information. This mostly works but we can't rely on stream redirection, piping or capture (that's why we still need the log files for testing) unless we execute the installer directly without START /WAIT. For most end users, this won't be an issue, I hope. The output can be silenced with /Q (quiet).

This only applies to /S mode (S for silent, but let's call it headlesS now).

This is how it looks more or less:

> cmd /C START /WAIT Miniforge3-4.10.1-0-Windows-x86_64.exe /S /D=C:\Users\Jaime\Miniforge-again
Welcome to Miniforge3 4.10.1-0

By continuing this installation you are accepting this license agreement:
C:\Users\Jaime\Miniforge-again\EULA.txt
Please run the installer in GUI mode to read the details.

Miniforge3 will now be installed into this location:
C:\Users\Jaime\Miniforge-again

Unpacking payload...
Setting up the package cache...
Setting up the base environment...
Installing packages for base, creating shortcuts if necessary...
Initializing conda directories...
Running post install...
Done!
> cmd /C START /WAIT Miniforge3-4.10.1-0-Windows-x86_64.exe /?
Installs Miniforge3 4.10.1-0

USAGE
-----

Miniforge3-4.10.1-0-Windows-x86_64.exe [options]

OPTIONS
-------

/InstallationType=AllUsers [default: JustMe]
/AddToPath=[0|1] [default: 0]
/KeepPkgCache=[0|1] [default: 1]
/RegisterPython=[0|1] [default: AllUsers: 1, JustMe: 0]
/NoRegistry=[0|1] [default: AllUsers: 0, JustMe: 0]
/NoScripts=[0|1] [default: 0]
/NoShortcuts=[0|1] [default: 0]
/CheckPathLength=[0|1] [default: 1]
/? (show this help message)
/S (run in CLI/headless mode)
/D=[installation directory] (must be last parameter)

EXAMPLES
--------

Install for all users, but don't add to PATH env var:
> Miniforge3-4.10.1-0-Windows-x86_64.exe /InstallationType=AllUsers

Install for just me, add to PATH and register as system Python:
> Miniforge3-4.10.1-0-Windows-x86_64.exe /RegisterPython=1 /AddToPath=1

Install for just me, with no registry modification (for CI):
> Miniforge3-4.10.1-0-Windows-x86_64.exe /NoRegistry=1

Install via CLI (no GUI) into C:\Miniforge3
> cmd /C START /WAIT Miniforge3-4.10.1-0-Windows-x86_64.exe /S /D=C:\Miniforge3

NOTE: If you install for AllUsers, then the option to AddToPath
is disabled (i.e. if /InstallationType=AllUsers, then
/AddToPath=1 will be ignored).

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Aug 30, 2024
@jaimergp jaimergp marked this pull request as ready for review September 6, 2024 10:20
@jaimergp jaimergp requested a review from a team as a code owner September 6, 2024 10:20
@jaimergp jaimergp changed the title Draft support for stdout logging Windows: Report installation messages to console Sep 6, 2024
Copy link
Contributor

@marcoesters marcoesters left a comment

Choose a reason for hiding this comment

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

I like this a lot. However, I think it there should be an option to suppress the output to still allow for old behavior, especially since stream redirecting doesn't work.

Alternatively, we can make this an opt-in option, but I think outputting into the console should be the default.

Do you know how this would look like inside a GitHub Action?

@jaimergp
Copy link
Contributor Author

I think it there should be an option to suppress the output to still allow for old behavior, especially since stream redirecting doesn't work.

Good point. You mean a CLI flag (e.g. /Q?) or a constructor option?

Do you know how this would look like inside a GitHub Action?

Haven't checked yet, but will do.

@marcoesters
Copy link
Contributor

I think it there should be an option to suppress the output to still allow for old behavior, especially since stream redirecting doesn't work.

Good point. You mean a CLI flag (e.g. /Q?) or a constructor option?

A CLI flag

@jaimergp
Copy link
Contributor Author

Do you know how this would look like inside a GitHub Action?

The output doesn't show up in GHA logs. I guess their capture mechanism doesn't involve low level Windows APIs and "just" the stdout streams 😂

Or am I missing something in how I set this up?

@jaimergp
Copy link
Contributor Author

Ok, it looks like stream redirection does work if invoked directly like:

my-installer.exe /S > out.txt

However that call is not blocking, so the user will have to check the logs manually via polling or something. Added this gotcha to the docs.

@jaimergp
Copy link
Contributor Author

You can see that the direct call does work on GHA output now, but we have to block with some sleep-like statements.

Copy link
Contributor

@marcoesters marcoesters left a comment

Choose a reason for hiding this comment

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

I discovered another gotcha: calling the uninstaller opens a new Window for some reason.

like this:

```batch
> cmd.exe /c start /wait my_installer.exe /S
Copy link
Contributor

Choose a reason for hiding this comment

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

cmd.exe /c is not necessary. You could also consider adding PowerShell since this is the default profile in the Windows Terminal

Start-Process -FilePath my_installer.exe -ArgumentList "/S" -NoNewWindow -Wait

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, you can even use -RedirectStandardOutput out.txt to correctly redirect things!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added this to the documentation.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you replaced the documentation. I don't see the harm showing both cmd.exe and PowerShell.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tabs with both now.

constructor/nsis/main.nsi.tmpl Outdated Show resolved Hide resolved
@jaimergp
Copy link
Contributor Author

calling the uninstaller opens a new Window for some reason.

Yep, can reproduce. I think this is due to the fact that the uninstaller copies itself to a temporary location so it can delete itself during the "Removing files and folders..." step. That would cause the new process to lose the parent console and hence why we get a new allocated console for that. I guess that's better than nothing so I'm inclined to leave it like that. I'm not concerned about CI usage because in those cases users don't really uninstall, just spin a new one up, right?

@marcoesters
Copy link
Contributor

calling the uninstaller opens a new Window for some reason.

Yep, can reproduce. I think this is due to the fact that the uninstaller copies itself to a temporary location so it can delete itself during the "Removing files and folders..." step. That would cause the new process to lose the parent console and hence why we get a new allocated console for that. I guess that's better than nothing so I'm inclined to leave it like that. I'm not concerned about CI usage because in those cases users don't really uninstall, just spin a new one up, right?

I use the uninstallation procedure in a CI, but I don't see how this would break it. And even if it does, /Q never attaches to the console.

However, it might be worth pointing out the new window in the documentation.

@jaimergp
Copy link
Contributor Author

However, it might be worth pointing out the new window in the documentation.

Added a couple sentences.

> cmd.exe /c start /wait my_installer.exe /S
`````{tab-set}
````{tab-item} CMD
```pwsh
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
```pwsh
```batch

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 used pwsh on purpose here because the batch syntax highlighting didn't shown any colours at all.


`````{tab-set}
````{tab-item} CMD
```pwsh
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
```pwsh
```batch

> cmd.exe /c start /wait my_installer.exe /S
`````{tab-set}
````{tab-item} CMD
```pwsh
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
```pwsh
```batch

> my_installer.exe /S > logs.txt
`````{tab-set}
````{tab-item} CMD
```pwsh
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
```pwsh
```batch

@jaimergp jaimergp merged commit 89348cc into conda:main Sep 13, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed [bot] added once the contributor has signed the CLA
Projects
Status: 🏁 Done
3 participants