From 137e68f5a835c253e6a1597be49c35e7f7fd7d28 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 31 Mar 2020 11:20:42 -0500 Subject: [PATCH 01/10] [ci] reduced duplication in Python Windows CI --- .appveyor.yml | 44 +++++++++++++------------------------------- .ci/test_windows.ps1 | 26 +++++++++++++++++++++++--- .vsts-ci.yml | 12 +++++++----- 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 990d36953dd1..920feeb89f74 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -8,7 +8,11 @@ configuration: # a trick to construct a build matrix with multiple Python versi environment: matrix: - COMPILER: MSVC + TASK: appveyor-python + CONDA_ENV: test-env - COMPILER: MINGW + TASK: appveyor-python + CONDA_ENV: test-env clone_depth: 5 @@ -19,39 +23,17 @@ install: - set PYTHON_VERSION=%CONFIGURATION% - ps: >- switch ($env:PYTHON_VERSION) { - "2.7" {$env:MINICONDA = """C:\Miniconda-x64"""} - "3.5" {$env:MINICONDA = """C:\Miniconda35-x64"""} - "3.6" {$env:MINICONDA = """C:\Miniconda36-x64"""} - "3.7" {$env:MINICONDA = """C:\Miniconda37-x64"""} - default {$env:MINICONDA = """C:\Miniconda37-x64"""} + "2.7" {$env:MINICONDA = "C:\Miniconda-x64"} + "3.5" {$env:MINICONDA = "C:\Miniconda35-x64"} + "3.6" {$env:MINICONDA = "C:\Miniconda36-x64"} + "3.7" {$env:MINICONDA = "C:\Miniconda37-x64"} + default {$env:MINICONDA = "C:\Miniconda37-x64"} } - - set PATH=%MINICONDA%;%MINICONDA%\Scripts;%PATH% + $env:PATH="$env:MINICONDA;$env:MINICONDA\Scripts;$env:PATH" - ps: $env:LGB_VER = (Get-Content VERSION.txt).trim() - - activate - - conda config --set always_yes yes --set changeps1 no - - conda update -q -y conda - - conda create -q -y -n test-env python=%PYTHON_VERSION% joblib matplotlib numpy pandas psutil pytest python-graphviz "scikit-learn<=0.21.3" scipy - - activate test-env -build_script: - - cd %APPVEYOR_BUILD_FOLDER%\python-package - - IF "%COMPILER%"=="MINGW" ( - python setup.py install --mingw) - ELSE ( - python setup.py install) +build: false test_script: - - pytest %APPVEYOR_BUILD_FOLDER%\tests\python_package_test - - cd %APPVEYOR_BUILD_FOLDER%\examples\python-guide - - ps: >- - @("import matplotlib", "matplotlib.use('Agg')") + (Get-Content "plot_example.py") | Set-Content "plot_example.py" # prevent interactive window mode - (Get-Content "plot_example.py").replace('graph.render(view=True)', 'graph.render(view=False)') | Set-Content "plot_example.py" - - ps: >- - foreach ($file in @(Get-ChildItem *.py)) { - @("import sys, warnings", "warnings.showwarning = lambda message, category, filename, lineno, file=None, line=None: sys.stdout.write(warnings.formatwarning(message, category, filename, lineno, line))") + (Get-Content $file) | Set-Content $file - python $file - if (!$?) { $host.SetShouldExit(-1) } - } # run all examples - - cd %APPVEYOR_BUILD_FOLDER%\examples\python-guide\notebooks - - conda install -q -y -n test-env ipywidgets notebook - - jupyter nbconvert --ExecutePreprocessor.timeout=180 --to notebook --execute --inplace *.ipynb # run all notebooks + - conda init powershell + - poowershell.exe -ExecutionPolicy Bypass -File .\.ci\test_windows.ps1 diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index cf34af079268..84118925de63 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -6,6 +6,19 @@ function Check-Output { } } +# unify environment variables for Azure devops and AppVeyor +if (Test-Path env:APPVEYOR) { + $env:BUILD_SOURCESDIRECTORY = $env:APPVEYOR_BUILD_FOLDER +} + +# setup for Python +conda init powershell +conda activate +conda config --set always_yes yes --set changeps1 no +conda update -q -y conda +conda create -q -y -n $env:CONDA_ENV python=$env:PYTHON_VERSION joblib matplotlib numpy pandas psutil pytest python-graphviz "scikit-learn<=0.21.3" scipy wheel ; Check-Output $? +conda activate $env:CONDA_ENV + if ($env:TASK -eq "regular") { mkdir $env:BUILD_SOURCESDIRECTORY/build; cd $env:BUILD_SOURCESDIRECTORY/build cmake -A x64 .. ; cmake --build . --target ALL_BUILD --config Release ; Check-Output $? @@ -33,15 +46,22 @@ elseif ($env:TASK -eq "bdist") { python setup.py bdist_wheel --plat-name=win-amd64 --universal ; Check-Output $? cd dist; pip install @(Get-ChildItem *.whl) ; Check-Output $? cp @(Get-ChildItem *.whl) $env:BUILD_ARTIFACTSTAGINGDIRECTORY +} elseif ($env:TASK -eq "appveyor-python") { + cd $env:BUILD_SOURCESDIRECTORY\python-package + if ($env:COMPILER -eq "MINGW") { + python setup.py install --mingw | Check-Output $? + } else { + python setup.py install | Check-Output $? + } } -$tests = $env:BUILD_SOURCESDIRECTORY + $(If ($env:TASK -eq "sdist") {"/tests/python_package_test"} Else {"/tests"}) # cannot test C API with "sdist" task +$tests = $env:BUILD_SOURCESDIRECTORY + $(If (($env:TASK -eq "sdist") -or ($env:TASK -eq "appveyor-python")) {"/tests/python_package_test"} Else {"/tests"}) # cannot test C API with "sdist" task pytest $tests ; Check-Output $? -if ($env:TASK -eq "regular") { +if (($env:TASK -eq "regular") -or ($env:TASK -eq "appveyor-python")) { cd $env:BUILD_SOURCESDIRECTORY/examples/python-guide @("import matplotlib", "matplotlib.use('Agg')") + (Get-Content "plot_example.py") | Set-Content "plot_example.py" - (Get-Content "plot_example.py").replace('graph.render(view=True)', 'graph.render(view=False)') | Set-Content "plot_example.py" + (Get-Content "plot_example.py").replace('graph.render(view=True)', 'graph.render(view=False)') | Set-Content "plot_example.py" # prevent interactive window mode foreach ($file in @(Get-ChildItem *.py)) { @("import sys, warnings", "warnings.showwarning = lambda message, category, filename, lineno, file=None, line=None: sys.stdout.write(warnings.formatwarning(message, category, filename, lineno, line))") + (Get-Content $file) | Set-Content $file python $file ; Check-Output $? diff --git a/.vsts-ci.yml b/.vsts-ci.yml index e004b56d5500..74d8d0ee4f82 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -108,7 +108,7 @@ jobs: - task: PublishBuildArtifacts@1 condition: and(succeeded(), in(variables['TASK'], 'regular', 'sdist', 'bdist'), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/'))) inputs: - pathtoPublish: '$(Build.ArtifactStagingDirectory)' + pathtoPublish: '$(Build.ArtifactStagingDirectory)' artifactName: PackageAssets artifactType: container ########################################### @@ -129,11 +129,13 @@ jobs: TASK: bdist PYTHON_VERSION: 3.5 steps: - - powershell: Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" - displayName: Enable conda + - powershell: | + Write-Host "##vso[task.prependpath]$env:CONDA\Scripts" + Write-Host "##vso[task.setvariable variable=AZURE]true" + displayName: 'Set Variables' - script: | - cmd /c 'activate & conda config --set always_yes yes --set changeps1 no & conda update -q -y conda & conda create -q -y -n %CONDA_ENV% python=%PYTHON_VERSION% joblib matplotlib numpy pandas psutil pytest python-graphviz "scikit-learn<=0.21.3" scipy' - cmd /c "activate %CONDA_ENV% & powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/test_windows.ps1" + cmd /c "conda init powershell" + cmd /c "powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/test_windows.ps1" displayName: Test - task: PublishBuildArtifacts@1 condition: and(succeeded(), in(variables['TASK'], 'regular', 'sdist', 'bdist'), not(startsWith(variables['Build.SourceBranch'], 'refs/pull/'))) From 69c280a845edeb644b64b94cbb1a1078403bf909 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 31 Mar 2020 11:43:02 -0500 Subject: [PATCH 02/10] fixed typo --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 920feeb89f74..9d1890005b10 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -36,4 +36,4 @@ build: false test_script: - conda init powershell - - poowershell.exe -ExecutionPolicy Bypass -File .\.ci\test_windows.ps1 + - powershell.exe -ExecutionPolicy Bypass -File .\.ci\test_windows.ps1 From 79c48abcf9ad0ae2c843b033e99587562ea90687 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 31 Mar 2020 15:24:17 -0500 Subject: [PATCH 03/10] reorganized --- .ci/test_windows.ps1 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 84118925de63..53b4bd82486e 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -8,6 +8,7 @@ function Check-Output { # unify environment variables for Azure devops and AppVeyor if (Test-Path env:APPVEYOR) { + $env:APPVEYOR = "true" $env:BUILD_SOURCESDIRECTORY = $env:APPVEYOR_BUILD_FOLDER } @@ -46,7 +47,7 @@ elseif ($env:TASK -eq "bdist") { python setup.py bdist_wheel --plat-name=win-amd64 --universal ; Check-Output $? cd dist; pip install @(Get-ChildItem *.whl) ; Check-Output $? cp @(Get-ChildItem *.whl) $env:BUILD_ARTIFACTSTAGINGDIRECTORY -} elseif ($env:TASK -eq "appveyor-python") { +} elseif (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python")) { cd $env:BUILD_SOURCESDIRECTORY\python-package if ($env:COMPILER -eq "MINGW") { python setup.py install --mingw | Check-Output $? @@ -55,10 +56,15 @@ elseif ($env:TASK -eq "bdist") { } } -$tests = $env:BUILD_SOURCESDIRECTORY + $(If (($env:TASK -eq "sdist") -or ($env:TASK -eq "appveyor-python")) {"/tests/python_package_test"} Else {"/tests"}) # cannot test C API with "sdist" task +if (($env:TASK -eq "sdist") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { + $tests = $env:BUILD_SOURCESDIRECTORY + "/tests/python_package_test" +} else { + # cannot test C API with "sdist" task + $tests = $env:BUILD_SOURCESDIRECTORY + "/tests" +} pytest $tests ; Check-Output $? -if (($env:TASK -eq "regular") -or ($env:TASK -eq "appveyor-python")) { +if (($env:TASK -eq "regular") -or (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python"))) { cd $env:BUILD_SOURCESDIRECTORY/examples/python-guide @("import matplotlib", "matplotlib.use('Agg')") + (Get-Content "plot_example.py") | Set-Content "plot_example.py" (Get-Content "plot_example.py").replace('graph.render(view=True)', 'graph.render(view=False)') | Set-Content "plot_example.py" # prevent interactive window mode From a331e2b1a13da7a9b82ae2d37b2677499d2bd8af Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 31 Mar 2020 15:30:55 -0500 Subject: [PATCH 04/10] fixed task name --- .appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 9d1890005b10..583ad6276079 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -8,10 +8,10 @@ configuration: # a trick to construct a build matrix with multiple Python versi environment: matrix: - COMPILER: MSVC - TASK: appveyor-python + TASK: python CONDA_ENV: test-env - COMPILER: MINGW - TASK: appveyor-python + TASK: python CONDA_ENV: test-env clone_depth: 5 From eaac8bf0919bd23f2f4d3da4e4090bfa891670c8 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 1 Apr 2020 05:03:45 +0100 Subject: [PATCH 05/10] Update .ci/test_windows.ps1 Co-Authored-By: Nikita Titov --- .ci/test_windows.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 53b4bd82486e..66c9638ee06a 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -50,7 +50,7 @@ elseif ($env:TASK -eq "bdist") { } elseif (($env:APPVEYOR -eq "true") -and ($env:TASK -eq "python")) { cd $env:BUILD_SOURCESDIRECTORY\python-package if ($env:COMPILER -eq "MINGW") { - python setup.py install --mingw | Check-Output $? + python setup.py install --mingw ; Check-Output $? } else { python setup.py install | Check-Output $? } From 64ef6ac6aeac47d443b9079547dd58d6091c8b5c Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 31 Mar 2020 23:13:08 -0500 Subject: [PATCH 06/10] changes from code review --- .appveyor.yml | 4 +--- .ci/test_windows.ps1 | 2 +- .vsts-ci.yml | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 583ad6276079..bac0dfb04bd0 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -9,10 +9,8 @@ environment: matrix: - COMPILER: MSVC TASK: python - CONDA_ENV: test-env - COMPILER: MINGW TASK: python - CONDA_ENV: test-env clone_depth: 5 @@ -21,6 +19,7 @@ install: - set PATH=%PATH:C:\Program Files\Git\usr\bin;=% # delete sh.exe from PATH (mingw32-make fix) - set PATH=C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;%PATH% - set PYTHON_VERSION=%CONFIGURATION% + - set CONDA_ENV="test-env" - ps: >- switch ($env:PYTHON_VERSION) { "2.7" {$env:MINICONDA = "C:\Miniconda-x64"} @@ -35,5 +34,4 @@ install: build: false test_script: - - conda init powershell - powershell.exe -ExecutionPolicy Bypass -File .\.ci\test_windows.ps1 diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index 66c9638ee06a..c8081381a4da 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -17,7 +17,7 @@ conda init powershell conda activate conda config --set always_yes yes --set changeps1 no conda update -q -y conda -conda create -q -y -n $env:CONDA_ENV python=$env:PYTHON_VERSION joblib matplotlib numpy pandas psutil pytest python-graphviz "scikit-learn<=0.21.3" scipy wheel ; Check-Output $? +conda create -q -y -n $env:CONDA_ENV python=$env:PYTHON_VERSION joblib matplotlib numpy pandas psutil pytest python-graphviz "scikit-learn<=0.21.3" scipy ; Check-Output $? conda activate $env:CONDA_ENV if ($env:TASK -eq "regular") { diff --git a/.vsts-ci.yml b/.vsts-ci.yml index 74d8d0ee4f82..2da352c8df9f 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -134,7 +134,6 @@ jobs: Write-Host "##vso[task.setvariable variable=AZURE]true" displayName: 'Set Variables' - script: | - cmd /c "conda init powershell" cmd /c "powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/test_windows.ps1" displayName: Test - task: PublishBuildArtifacts@1 From 109e152cd5dea022e0b769f9fc900a5d7f3434c3 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Tue, 31 Mar 2020 23:56:50 -0500 Subject: [PATCH 07/10] added conda init powershell back --- .appveyor.yml | 1 + .vsts-ci.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index bac0dfb04bd0..18d5ab66d09f 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -34,4 +34,5 @@ install: build: false test_script: + - conda init powershell - powershell.exe -ExecutionPolicy Bypass -File .\.ci\test_windows.ps1 diff --git a/.vsts-ci.yml b/.vsts-ci.yml index 2da352c8df9f..74d8d0ee4f82 100644 --- a/.vsts-ci.yml +++ b/.vsts-ci.yml @@ -134,6 +134,7 @@ jobs: Write-Host "##vso[task.setvariable variable=AZURE]true" displayName: 'Set Variables' - script: | + cmd /c "conda init powershell" cmd /c "powershell -ExecutionPolicy Bypass -File %BUILD_SOURCESDIRECTORY%/.ci/test_windows.ps1" displayName: Test - task: PublishBuildArtifacts@1 From 4a194da3c1c0e93535ce6ad82f3d48288973c3c5 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 1 Apr 2020 16:57:34 +0100 Subject: [PATCH 08/10] Update .ci/test_windows.ps1 Co-Authored-By: Nikita Titov --- .ci/test_windows.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/test_windows.ps1 b/.ci/test_windows.ps1 index c8081381a4da..1d6624fa344c 100644 --- a/.ci/test_windows.ps1 +++ b/.ci/test_windows.ps1 @@ -52,7 +52,7 @@ elseif ($env:TASK -eq "bdist") { if ($env:COMPILER -eq "MINGW") { python setup.py install --mingw ; Check-Output $? } else { - python setup.py install | Check-Output $? + python setup.py install ; Check-Output $? } } From 70525bd2708289d78de748ca7f669f735becc519 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 1 Apr 2020 11:01:24 -0500 Subject: [PATCH 09/10] Switched to absolute paths --- .appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 18d5ab66d09f..b4f6ca56cce2 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -29,10 +29,10 @@ install: default {$env:MINICONDA = "C:\Miniconda37-x64"} } $env:PATH="$env:MINICONDA;$env:MINICONDA\Scripts;$env:PATH" - - ps: $env:LGB_VER = (Get-Content VERSION.txt).trim() + - ps: $env:LGB_VER = (Get-Content $env:APPVEYOR_BUILD_FOLDER\VERSION.txt).trim() build: false test_script: - conda init powershell - - powershell.exe -ExecutionPolicy Bypass -File .\.ci\test_windows.ps1 + - powershell.exe -ExecutionPolicy Bypass -File $env:APPVEYOR_BUILD_FOLDER\.ci\test_windows.ps1 From 6ee3bd103271930e47c8f08c3e4b87ba25cf9278 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Wed, 1 Apr 2020 11:26:16 -0500 Subject: [PATCH 10/10] fixed env variables --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index b4f6ca56cce2..f8cd85f17dcb 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -35,4 +35,4 @@ build: false test_script: - conda init powershell - - powershell.exe -ExecutionPolicy Bypass -File $env:APPVEYOR_BUILD_FOLDER\.ci\test_windows.ps1 + - powershell.exe -ExecutionPolicy Bypass -File %APPVEYOR_BUILD_FOLDER%\.ci\test_windows.ps1