Skip to content

Commit

Permalink
fix: Fixed issue with zip renaming on Windows platform (claranet#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahlinc authored Jun 18, 2020
1 parent e52eed7 commit 72d887b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 10 additions & 2 deletions package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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),
Expand Down
8 changes: 6 additions & 2 deletions package.tf
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 72d887b

Please sign in to comment.