Skip to content

Commit

Permalink
Use a symlink to the venv-installed poetry script
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed Feb 19, 2021
1 parent fa21ac9 commit e1dcdf1
Showing 1 changed file with 11 additions and 53 deletions.
64 changes: 11 additions & 53 deletions install-poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import re
import shutil
import site
import stat
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -497,7 +496,8 @@ def uninstall(self) -> int:

shutil.rmtree(str(self._data_dir))
for script in ["poetry", "poetry.bat"]:
self._bin_dir.joinpath(script).unlink(missing_ok=True)
if self._bin_dir.joinpath(script).exists():
self._bin_dir.joinpath(script).unlink()

return 0

Expand Down Expand Up @@ -548,62 +548,20 @@ def make_bin(self, site_packages: Path, version: str) -> None:
f.write(
BAT.format(
python_executable=python_executable,
poetry_bin=self._bin_dir.joinpath("poetry"),
poetry_bin=str(
self._data_dir.joinpath("venv/Scripts/poetry.exe")
),
)
)

# Versions of Poetry prior to 1.2.0 did not have the main()
# function at the poetry.console.application level but et he poetry.console one.
main_module = "poetry.console.application"
version_content = site_packages.joinpath("poetry/__version__.py").read_text(
encoding="utf-8"
)

current_version_re = re.match('(?ms).*__version__ = "(.+)".*', version_content)
if not current_version_re:
self._write(
colorize(
"warning",
"Unable to get the current Poetry version. Assuming None",
)
)
if is_decorated():
self._write("")

current_version = "1.2.0"
else:
current_version = current_version_re.group(1)
return

m = self.VERSION_REGEX.match(current_version)
if tuple(int(p) for p in m.groups()[:2]) < (1, 2):
main_module = "poetry.console"
if self._data_dir.joinpath("venv/bin/poetry").exists():
self._data_dir.joinpath("venv/bin/poetry").unlink()

with self._bin_dir.joinpath("poetry").open("w", encoding="utf-8") as f:
f.write("#!/usr/bin/env {}\n".format(python_executable))

if WINDOWS:
f.write(
BIN.format(
site_packages=str(site_packages.resolve()).replace(
"\\", "\\\\"
),
main_module=main_module,
)
)
else:
f.write(
BIN.format(
site_packages=str(site_packages.resolve()),
main_module=main_module,
)
)

if not WINDOWS:
# Making the file executable
st = os.stat(self._bin_dir.joinpath("poetry").as_posix())
os.chmod(
self._bin_dir.joinpath("poetry").as_posix(), st.st_mode | stat.S_IEXEC
)
self._data_dir.joinpath("venv/bin/poetry").symlink_to(
self._bin_dir.joinpath("poetry")
)

def install_poetry(self, version: str, env_path: Path) -> None:
self._overwrite(
Expand Down

0 comments on commit e1dcdf1

Please sign in to comment.