Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 6175186

Browse files
authored
feat(python): allow installing a version from git directly (#11)
1 parent f9b3290 commit 6175186

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

layer/Python/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ USER root
66
WORKDIR /tmp
77

88
# PACKAGE_SUFFIX = '[all]==2.0.0'
9+
# PACKAGE_SUFFIX = '[all] @ git+https://github.com/awslabs/aws-lambda-powertools-python@v2'
910
# PACKAGE_SUFFIX = '[all]'
1011
# PACKAGE_SUFFIX = '=='2.0.0'
12+
# PACKAGE_SUFFIX = ' @ git+https://github.com/awslabs/aws-lambda-powertools-python@v2'
1113
# PACKAGE_SUFFIX = ''
1214

1315
RUN yum update -y && yum install -y zip unzip wget tar gzip binutils
@@ -29,7 +31,7 @@ RUN yum install -y \
2931
# Install cython to generate native code
3032
RUN pip install --upgrade pip wheel && pip install --upgrade cython
3133
# Optimize binary size and strip debugging symbols for optimum size
32-
RUN CFLAGS="-Os -g0 -s" pip install --no-binary pydantic -t /asset/python aws-lambda-powertools$PACKAGE_SUFFIX
34+
RUN CFLAGS="-Os -g0 -s" pip install --no-binary pydantic -t /asset/python "aws-lambda-powertools$PACKAGE_SUFFIX"
3335

3436
# Removing nonessential files
3537
RUN cd /asset && \

src/lambda-powertools-layer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ export class LambdaPowertoolsLayer extends lambda.LayerVersion {
5858
suffix = '[all]';
5959
}
6060
if (version) {
61-
suffix = `${suffix}==${version}`;
61+
if (version.startsWith('git')) {
62+
suffix = `${suffix} @ ${version}`;
63+
} else {
64+
suffix = `${suffix}==${version}`;
65+
}
6266
}
6367
break;
6468
case lambda.RuntimeFamily.NODEJS:

test/lambda-powertools-python-layer.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ describe('construct build args for Dockerfile', () => {
117117
expect(args).toEqual('[all]');
118118
});
119119

120+
test('returns a git url with extras when a git url is provided', () => {
121+
const version = 'git+https://github.com/awslabs/aws-lambda-powertools-python@v2';
122+
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, true, version);
123+
124+
expect(args).toEqual(`[all] @ ${version}`);
125+
});
126+
120127
test('returns only version when no extras flag provided', () => {
121128
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, undefined, '1.11.0');
122129

@@ -129,4 +136,11 @@ describe('construct build args for Dockerfile', () => {
129136
expect(args).toEqual('');
130137
});
131138

139+
test('returns a git url when a git url is provided and extras provided', () => {
140+
const version = 'git+https://github.com/awslabs/aws-lambda-powertools-python@v2';
141+
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, false, version);
142+
143+
expect(args).toEqual(` @ ${version}`);
144+
});
145+
132146
});

0 commit comments

Comments
 (0)