Skip to content

Commit 54b7aa8

Browse files
committed
Add command line option to enter path to requirements file.
1 parent b6541bb commit 54b7aa8

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ git submodule update --init --recursive --remote
4848
$ ./build.sh -h
4949
AWS Lambda Layer Builder for Python Libraries
5050
51-
Usage: build.sh [-p PYTHON_VER] [-n NAME] [-r] [-h] [-v]
51+
Usage: build.sh [-p PYTHON_VER] [-n NAME] [-f] [-r] [-h] [-v]
5252
-p PYTHON_VER : Python version to use: 2.7, 3.6, 3.7, 3.8 (default 3.7)
5353
-n NAME : Name of the layer
54+
-f REQ_PATH : Path to requirements file
5455
-r : Raw mode, don't zip layer contents
5556
-d : Don't install Python dependencies
5657
-s : Don't strip .so files
@@ -61,6 +62,7 @@ Usage: build.sh [-p PYTHON_VER] [-n NAME] [-r] [-h] [-v]
6162
- Run the builder with the command `./build.sh`
6263
- or `_build_layer/build.sh` if installed in sub-dir
6364
- It uses the first requirements.txt file found in these locations (in order):
65+
- Input on the command line using the `-f` switch
6466
- Same directory as script
6567
- Parent directory of script (useful when used as submodule)
6668
- Function sub-directory of the parent directory (useful when used as submodule)

build.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ displayVer() {
2727
# Display usage
2828
usage() {
2929
echo -e "AWS Lambda Layer Builder for Python Libraries\n"
30-
echo -e "Usage: ${scriptname} [-p PYTHON_VER] [-n NAME] [-r] [-h] [-v]"
30+
echo -e "Usage: ${scriptname} [-p PYTHON_VER] [-n NAME] [-f] [-r] [-h] [-v]"
3131
echo -e " -p PYTHON_VER\t: Python version to use: 2.7, 3.6, 3.7, 3.8 (default 3.7)"
3232
echo -e " -n NAME\t: Name of the layer"
33+
echo -e " -f REQ_PATH\t: Path to requirements file"
3334
echo -e " -r\t\t: Raw mode, don't zip layer contents"
3435
echo -e " -d\t\t: Don't install Python dependencies"
3536
echo -e " -s\t\t: Don't strip .so files"
@@ -38,10 +39,11 @@ usage() {
3839
}
3940

4041
# Handle configuration
41-
while getopts ":p:n:dsrhv" arg; do
42+
while getopts ":p:n:f:dsrhv" arg; do
4243
case "${arg}" in
4344
p) PYTHON_VER=${OPTARG};;
4445
n) NAME=${OPTARG};;
46+
f) REQ_PATH=${OPTARG};;
4547
r) RAW_MODE=true;;
4648
d) NO_DEPS=true;;
4749
s) STRIP=false;;
@@ -64,7 +66,12 @@ NO_DEPS="${NO_DEPS:-false}"
6466
STRIP="${STRIP:-true}"
6567

6668
# Find location of requirements.txt
67-
if [[ -f "${CURRENT_DIR}/requirements.txt" ]]; then
69+
if [[ -f $REQ_PATH ]]; then
70+
if [[ ${REQ_PATH:0:1} != '/' ]]; then
71+
REQ_PATH="$(pwd)/${REQ_PATH}"
72+
fi
73+
echo "Using requirements.txt from command line input"
74+
elif [[ -f "${CURRENT_DIR}/requirements.txt" ]]; then
6875
REQ_PATH="${CURRENT_DIR}/requirements.txt"
6976
echo "Using requirements.txt from script dir"
7077
elif [[ -f "${PARENT_DIR}/requirements.txt" ]]; then

0 commit comments

Comments
 (0)