Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python path discovery if not called python #3330

Merged
merged 17 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .azure-pipelines/jobs/run-tests-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ steps:
inputs:
versionSpec: '$(python.version)'
architecture: '$(python.architecture)'
addToPath: true

- powershell: |
Write-Host "##vso[task.setvariable variable=PIPENV_DEFAULT_PYTHON_VERSION]$env:PYTHON_VERSION"
env:
PYTHON_VERSION: $(python.version)

- template: ../steps/install-dependencies.yml

Expand Down
19 changes: 5 additions & 14 deletions .azure-pipelines/jobs/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@ steps:
inputs:
versionSpec: '$(python.version)'
architecture: '$(python.architecture)'
addToPath: true

- script: |
echo '##vso[task.setvariable variable=PIPENV_DEFAULT_PYTHON_VERSION]$(python.version)'

- template: ../steps/install-dependencies.yml

- bash: |
mkdir -p "$AGENT_HOMEDIRECTORY/.virtualenvs"
mkdir -p "$WORKON_HOME"
pip install certifi
export GIT_SSL_CAINFO="$(python -m certifi)"
export LANG="C.UTF-8"
export PIP_PROCESS_DEPENDENCY_LINKS="1"
echo "Path $PATH"
echo "Installing Pipenv…"
pip install -e "$(pwd)[test]" --upgrade
pipenv install --deploy --dev
pipenv run pip install -e "$(pwd)[test]" --upgrade
echo pipenv --venv && echo pipenv --py && echo pipenv run python --version
displayName: Make Virtualenv
- template: ../steps/create-virtualenv-linux.yml

- script: |
# Fix Git SSL errors
Expand Down
14 changes: 14 additions & 0 deletions .azure-pipelines/steps/create-virtualenv-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
steps:
- bash: |
mkdir -p "$AGENT_HOMEDIRECTORY/.virtualenvs"
mkdir -p "$WORKON_HOME"
pip install certifi
export GIT_SSL_CAINFO="$(python -m certifi)"
export LANG="C.UTF-8"
export PIP_PROCESS_DEPENDENCY_LINKS="1"
echo "Path $PATH"
echo "Installing Pipenv…"
pipenv install --deploy --dev
pipenv run pip install -e "$(pwd)[test]" --upgrade
echo pipenv --venv && echo pipenv --py && echo pipenv run python --version
displayName: Make Virtualenv
32 changes: 28 additions & 4 deletions .azure-pipelines/steps/create-virtualenv.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
steps:
- script: |
virtualenv D:\.venv
D:\.venv\Scripts\pip.exe install -e .[test] && D:\.venv\Scripts\pipenv install --dev && D:\.venv\Scripts\pipenv run pip install -e .[test]
echo D:\.venv\Scripts\pipenv --venv && echo D:\.venv\Scripts\pipenv --py && echo D:\.venv\Scripts\pipenv run python --version

- powershell: |
$env:PY_EXE=$(python -c "import sys; print(sys.executable)")
if (!$env:PY_EXE) {
$env:PY_EXE="python"
}
Write-Host "##vso[task.setvariable variable=PY_EXE]"$env:PY_EXE
Write-Host "Found Python: $env:PY_EXE"
Invoke-Expression "$env:PY_EXE -m virtualenv D:\.venv"
Write-Host "##vso[task.setvariable variable=VIRTUAL_ENV]D:\.venv"
Invoke-Expression "D:\.venv\Scripts\activate.ps1"
$env:VIRTUAL_ENV="D:\.venv"
Write-Host "Installing local package..."
Invoke-Expression "$env:PY_EXE -m pip install -e .[test] --upgrade"
Write-Host "upgrading local package in virtual env"
$venv_scripts = Join-Path -path D:\.venv -childpath Scripts
$venv_py = Join-Path -path $venv_scripts -childpath python.exe
Invoke-Expression "$venv_py -m pip install -e .[test] --upgrade"
Write-Host "Installing pipenv development packages"
Invoke-Expression "$venv_py -m pipenv install --dev"
Write-Host "Installing local package in pipenv environment"
Invoke-Expression "$venv_py -m pipenv run pip install -e .[test]"
Write-Host "Printing metadata"
Write-Host $(Invoke-Expression "$venv_py -m pipenv --venv")
Write-Host $(Invoke-Expression "$venv_py -m pipenv --py")
Write-Host $(Invoke-Expression "$venv_py -m pipenv run python --version")
displayName: Make Virtualenv
env:
PIPENV_DEFAULT_PYTHON_VERSION: $(PIPENV_DEFAULT_PYTHON_VERSION)
2 changes: 1 addition & 1 deletion .azure-pipelines/steps/install-dependencies.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
steps:
- script: 'python -m pip install --upgrade pip && python -m pip install -e .[test]'
- script: 'python -m pip install --upgrade pip setuptools wheel && python -m pip install -e .[test] --upgrade'
displayName: Upgrade Pip & Install Pipenv
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ venv.bak/
# mypy
.mypy_cache/

# Temporarily generating these with pytype locally for type safety
typeshed/
pytype.cfg

### Python Patch ###
.venv/

Expand Down
2 changes: 2 additions & 0 deletions news/2783.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed an issue which caused errors due to reliance on the system utilities ``which`` and ``where`` which may not always exist on some systems.
- Fixed a bug which caused periodic failures in python discovery when executables named ``python`` were not present on the target ``$PATH``.
23 changes: 13 additions & 10 deletions pipenv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@
warnings.filterwarnings("ignore", category=ResourceWarning)
warnings.filterwarnings("ignore", category=UserWarning)

if sys.version_info >= (3, 1) and sys.version_info <= (3, 6):
if sys.stdout.isatty() and sys.stderr.isatty():
import io
import atexit
stdout_wrapper = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')
atexit.register(stdout_wrapper.close)
stderr_wrapper = io.TextIOWrapper(sys.stderr.buffer, encoding='utf8')
atexit.register(stderr_wrapper.close)
sys.stdout = stdout_wrapper
sys.stderr = stderr_wrapper

os.environ["PIP_DISABLE_PIP_VERSION_CHECK"] = fs_str("1")

Expand All @@ -46,6 +36,19 @@
except Exception:
pass

from .vendor.vistir.misc import get_wrapped_stream
if sys.version_info >= (3, 0):
stdout = sys.stdout.buffer
stderr = sys.stderr.buffer
else:
stdout = sys.stdout
stderr = sys.stderr


sys.stderr = get_wrapped_stream(stderr)
sys.stdout = get_wrapped_stream(stdout)


from .cli import cli
from . import resolver

Expand Down
2 changes: 1 addition & 1 deletion pipenv/cmdparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ScriptEmptyError(ValueError):


def _quote_if_contains(value, pattern):
if next(re.finditer(pattern, value), None):
if next(iter(re.finditer(pattern, value)), None):
return '"{0}"'.format(re.sub(r'(\\*)"', r'\1\1\\"', value))
return value

Expand Down
Loading