Skip to content

Commit f74abbc

Browse files
author
Marat Salimzianov
committed
Implemented --no-deps argument for pip
1 parent 985200e commit f74abbc

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
data "external" "lambda_archive" {
22
program = ["python3", "${path.module}/scripts/build_lambda.py"]
33
query = {
4-
src_dir = "${var.src_dir}"
5-
output_path = "${var.output_path}"
4+
src_dir = var.src_dir
5+
output_path = var.output_path
6+
install_dependencies = var.install_dependencies
67
}
78
}

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
output "archive_path" {
22
description = "Path of the archive file."
3-
value = "${data.external.lambda_archive.result.archive}"
3+
value = data.external.lambda_archive.result.archive
44
}
55

66
output "source_code_hash" {
77
description = "Base64 encoded SHA256 hash of the archive file."
8-
value = "${data.external.lambda_archive.result.base64sha256}"
8+
value = data.external.lambda_archive.result.base64sha256
99
}

scripts/build_lambda.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import tempfile
1414
import zipfile
1515

16-
def build(src_dir, output_path):
16+
def build(src_dir, output_path, install_dependencies):
1717
with tempfile.TemporaryDirectory() as build_dir:
1818
copy_tree(src_dir, build_dir)
1919
if os.path.exists(os.path.join(src_dir, 'requirements.txt')):
@@ -24,7 +24,8 @@ def build(src_dir, output_path):
2424
'install',
2525
'--ignore-installed',
2626
'--target', build_dir,
27-
'-r', os.path.join(build_dir, 'requirements.txt')],
27+
'-r', os.path.join(build_dir, 'requirements.txt'),
28+
*(['--no-deps'] if install_dependencies == 'false' else [])],
2829
check=True,
2930
stdout=subprocess.DEVNULL,
3031
)
@@ -71,5 +72,5 @@ def get_hash(output_path):
7172
logging.basicConfig(level='DEBUG')
7273
query = json.loads(sys.stdin.read())
7374
logging.debug(query)
74-
archive = build(query['src_dir'], query['output_path'])
75+
archive = build(query['src_dir'], query['output_path'], query['install_dependencies'])
7576
print(json.dumps({'archive': archive, 'base64sha256':get_hash(archive)}))

variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
variable "src_dir" {
22
description = "Path to root of Python source to package."
3-
type = "string"
3+
type = string
44
}
55

66
variable "output_path" {
77
description = "The output of the archive file."
8-
type = "string"
8+
type = string
9+
}
10+
11+
variable "install_dependencies" {
12+
description = "Whether to install pip dependecies"
13+
type = bool
14+
default = true
915
}

0 commit comments

Comments
 (0)