Skip to content

Commit 72d887b

Browse files
authored
fix: Fixed issue with zip renaming on Windows platform (claranet#32)
1 parent e52eed7 commit 72d887b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

package.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
PY37 = sys.version_info >= (3, 7)
3030
PY36 = sys.version_info >= (3, 6)
3131

32+
WINDOWS = platform.system() == 'Windows'
33+
OSX = platform.system() == 'Darwin'
34+
3235
################################################################################
3336
# Logging
3437

@@ -291,11 +294,12 @@ def open(self):
291294
return self
292295

293296
def close(self, failed=False):
297+
self._zip.close()
298+
self._zip = None
294299
if failed:
295300
os.unlink(self._tmp_filename)
296301
else:
297302
os.replace(self._tmp_filename, self.filename)
298-
self._zip = None
299303

300304
def __enter__(self):
301305
return self.open()
@@ -845,10 +849,14 @@ def install_pip_requirements(query, requirements_file):
845849
target_file = os.path.join(temp_dir, requirements_filename)
846850
shutil.copyfile(requirements_file, target_file)
847851

852+
python_exec = runtime
853+
if WINDOWS and not docker:
854+
python_exec = 'python.exe'
855+
848856
# Install dependencies into the temporary directory.
849857
with cd(temp_dir):
850858
pip_command = [
851-
runtime, '-m', 'pip',
859+
python_exec, '-m', 'pip',
852860
'install', '--no-compile',
853861
'--prefix=', '--target=.',
854862
'--requirement={}'.format(requirements_filename),

package.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
locals {
2+
python = (substr(pathexpand("~"), 0, 1) == "/") ? "python3" : "python.exe"
3+
}
4+
15
# Generates a filename for the zip archive based on the content of the files
26
# in source_path. The filename will change when the source code changes.
37
data "external" "archive_prepare" {
48
count = var.create && var.create_package ? 1 : 0
59

6-
program = ["python3", "${path.module}/package.py", "prepare"]
10+
program = [local.python, "${path.module}/package.py", "prepare"]
711
working_dir = path.cwd
812

913
query = {
@@ -52,7 +56,7 @@ resource "null_resource" "archive" {
5256

5357
provisioner "local-exec" {
5458
interpreter = [
55-
"python3", "${path.module}/package.py", "build",
59+
local.python, "${path.module}/package.py", "build",
5660
"--timestamp", data.external.archive_prepare[0].result.timestamp
5761
]
5862
command = data.external.archive_prepare[0].result.build_plan_filename

0 commit comments

Comments
 (0)