Skip to content

Commit

Permalink
Fix install on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stealthycoin committed Oct 10, 2022
1 parent d959fdc commit 32967eb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion backends/build_system/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
BIN_DIRNAME = "Scripts" if IS_WINDOWS else "bin"
PYTHON_EXE_NAME = "python.exe" if IS_WINDOWS else "python"
PYINSTALLER_EXE_NAME = "pyinstaller.exe" if IS_WINDOWS else "pyinstaller"
CLI_EXECUTABLES = ["aws.cmd"] if IS_WINDOWS else ["aws", "aws_completer"]
CLI_SCRIPTS = ["aws.cmd"] if IS_WINDOWS else ["aws", "aws_completer"]
LOCK_SUFFIX = "win-lock.txt" if IS_WINDOWS else "lock.txt"

# Requirements files
Expand Down
26 changes: 20 additions & 6 deletions backends/build_system/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
import os
import functools

from constants import CLI_EXECUTABLES
from constants import CLI_SCRIPTS
from constants import IS_WINDOWS
from constants import BIN_DIRNAME
from constants import PYTHON_EXE_NAME
from constants import ArtifactType
from utils import Utils


TEMPLATE = """@echo off
{path} %*
"""

class Uninstaller:
def __init__(self, utils: Utils = None):
if utils is None:
Expand All @@ -30,7 +34,7 @@ def __init__(self, utils: Utils = None):
def uninstall(self, install_dir: str, bin_dir: str):
if self._utils.isdir(install_dir):
self._utils.rmtree(install_dir)
for exe in CLI_EXECUTABLES:
for exe in CLI_SCRIPTS:
exe_path = os.path.join(bin_dir, exe)
if self._utils.islink(exe_path):
self._utils.remove(exe_path)
Expand All @@ -45,7 +49,7 @@ def __init__(self, build_dir: str, utils: Utils = None):

def install(self, install_dir: str, bin_dir: str):
self._copy_to_install_dir(install_dir)
self._symlink_executables(install_dir, bin_dir)
self._install_executables(install_dir, bin_dir)

@functools.cached_property
def artifact_type(self):
Expand All @@ -66,14 +70,24 @@ def _get_build_lib(self):
return os.path.join(self._build_dir, "exe", "aws", "dist")
return os.path.join(self._build_dir, "venv")

def _install_executables(self, install_dir, bin_dir):
if IS_WINDOWS and self.artifact_type == ArtifactType.PORTABLE_EXE:
self._install_executables_on_windows(install_dir, bin_dir)
else:
self._symlink_executables(install_dir, bin_dir)

def _install_executables_on_windows(self, install_dir, bin_dir):
with open(os.path.join(bin_dir, "aws.cmd"), "w") as f:
f.write(TEMPLATE.format(path=os.path.join(install_dir, "aws.exe")))
def _symlink_executables(self, install_dir, bin_dir):
if not self._utils.path_exists(bin_dir):
self._utils.makedirs(bin_dir)
for exe in CLI_EXECUTABLES:
for exe in CLI_SCRIPTS:
print(exe)
exe_path = os.path.join(bin_dir, exe)
if self._utils.islink(exe_path):
self._utils.remove(exe_path)
self._utils.symlink(
self._utils.link(
self._get_install_bin_exe(install_dir, exe), exe_path
)

Expand All @@ -87,7 +101,7 @@ def _update_script_header(self, install_dir):
python_exe_path = self._get_install_bin_exe(
install_dir, PYTHON_EXE_NAME
)
for exe in CLI_EXECUTABLES:
for exe in CLI_SCRIPTS:
exe_path = self._get_install_bin_exe(install_dir, exe)
lines = self._utils.read_file_lines(exe_path)
lines[0] = self._get_script_header(python_exe_path)
Expand Down
3 changes: 3 additions & 0 deletions backends/build_system/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ def makedirs(self, path: str):
def symlink(self, src: str, dst: str):
os.symlink(src, dst)

def link(self, src: str, dst: str):
os.link(src, dst)

def read_file_lines(self, path: str) -> List[str]:
return open(path, "r").readlines()

Expand Down
6 changes: 2 additions & 4 deletions tests/backends/build_system/integration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
BIN_DIRNAME = "Scripts" if IS_WINDOWS else "bin"
PYTHON_EXE_NAME = "python.exe" if IS_WINDOWS else "python"
CLI_SCRIPT_NAME = "aws.cmd" if IS_WINDOWS else "aws"
CLI_EXE_NAME = "aws.exe" if IS_WINDOWS else "aws"
LOCK_SUFFIX = "win-lock.txt" if IS_WINDOWS else "lock.txt"

ROOT = Path(__file__).parents[4]
Expand Down Expand Up @@ -72,7 +71,6 @@ def assert_built_venv_is_correct(self, venv_dir):

def assert_venv_is_correct(self, venv_dir):
files = os.listdir(venv_dir)
print(files)
assert "Include" in files or "include" in files
assert "Lib" in files or "lib" in files or "lib64" in files
assert "pyvenv.cfg" in files
Expand All @@ -92,7 +90,7 @@ def assert_built_exe_is_correct(self, root_dir):
self.assert_version_string_is_correct(aws_exe)

def assert_installed_exe_is_correct(self, exe_dir):
self.assert_version_string_is_correct(exe_dir / CLI_EXE_NAME)
self.assert_version_string_is_correct(exe_dir / CLI_SCRIPT_NAME)

def assert_installed_venv_is_correct(self, exe_dir, lib_dir):
self.assert_version_string_is_correct(exe_dir / CLI_SCRIPT_NAME)
Expand Down Expand Up @@ -201,7 +199,7 @@ def call_install(self, bin_path: str, lib_path: str):
"--lib-dir",
lib_path,
"--build-dir",
"build"
"build",
]
return self.subprocess(args)

Expand Down

0 comments on commit 32967eb

Please sign in to comment.