Skip to content

Conversation

@anonhostpi
Copy link
Contributor

@anonhostpi anonhostpi commented Jul 1, 2025

Purpose: Make the .ps1 Installer Easier to Use

Reddit Post: https://www.reddit.com/r/PowerShell/comments/1lpk3fj/python_embedding_again/

This PR attempts to make Install-IronPython.ps1 usable via one-liner

This change is was based on the method Chocolatey uses in its installer:

It now uses [scriptblock]::Create((iwr $url).Content) instead. NOTE: This would be blocked in Constrained Language Mode

# Production
# - This is NOT live
# - This is just a demonstration of what said one-liner will eventually look like
& ([scriptblock]::Create((iwr 'https://raw.githubusercontent.com/IronLanguages/ironpython3/main/eng/scripts/Install-IronPython.ps1'l).Content) -Path "." # Or whatever path you prefer

# Testing
# - see comment below: https://github.com/IronLanguages/ironpython3/pull/1957#issuecomment-3025854603

@anonhostpi
Copy link
Contributor Author

@dotnet-policy-service agree

@anonhostpi
Copy link
Contributor Author

anonhostpi commented Jul 1, 2025

Testing:

$url = 'https://raw.githubusercontent.com/anonhostpi/ironpython3/iex-web-support/eng/scripts/Install-IronPython.ps1'

cd (New-Item -Path "$env:TEMP\$([guid]::NewGuid())" -ItemType Directory)

iex ((New-Object System.Net.WebClient).DownloadString($url))

# Then actually testing the install:

# - Using the shims
.\Enter-IronPythonEnvironment.ps1
ipy -c "print('Hello from shimmed IronPython!')"

# - Embedding IronPython directly into PowerShell
Import-Module ".\IronPython.dll"
& {
    [IronPython.Hosting.Python]::CreateEngine().
        CreateScriptSourceFromString("print('Hello from embedded IronPython!')").
        Execute()
}

@anonhostpi anonhostpi changed the title Implement Support for Chocolatey-style Install Implement Support for a Chocolatey-style Install Jul 2, 2025
@anonhostpi anonhostpi marked this pull request as ready for review July 2, 2025 00:04
@anonhostpi
Copy link
Contributor Author

anonhostpi commented Jul 2, 2025

NOTE: It maybe worth stabilizing Install-IronPython.ps1 in the future by adding a separate releases asset instead of linking the file directly (via raw.githubusercontent.com)

ADDITIONAL NOTE: It may also be worth implementing this kind of install script for IronRuby

@anonhostpi anonhostpi changed the title Implement Support for a Chocolatey-style Install Implement Support for One-liner Installs Jul 2, 2025
@anonhostpi
Copy link
Contributor Author

NOTE: [scriptblock]::Create() would be blocked in Constrained Language Mode. However, I don't know why you would be installing this on a system that has been locked down with CLM.

If that edge-case ever occurs, & (iex "{ $(iwr $url).Content }") -Path "..." would probably work as well, though not very elegant and may present issues with scoping.

@anonhostpi anonhostpi requested a review from Lamparter July 3, 2025 00:49
Copy link
Contributor

@slozier slozier left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for the PR!

@anonhostpi
Copy link
Contributor Author

anonhostpi commented Jul 4, 2025

@slozier @Lamparter

Done! Anything else?

@anonhostpi anonhostpi requested a review from slozier July 4, 2025 09:48
Comment on lines 13 to +27
.EXAMPLE
PS>Invoke-WebRequest -Uri https://github.com/IronLanguages/ironpython3/releases/download/v3.4.0/IronPython.3.4.0.zip -OutFile IronPython.3.4.0.zip
PS>Expand-Archive -Path IronPython.3.4.0.zip -DestinationPath IronPython-unzipped
PS>./IronPython-unzipped/scripts/Install-IronPython -Path ~/ipyenv/v3.4.0
With a one-liner, install latest over the web:
The official binaries are downloaded from GitHub to the current directory, unzipped, and then the installation proceeds using the script from the unzipped directory. IronPython is installed into ~/ipyenv/v3.4.0.
PS>& ([scriptblock]::Create((iwr 'https://raw.githubusercontent.com/IronLanguages/ironpython3/main/eng/scripts/Install-IronPython.ps1').Content)) -Path ~/ipyenv/v3.4.2
The official binaries are downloaded from GitHub to the current directory, unzipped, and then the installation proceeds using the script from the unzipped directory. IronPython is installed into ~/ipyenv/v3.4.2
.EXAMPLE
PS>Invoke-WebRequest -Uri https://github.com/IronLanguages/ironpython3/releases/download/v3.4.2/IronPython.3.4.2.zip -OutFile IronPython.3.4.2.zip
PS>Expand-Archive -Path IronPython.3.4.2.zip -DestinationPath IronPython-unzipped
PS>./IronPython-unzipped/scripts/Install-IronPython -Path ~/ipyenv/v3.4.2
The official binaries are downloaded from GitHub to the current directory, unzipped, and then the installation proceeds using the script from the unzipped directory. IronPython is installed into ~/ipyenv/v3.4.2
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'd like to draw attention to the fact that I placed the web install into its own EXAMPLE block. Diff may be hard to read:

This is the 2 new EXAMPLE blocks:

.EXAMPLE

    With a one-liner, install latest over the web:

    PS>& ([scriptblock]::Create((iwr 'https://raw.githubusercontent.com/IronLanguages/ironpython3/main/eng/scripts/Install-IronPython.ps1').Content)) -Path ~/ipyenv/v3.4.2

    The official binaries are downloaded from GitHub to the current directory, unzipped, and then the installation proceeds using the script from the unzipped directory. IronPython is installed into ~/ipyenv/v3.4.2

.EXAMPLE

    PS>Invoke-WebRequest -Uri https://github.com/IronLanguages/ironpython3/releases/download/v3.4.2/IronPython.3.4.2.zip -OutFile IronPython.3.4.2.zip
    PS>Expand-Archive -Path IronPython.3.4.2.zip -DestinationPath IronPython-unzipped
    PS>./IronPython-unzipped/scripts/Install-IronPython -Path ~/ipyenv/v3.4.2

    The official binaries are downloaded from GitHub to the current directory, unzipped, and then the installation proceeds using the script from the unzipped directory. IronPython is installed into ~/ipyenv/v3.4.2

@anonhostpi
Copy link
Contributor Author

anonhostpi commented Jul 6, 2025

@slozier

Oh, I forgot to mention. I think these Resolve-Path don't work with the ipyenv path?

Done

Instead of importing the SQLite and WPF DLLs. You can add the DLLs folder to the search paths and then import sqlite3 should work.

Tested and done

Thanks! I think the script downloads the latest so it'll be v3.4.2?

There may need to be an issue started to bump source files to 3.4.2:

https://github.com/search?q=repo%3AIronLanguages%2Fironpython3%203.4.0&type=code

I feel like covering the README.md and Install-IronPython.ps1 is fair game with this PR, but the other 5 files in that code search may need to be addressed separately

Instances of '3.4.0' in README.md and Install-IronPython.ps1 been bumped to '3.4.2'

I will be creating a new issue for the other 5 files. #1960

Indeed, having it default to the PowerShell folder is not great. Will need to think about that one...

Started an issue to track it: #1959

Copy link
Contributor

@slozier slozier left a comment

Choose a reason for hiding this comment

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

Thanks! It all looks good to me.

@slozier slozier merged commit e73a4c7 into IronLanguages:main Jul 7, 2025
5 checks passed
@anonhostpi anonhostpi deleted the iex-web-support branch July 8, 2025 14:20
@anonhostpi
Copy link
Contributor Author

I announced it on Reddit: https://www.reddit.com/r/PowerShell/comments/1luv01h/full_ironpython_can_now_be_installed_via_oneliner/

Hopefully, that will gain you some maintainer traction from the PowerShell community

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.

3 participants