diff --git a/package.py b/package.py index 18d1720..0e6f603 100644 --- a/package.py +++ b/package.py @@ -29,6 +29,9 @@ PY37 = sys.version_info >= (3, 7) PY36 = sys.version_info >= (3, 6) +WINDOWS = platform.system() == 'Windows' +OSX = platform.system() == 'Darwin' + ################################################################################ # Logging @@ -291,11 +294,12 @@ def open(self): return self def close(self, failed=False): + self._zip.close() + self._zip = None if failed: os.unlink(self._tmp_filename) else: os.replace(self._tmp_filename, self.filename) - self._zip = None def __enter__(self): return self.open() @@ -845,10 +849,14 @@ def install_pip_requirements(query, requirements_file): target_file = os.path.join(temp_dir, requirements_filename) shutil.copyfile(requirements_file, target_file) + python_exec = runtime + if WINDOWS and not docker: + python_exec = 'python.exe' + # Install dependencies into the temporary directory. with cd(temp_dir): pip_command = [ - runtime, '-m', 'pip', + python_exec, '-m', 'pip', 'install', '--no-compile', '--prefix=', '--target=.', '--requirement={}'.format(requirements_filename), diff --git a/package.tf b/package.tf index 3509f06..07de800 100644 --- a/package.tf +++ b/package.tf @@ -1,9 +1,13 @@ +locals { + python = (substr(pathexpand("~"), 0, 1) == "/") ? "python3" : "python.exe" +} + # Generates a filename for the zip archive based on the content of the files # in source_path. The filename will change when the source code changes. data "external" "archive_prepare" { count = var.create && var.create_package ? 1 : 0 - program = ["python3", "${path.module}/package.py", "prepare"] + program = [local.python, "${path.module}/package.py", "prepare"] working_dir = path.cwd query = { @@ -52,7 +56,7 @@ resource "null_resource" "archive" { provisioner "local-exec" { interpreter = [ - "python3", "${path.module}/package.py", "build", + local.python, "${path.module}/package.py", "build", "--timestamp", data.external.archive_prepare[0].result.timestamp ] command = data.external.archive_prepare[0].result.build_plan_filename