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

feat(python): allow installing a version from git directly #11

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion layer/Python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ USER root
WORKDIR /tmp

# PACKAGE_SUFFIX = '[all]==2.0.0'
# PACKAGE_SUFFIX = '[all] @ git+https://github.com/awslabs/aws-lambda-powertools-python@v2'
# PACKAGE_SUFFIX = '[all]'
# PACKAGE_SUFFIX = '=='2.0.0'
# PACKAGE_SUFFIX = ' @ git+https://github.com/awslabs/aws-lambda-powertools-python@v2'
# PACKAGE_SUFFIX = ''

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

# Removing nonessential files
RUN cd /asset && \
Expand Down
6 changes: 5 additions & 1 deletion src/lambda-powertools-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ export class LambdaPowertoolsLayer extends lambda.LayerVersion {
suffix = '[all]';
}
if (version) {
suffix = `${suffix}==${version}`;
if (version.startsWith('git')) {
suffix = `${suffix} @ ${version}`;
} else {
suffix = `${suffix}==${version}`;
}
}
break;
case lambda.RuntimeFamily.NODEJS:
Expand Down
14 changes: 14 additions & 0 deletions test/lambda-powertools-python-layer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ describe('construct build args for Dockerfile', () => {
expect(args).toEqual('[all]');
});

test('returns a git url with extras when a git url is provided', () => {
const version = 'git+https://github.com/awslabs/aws-lambda-powertools-python@v2';
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, true, version);

expect(args).toEqual(`[all] @ ${version}`);
});

test('returns only version when no extras flag provided', () => {
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, undefined, '1.11.0');

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

test('returns a git url when a git url is provided and extras provided', () => {
const version = 'git+https://github.com/awslabs/aws-lambda-powertools-python@v2';
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, false, version);

expect(args).toEqual(` @ ${version}`);
});

});