Skip to content

Commit

Permalink
Fix build-install.ps1 for Win10 compatibility
Browse files Browse the repository at this point in the history
Fix tools/build-install.ps1 to work with Windows 10
and python 3.7.4.
Python 3.7.4 has an odd choice of pip install location. So add
helper tools/ci/PATH-add-pip-site.ps1.
  • Loading branch information
jtmoon79 committed Jul 11, 2020
1 parent 0ec4db3 commit a800891
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
19 changes: 12 additions & 7 deletions tools/build-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ function Get-Command-Safely {

#
# make a good effort to get the path to the local python 3 installation
# if $PTYHON is set, assume it's the PYTHON interpreter
#
Foreach ($pythonpath in @("$env:PYTHON", # if $PTYHON is set, assume it's the PYTHON interpreter
Foreach ($pythonpath in @("$PYTHON",
"$env:PYTHON",
'python3.7',
'python3.7.exe',
'C:\Windows\py.exe',
Expand Down Expand Up @@ -88,13 +90,16 @@ if (-not (Test-Path-Safely $cv_whl)) {
& $PYTHON -m twine check $cv_whl
if ($LASTEXITCODE) { exit $LASTEXITCODE }

#
# install the wheel (must be done outside the project directory)
Push-Location ..
#

& $PYTHON -m pip install -v $cv_whl
if ($LASTEXITCODE) { exit $LASTEXITCODE }
# add user.site to $env:PATH so it runs and avoids PATH warning
.\tools\ci\PATH-add-pip-site.ps1

& $PACKAGE_NAME --version
Push-Location ..

& $PYTHON -m pip install --force-reinstall --user --disable-pip-version-check -v $cv_whl
if ($LASTEXITCODE) { exit $LASTEXITCODE }

#
Expand All @@ -116,12 +121,12 @@ if ($LASTEXITCODE) { exit $LASTEXITCODE }
Write-Host "
To uninstall remaining package:
$PYTHON -m pip uninstall -y '$PACKAGE_NAME'
& `$PYTHON -m pip uninstall -y '$PACKAGE_NAME'
"

Write-Host "Success!
To upload to pypi:
$PYTHON -m twine upload --verbose $cv_whl
& `$PYTHON -m twine upload --verbose $cv_whl
"
2 changes: 1 addition & 1 deletion tools/build-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fi
user_arg=''
fi
set -x
${PYTHON} -m pip install ${user_arg} --verbose "${cv_whl}"
${PYTHON} -m pip install --disable-pip-version-check ${user_arg} --verbose "${cv_whl}"
)

# make sure to attempt uninstall if asked
Expand Down
29 changes: 29 additions & 0 deletions tools/ci/PATH-add-pip-site.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# PATH-add-pip-site.ps1

# update PATH with potential pip install locations on a Windows host
function add_pip_site_PATH {
# presumes $PYTHON is set to the desired python interpreter
$usersite = & $PYTHON -c 'import site; print(site.USER_SITE);'
$userbase = & $PYTHON -c 'import site; print(site.USER_BASE);'
$userbasescript1 = Join-Path -Path "$userbase" -ChildPath "Script"
# --user install location on Windows 10 is annoyingly specific and not
# available in site module
$userbasescript2 = Join-Path -Path "$userbase" -ChildPath (& $PYTHON -c 'import sys; print(\"Python\" + str(sys.version_info[0]) + str(sys.version_info[1]));')
$userbasescript3 = Join-Path -Path "$userbasescript2" -ChildPath "Scripts"
$paths = $env:PATH.Split($([IO.Path]::PathSeparator))
ForEach ($path_ in @("$usersite",
"$userbase",
"$userbasescript1",
"$userbasescript2",
"$userbasescript3"))
{
if ($paths -contains $path_) {
Write-Debug "skip adding to env:PATH '$path_'"
continue
}
$env:PATH += "$([IO.Path]::PathSeparator)$path_"
Write-Debug "added to env:PATH '$path_'"
}
}

add_pip_site_PATH

0 comments on commit a800891

Please sign in to comment.