Skip to content

Commit 7977fa0

Browse files
authored
Update Install-IronPython and pack in zipfile (#1585)
* Update Install-IronPython and pack in zipfile * Create startup script for mono during installation * Update README for zip package * Prioritize installation from within zip file
1 parent caf05c9 commit 7977fa0

3 files changed

Lines changed: 91 additions & 49 deletions

File tree

Package/zip/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ After unpacking the archive, move or copy one of the `net` directories matching
1313

1414
If access to the Python Standard Library is desired from IronPython, move or copy the whole `lib` directory **into** the moved/copied directory from the previous step. The `lib` directory has to be in the same directory as `IronPython.dll`.
1515

16+
The `scripts` subdirectory contains an installation script that facilitates the installation. Example:
17+
18+
```powershell
19+
PS> ./scripts/Install-IronPython.ps1 ~/.local/share/ironpython
20+
```
21+
22+
Run `help ./scripts/Install-IronPython` in PowerShell for more information about supported options.
23+
1624
## Command-line Usage
1725

1826
To start a command-line interpreter on Windows run `ipy.exe` (for .NET Framework) or `ipy.bat` (for .NET). On Posix systems, run `ipy.sh`. `ipy.sh` may be renamed to simply `ipy` for convenience.

Package/zip/Zip.Packaging.targets

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="Current">
33
<Target Name="ZipPackage" DependsOnTargets="Stage" AfterTargets="Package" Outputs="$(PackageDir)\IronPython.$(PackageVersion).zip;$(PackageDir)\IronPython.StdLib.$(PackageVersion).zip">
44
<MakeDir Directories="$(PackageDir)" Condition="!Exists('$(PackageDir)')"/>
55

66
<ItemGroup>
77
<ZipFiles Include="$(StageDir)\**\*.*" Exclude="$(StageDir)\README.md;$(StageDir)\**\*.pdb;$(StageDir)\netcoreapp2.1\**\*;$(StageDir)\net7.0*\**\*" />
88
<ZipFiles Include="README.md" Link="$(MSBuildThisFileDirectory)README.md" />
9+
<ZipFiles Include="scripts/Enter-IronPythonEnvironment.ps1" Link="$(RootDir)Src\Scripts\Enter-IronPythonEnvironment.ps1" />
10+
<ZipFiles Include="scripts/Install-IronPython.ps1" Link="$(RootDir)Src\Scripts\Install-IronPython.ps1" />
911
</ItemGroup>
1012
<Zip Files="@(ZipFiles)" ZipFileName="$(PackageDir)\IronPython.$(PackageVersion).zip" WorkingDirectory="$(StageDir)" />
1113

Src/Scripts/Install-IronPython.ps1

Lines changed: 80 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,79 @@
55

66
<#
77
.SYNOPSIS
8-
Install IronPython 3 for .NET 6 from an official zip file distributable.
8+
Install IronPython 3 from an official zip file distributable.
99
1010
.DESCRIPTION
11-
This script facilitates installation of IronPython on .NET 6 binaries from a zip file. The zip file is assumed to have content as published on the IronPython's download page. The zip file is produced by IronPython's "package" build target.
11+
This script facilitates installation of IronPython binaries from a zip file. The zip file is assumed to have content as published on the IronPython's download page. The zip file is produced by IronPython's "package" build target.
1212
1313
.EXAMPLE
14-
PS>./make
15-
PS>./make package
16-
PS>./Src/Scripts/Install-IronPython.ps1 env
1714
18-
These commands should be issued on a Powershell prompt with the current directory set to the project root.
19-
The project is first built, then packaged, and finally the script uses the zipfile produced during packaging to install IronPython in directory "env"
15+
PS>Invoke-WebRequest -Uri https://github.com/IronLanguages/ironpython3/releases/download/v3.4.0-beta1/IronPython.3.4.0-beta1.zip -OutFile IronPython.3.4.0-beta1.zip
16+
PS>Expand-Archive -Path IronPython.3.4.0-beta1.zip -DestinationPath IronPython-unzipped
17+
PS>./IronPython-unzipped/scripts/Install-IronPython -Path ~/ipyenv/v3.4.0-beta1
18+
19+
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-beta1.
2020
2121
.EXAMPLE
2222
2323
PS>Invoke-WebRequest -Uri https://github.com/IronLanguages/ironpython3/releases/download/v3.4.0-beta1/IronPython.3.4.0-beta1.zip -OutFile IronPython.3.4.0-beta1.zip
24-
PS>Install-IronPython -Path ~/ipyenv/v3.4.0-beta1 -ZipFile IronPython.3.4.0-beta1.zip -Force
24+
PS>Install-IronPython -Path ~/ipyenv/v3.4.0-beta1 -ZipFile IronPython.3.4.0-beta1.zip -Framework net462 -Force
2525
26-
The official binaries are downloaded from GitHub to the current directory and then the installation proceeds using the downloaded zip file. IronPython is installed into ~/ipyenv/v3.4.0-beta1, overwriting any previous installation in that location.
26+
The official binaries are downloaded from GitHub to the current directory and then the installation proceeds using the downloaded zip file. IronPython is installed into ~/ipyenv/v3.4.0-beta1, overwriting any previous installation in that location. IronPython binaries running on .NET Framework 4.6.2 are used during the installation.
2727
This example assumes that the installation script is in a directory on the search path ($env:PATH).
28+
29+
.EXAMPLE
30+
31+
PS>./make
32+
PS>./make package
33+
PS>./Src/Scripts/Install-IronPython.ps1 env
34+
35+
These commands should be issued on a Powershell prompt with the current directory set to the project root.
36+
The project is first built, then packaged, and finally the script uses the zipfile produced during packaging to install IronPython in directory "env".
37+
2838
#>
2939
[CmdletBinding()]
3040
Param(
3141
# Target directory to which IronPython is to be installed.
3242
[Parameter(Position=0, Mandatory)]
33-
[SupportsWildcards()]
3443
[string] $Path,
3544

3645
# The path to the downloaded zip file with IronPython binaries. If empty, the script will try to grab the package directly produced by the local build.
3746
[string] $ZipFile,
3847

48+
# The moniker of the .NET platform to install for.
49+
[string] $Framework = "net6.0",
50+
3951
# If the target path exists, it will be wiped clean beforehand.
4052
[switch] $Force
4153
)
4254

4355
$ErrorActionPreference = "Stop"
4456

45-
$defaultVersion = "3.4.0-beta1"
46-
4757
if (-not $ZipFile) {
48-
# If zipfile path not given, assume that the script is in the standard location within the source tree
49-
# and locate the zip archive in the standard location of the package target.
50-
$projectRoot = $PSScriptRoot | Split-Path | Split-Path
51-
$ZipFile = Join-Path $projectRoot "Package/Release/Packages/IronPython-$defaultVersion/IronPython.$defaultVersion.zip"
58+
# If zipfile path not given, try to locate it
59+
$splitPSScriptRoot = $PSScriptRoot -split "\$([IO.Path]::DirectorySeparatorChar)"
60+
if ($splitPSScriptRoot[-1] -eq "scripts" -and (Test-Path (Join-Path (Split-Path $PSScriptRoot) "lib"))) {
61+
# Script run from within already expanded zip file
62+
$unzipDir = $PSScriptRoot | Split-Path
63+
} elseif ($splitPSScriptRoot[-2] -eq "Src" -and $splitPSScriptRoot[-1] -eq "Scripts") {
64+
# Script run from within a checked out code base
65+
# Locate the zip archive in the standard location of the package target
66+
$projectRoot = $PSScriptRoot | Split-Path | Split-Path
67+
$ZipFile = @(Resolve-Path (Join-Path $projectRoot "Package/Release/Packages/IronPython-*/IronPython.3.*.zip"))
68+
if ($ZipFile.Count -gt 1) {
69+
Write-Error "Ambiguous implicit project zip file: $ZipFile"
70+
} elseif ($ZipFile.Count -lt 1) {
71+
Write-Error "Missing zip file. Have you run './make package'?"
72+
}
73+
} else {
74+
Write-Error "Cannot locate implicit zip file. Provide path to the zip file using '-ZipFile <path>'."
75+
}
76+
} elseif (-not (Test-Path $ZipFile)) {
77+
Write-Error "ZipFile not found: $ZipFile"
5278
}
5379

80+
# Prepare destination path
5481
if (Test-Path $Path) {
5582
if ($Force) {
5683
if ((Resolve-Path $Path).Count -gt 1) {
@@ -61,45 +88,50 @@ if (Test-Path $Path) {
6188
Write-Error "Path already exists: $Path"
6289
}
6390
}
91+
New-Item $Path -ItemType Directory | Out-Null
6492

65-
# Unzip archive and move files into place
66-
$unzipDir = Join-Path $Path "zip"
93+
# Unzip archive
94+
if (-not $unzipDir) {
95+
$unzipDir = Join-Path $Path "unzipped"
96+
Expand-Archive -Path $ZipFile -DestinationPath $unzipDir
97+
$unzipped = $true
98+
}
6799

68-
Expand-Archive -Path $ZipFile -DestinationPath $unzipDir
69-
Move-Item -Path (Join-Path $unzipDir "lib") -Destination $Path
70-
Move-Item -Path (Join-Path $unzipDir "net6.0/*") -Destination $Path -Exclude "*.xml","*.dll.config"
71-
Remove-Item -Path $unzipDir -Recurse
100+
# Copy files into place
101+
Copy-Item -Path (Join-Path $unzipDir $Framework "*") -Destination $Path -Recurse
102+
Copy-Item -Path (Join-Path $unzipDir "lib") -Destination $Path
72103

73-
# Create a startup script
74-
$ipyPath = Join-Path $Path "ipy.ps1"
75-
Set-Content -Path $ipyPath -Value @'
104+
# Prepare startup scripts
105+
if ($Framework -notlike "net4*") {
106+
$ipyPath = Join-Path $Path "ipy.ps1"
107+
Set-Content -Path $ipyPath -Value @'
76108
#!/usr/bin/env pwsh
77109
dotnet (Join-Path $PSScriptRoot ipy.dll) @args
78110
'@
79-
if ($IsMacOS -or $IsLinux) {
111+
if ($IsMacOS -or $IsLinux) {
112+
chmod +x $ipyPath
113+
chmod +x (Join-Path $Path "ipy.sh")
114+
Move-Item -Path (Join-Path $Path "ipy.sh") -Destination (Join-Path $Path "ipy")
115+
Remove-Item -Path (Join-Path $Path "ipy.bat")
116+
}
117+
} elseif ($IsMacOS -or $IsLinux) { # Mono
118+
$ipyPath = Join-Path $Path "ipy"
119+
Set-Content -Path $ipyPath -Value @'
120+
#!/bin/sh
121+
BASEDIR=$(dirname "$0")
122+
ABS_PATH=$(cd "$BASEDIR"; pwd)
123+
mono "$ABS_PATH/ipy.exe" "$@"
124+
'@
80125
chmod +x $ipyPath
81-
chmod +x (Join-Path $Path "ipy.sh")
82126
}
83127

84-
# Add items that are missing in the zip file, directly from the bin directory
85-
if ($projectRoot) {
86-
$binPath = Join-Path $projectRoot "bin/Release/net6.0"
87-
Copy-Item (Join-Path $projectRoot "Src/Scripts/Enter-IronPythonEnvironment.ps1") $Path
88-
if ($IsWindows){
89-
Copy-Item (Join-Path $binPath "ipy.exe") $Path
90-
} else {
91-
Copy-Item (Join-Path $binPath "ipy") $Path
92-
Copy-Item (Join-Path $binPath "Mono.Unix.dll") $Path
93-
$arch = uname -m
94-
switch ($arch) {
95-
"x86_64" { $arch = "x64" }
96-
}
97-
if ($IsMacOS) {
98-
$os = "osx"
99-
} else {
100-
$os = "linux"
101-
}
102-
$libs = Join-Path $binPath "runtimes" "$os-$arch" "native/*" -Resolve
103-
Copy-Item $libs $Path
104-
}
128+
# Install additional scripts
129+
Copy-Item -Path (Join-Path $unzipDir "scripts/Enter-IronPythonEnvironment.ps1") -Destination $Path
130+
if ($IsMacOS -or $IsLinux) {
131+
chmod -x (Join-Path $Path "Enter-IronPythonEnvironment.ps1")
132+
}
133+
134+
# Clean up unzipped files
135+
if ($unzipped) {
136+
Remove-Item -Path $unzipDir -Recurse
105137
}

0 commit comments

Comments
 (0)