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

get-poetry.py fallback to standard executables #1878

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poet

Alternatively, you can download the `get-poetry.py` file and execute it separately.

The setup script must be able to find one of following executables in your shell's path environment:

- `python` (which can be a py3 or py2 interpreter)
- `python3`
- `py.exe -3` (Windows)
- `py.exe -2` (Windows)

If you want to install prerelease versions, you can do so by passing `--preview` to `get-poetry.py`:

```bash
Expand Down
30 changes: 26 additions & 4 deletions get-poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ def expanduser(path):
POETRY_LIB_BACKUP = os.path.join(POETRY_HOME, "lib-backup")


BIN = """#!/usr/bin/env python
# -*- coding: utf-8 -*-
BIN = """# -*- coding: utf-8 -*-
import glob
import sys
import os
Expand All @@ -213,7 +212,7 @@ def expanduser(path):
main()
"""

BAT = u('@echo off\r\npython "{poetry_bin}" %*\r\n')
BAT = u('@echo off\r\n{python_executable} "{poetry_bin}" %*\r\n')


PRE_MESSAGE = """# Welcome to {poetry}!
Expand Down Expand Up @@ -585,23 +584,46 @@ def _make_lib(self, version):
finally:
gz.close()

def _which_python(self):
allowed_executables = ["python", "python3"]
if WINDOWS:
allowed_executables += ["py.exe -3", "py.exe -2"]

for executable in allowed_executables:
try:
subprocess.check_call(executable + " --version", shell=True)
except subprocess.CalledProcessError:
continue

return executable

raise RuntimeError(
"No python executable found in shell environment. Tried: "
+ str(allowed_executables)
)

def make_bin(self):
if not os.path.exists(POETRY_BIN):
os.mkdir(POETRY_BIN, 0o755)

python_executable = self._which_python()

if WINDOWS:
with open(os.path.join(POETRY_BIN, "poetry.bat"), "w") as f:
f.write(
u(
BAT.format(
python_executable=python_executable,
poetry_bin=os.path.join(POETRY_BIN, "poetry").replace(
os.environ["USERPROFILE"], "%USERPROFILE%"
)
),
)
)
)

with open(os.path.join(POETRY_BIN, "poetry"), "w", encoding="utf-8") as f:
if not WINDOWS:
f.write(u("#!/usr/bin/env {}\n".format(python_executable)))
f.write(u(BIN))

if not WINDOWS:
Expand Down