Skip to content

Commit 5c851d6

Browse files
MaksimZhukovvmapetrMaksimZhukovMaxim Lobanov
authored
Add support for unstable Python versions (actions#38)
* Add support of unstable versions to package generation (#2) * Add support of symver versions to Python setup scripts and tests Co-authored-by: Maksim Petrov <[email protected]> Co-authored-by: MaksimZhukov <[email protected]> Co-authored-by: Maxim Lobanov <[email protected]>
1 parent 67794a4 commit 5c851d6

17 files changed

+193
-74
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Manifest config tests
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
paths-ignore:
7+
- 'versions-manifest.json'
8+
9+
jobs:
10+
RunTests:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
with:
16+
submodules: true
17+
18+
- name: Install Pester
19+
shell: pwsh
20+
run: |
21+
Install-Module Pester -Force -Scope CurrentUser
22+
23+
- name: Run tests
24+
shell: pwsh
25+
run: |
26+
Import-Module Pester
27+
Invoke-Pester -Configuration @{
28+
Run = @{
29+
Path = "tests/ManifestConfig.Tests.ps1"
30+
Exit = $true
31+
}
32+
}

azure-pipelines/templates/build-job.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
targetType: filePath
1515
filePath: './builders/build-python.ps1'
1616
arguments: '-Version $(VERSION) -Platform $(Platform) -Architecture $(Architecture)'
17+
pwsh: true
1718

1819
- task: PublishPipelineArtifact@1
1920
displayName: 'Publish Artifact: Python $(VERSION)'

azure-pipelines/templates/test-job.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ jobs:
33
pool:
44
name: Azure Pipelines
55
vmImage: $(VmImage)
6+
variables:
7+
TestRunTitle: 'python-$(Platform)-$(Architecture)'
68
steps:
79
- checkout: self
810
submodules: true

builders/build-python.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ Required parameter. The platform for which Python will be built.
2121
#>
2222

2323
param(
24-
[Parameter (Mandatory=$true)][Version] $Version,
24+
[Parameter (Mandatory=$true)][semver] $Version,
2525
[Parameter (Mandatory=$true)][string] $Platform,
2626
[string] $Architecture = "x64"
2727
)
2828

2929
Import-Module (Join-Path $PSScriptRoot "../helpers" | Join-Path -ChildPath "common-helpers.psm1") -DisableNameChecking
3030
Import-Module (Join-Path $PSScriptRoot "../helpers" | Join-Path -ChildPath "nix-helpers.psm1") -DisableNameChecking
3131
Import-Module (Join-Path $PSScriptRoot "../helpers" | Join-Path -ChildPath "win-helpers.psm1") -DisableNameChecking
32+
Import-Module (Join-Path $PSScriptRoot "python-version.psm1") -DisableNameChecking
3233

3334
function Get-PythonBuilder {
3435
<#
@@ -49,13 +50,12 @@ function Get-PythonBuilder {
4950
5051
#>
5152

52-
param (
53-
[version] $Version,
53+
param(
54+
[semver] $Version,
5455
[string] $Architecture,
5556
[string] $Platform
5657
)
5758

58-
$Platform = $Platform.ToLower()
5959
if ($Platform -match 'win32') {
6060
$builder = [WinPythonBuilder]::New($Version, $Architecture, $Platform)
6161
} elseif ($Platform -match 'linux') {
@@ -71,5 +71,5 @@ function Get-PythonBuilder {
7171
}
7272

7373
### Create Python builder instance, and build artifact
74-
$Builder = Get-PythonBuilder -Version $Version -Architecture $Architecture -Platform $Platform
74+
$Builder = Get-PythonBuilder -Version $Version -Architecture $Architecture -Platform $Platform
7575
$Builder.Build()

builders/macos-python-builder.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class macOSPythonBuilder : NixPythonBuilder {
1717
#>
1818

1919
macOSPythonBuilder(
20-
[version] $version,
20+
[semver] $version,
2121
[string] $architecture,
2222
[string] $platform
2323
) : Base($version, $architecture, $platform) { }

builders/nix-python-builder.psm1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ class NixPythonBuilder : PythonBuilder {
3333
[string] $OutputArtifactName
3434

3535
NixPythonBuilder(
36-
[version] $version,
36+
[semver] $version,
3737
[string] $architecture,
3838
[string] $platform
3939
) : Base($version, $architecture, $platform) {
4040
$this.InstallationTemplateName = "nix-setup-template.sh"
4141
$this.InstallationScriptName = "setup.sh"
42-
4342
$this.OutputArtifactName = "python-$Version-$Platform-$Architecture.tar.gz"
4443
}
4544

@@ -50,8 +49,10 @@ class NixPythonBuilder : PythonBuilder {
5049
#>
5150

5251
$base = $this.GetBaseUri()
52+
$versionName = $this.GetBaseVersion()
53+
$nativeVersion = Convert-Version -version $this.Version
5354

54-
return "${base}/$($this.Version)/Python-$($this.Version).tgz"
55+
return "${base}/${versionName}/Python-${nativeVersion}.tgz"
5556
}
5657

5758
[string] GetPythonBinary() {
@@ -95,9 +96,7 @@ class NixPythonBuilder : PythonBuilder {
9596
$installationTemplateContent = Get-Content -Path $installationTemplateLocation -Raw
9697

9798
$variablesToReplace = @{
98-
"{{__VERSION_MAJOR__}}" = $this.Version.Major;
99-
"{{__VERSION_MINOR__}}" = $this.Version.Minor;
100-
"{{__VERSION_BUILD__}}" = $this.Version.Build;
99+
"{{__VERSION_FULL__}}" = $this.Version;
101100
}
102101
$variablesToReplace.keys | ForEach-Object { $installationTemplateContent = $installationTemplateContent.Replace($_, $variablesToReplace[$_]) }
103102

builders/python-builder.psm1

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class PythonBuilder {
2929
3030
#>
3131

32-
[version] $Version
32+
[semver] $Version
3333
[string] $Architecture
3434
[string] $Platform
3535
[string] $HostedToolcacheLocation
@@ -38,17 +38,17 @@ class PythonBuilder {
3838
[string] $ArtifactFolderLocation
3939
[string] $InstallationTemplatesLocation
4040

41-
PythonBuilder ([version] $version, [string] $architecture, [string] $platform) {
42-
$this.Version = $version
43-
$this.Architecture = $architecture
44-
$this.Platform = $platform
41+
PythonBuilder ([semver] $version, [string] $architecture, [string] $platform) {
42+
$this.InstallationTemplatesLocation = Join-Path -Path $PSScriptRoot -ChildPath "../installers"
4543

4644
$this.HostedToolcacheLocation = $env:AGENT_TOOLSDIRECTORY
4745
$this.TempFolderLocation = $env:BUILD_SOURCESDIRECTORY
4846
$this.WorkFolderLocation = $env:BUILD_BINARIESDIRECTORY
4947
$this.ArtifactFolderLocation = $env:BUILD_STAGINGDIRECTORY
5048

51-
$this.InstallationTemplatesLocation = Join-Path -Path $PSScriptRoot -ChildPath "../installers"
49+
$this.Version = $version
50+
$this.Architecture = $architecture
51+
$this.Platform = $platform
5252
}
5353

5454
[uri] GetBaseUri() {
@@ -79,11 +79,21 @@ class PythonBuilder {
7979
return "$pythonToolcacheLocation/$($this.Version)/$($this.Architecture)"
8080
}
8181

82+
[string] GetBaseVersion() {
83+
<#
84+
.SYNOPSIS
85+
Return Major.Minor.Patch version string.
86+
#>
87+
88+
return "$($this.Version.Major).$($this.Version.Minor).$($this.Version.Patch)"
89+
}
90+
8291
[void] PreparePythonToolcacheLocation() {
8392
<#
8493
.SYNOPSIS
8594
Prepare system hostedtoolcache folder for new Python version.
8695
#>
96+
8797
$pythonBinariesLocation = $this.GetFullPythonToolcacheLocation()
8898

8999
if (Test-Path $pythonBinariesLocation) {

builders/python-version.psm1

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function Convert-Label() {
2+
<#
3+
.SYNOPSIS
4+
Convert generic semver label to native Python label.
5+
#>
6+
7+
param(
8+
[Parameter(Mandatory)]
9+
[string] $label
10+
)
11+
12+
switch ($label) {
13+
"alpha" { return "a" }
14+
"beta" { return "b" }
15+
"rc" { return "rc" }
16+
default { throw "Invalid version label '$label'" }
17+
}
18+
}
19+
20+
function Convert-Version {
21+
<#
22+
.SYNOPSIS
23+
Convert generic semver version to native Python version.
24+
#>
25+
26+
param(
27+
[Parameter(Mandatory)]
28+
[semver] $version,
29+
[char] $delimiter = "."
30+
)
31+
32+
$nativeVersion = "{0}.{1}.{2}" -f $version.Major, $version.Minor, $version.Patch
33+
34+
if ($version.PreReleaseLabel)
35+
{
36+
$preReleaseLabel = $version.PreReleaseLabel.Split($delimiter)
37+
38+
$preReleaseLabelName = Convert-Label -Label $preReleaseLabel[0]
39+
$preReleaseLabelVersion = $preReleaseLabel[1]
40+
41+
$nativeVersion += "${preReleaseLabelName}${preReleaseLabelVersion}"
42+
}
43+
44+
return $nativeVersion
45+
}

builders/ubuntu-python-builder.psm1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class UbuntuPythonBuilder : NixPythonBuilder {
1717
#>
1818

1919
UbuntuPythonBuilder(
20-
[version] $version,
20+
[semver] $version,
2121
[string] $architecture,
2222
[string] $platform
2323
) : Base($version, $architecture, $platform) { }
@@ -68,6 +68,7 @@ class UbuntuPythonBuilder : NixPythonBuilder {
6868
} else {
6969
$tkinterInstallString = "sudo apt install -y python-tk tk-dev"
7070
}
71+
7172
Execute-Command -Command $tkinterInstallString
7273

7374
### Install dependent packages

builders/win-python-builder.psm1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class WinPythonBuilder : PythonBuilder {
2727
[string] $OutputArtifactName
2828

2929
WinPythonBuilder(
30-
[version] $version,
30+
[semver] $version,
3131
[string] $architecture,
3232
[string] $platform
3333
) : Base($version, $architecture, $platform) {
@@ -72,10 +72,12 @@ class WinPythonBuilder : PythonBuilder {
7272
#>
7373

7474
$base = $this.GetBaseUri()
75+
$versionName = $this.GetBaseVersion()
76+
$nativeVersion = Convert-Version -version $this.Version
7577
$architecture = $this.GetArchitectureExtension()
7678
$extension = $this.GetPythonExtension()
7779

78-
$uri = "${base}/$($this.Version)/python-$($this.Version)${architecture}${extension}"
80+
$uri = "${base}/${versionName}/python-${nativeVersion}${architecture}${extension}"
7981

8082
return $uri
8183
}

0 commit comments

Comments
 (0)