From d1cb6f1743ab2b2b7ec7dbc23a65aa66c25aeb40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Tarot=20=28=40silopolis=29?= Date: Thu, 28 Dec 2023 12:43:45 +0100 Subject: [PATCH 1/5] scripts: make scripts executable --- scripts/bootstrap.sh | 0 scripts/prestart.sh | 0 scripts/python_setup.sh | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/bootstrap.sh mode change 100644 => 100755 scripts/prestart.sh mode change 100644 => 100755 scripts/python_setup.sh diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh old mode 100644 new mode 100755 diff --git a/scripts/prestart.sh b/scripts/prestart.sh old mode 100644 new mode 100755 diff --git a/scripts/python_setup.sh b/scripts/python_setup.sh old mode 100644 new mode 100755 From bd118a5fd65b54220e7b474465eee654e3131132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Tarot=20=28=40silopolis=29?= Date: Thu, 28 Dec 2023 12:53:13 +0100 Subject: [PATCH 2/5] scripts:python_setup: only source `.env` file if it exists --- scripts/python_setup.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/python_setup.sh b/scripts/python_setup.sh index e4c7b7c..62eac84 100755 --- a/scripts/python_setup.sh +++ b/scripts/python_setup.sh @@ -7,7 +7,10 @@ cwd="$(pwd)" ## Change to project directory cd "$(dirname "$0")/.." # shellcheck source="../.env" -source .env +if [ -f .env ]; then + # shellcheck source="../.env" + source .env +fi ## Only compatible with Debian and Ubuntu if [[ ! $(dpkg -s python3-venv) ]]; then @@ -23,6 +26,7 @@ fi echo "-- Python: Activate '.venv' virtual environment" # shellcheck source="../.venv/bin/activate" source .venv/bin/activate + echo "-- Upgrage Python pip and setuptools in venv" pip install --upgrade setuptools pip echo "-- Install Python requirements in venv" From 44a5ae9c2e0730615644a90187529ceebb353cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Tarot=20=28=40silopolis=29?= Date: Thu, 28 Dec 2023 12:54:51 +0100 Subject: [PATCH 3/5] scripts:bootstrap: only source `.env` file if it exists Also fix shellcheck warning when sourced files do not exist --- scripts/bootstrap.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 45dc49f..2097e7e 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -6,20 +6,26 @@ set -e #ux cwd="$(pwd)" ## Change to project directory cd "$(dirname "$0")/.." -# shellcheck source="../.env" -source .env +if [ -f .env ]; then + # shellcheck source="../.env" disable=SC1091 + source .env +fi ./scripts/python_setup.sh "$@" echo "-- Shell: Source profile in case it's been updated" -# shellcheck source="$HOME/.profile" +# shellcheck source="$HOME/.profile" disable=SC1091 source "$HOME/.profile" + echo "-- Activate Python virtual environment" # shellcheck source="../.venv/bin/activate" source .venv/bin/activate -echo "-- Source '.env' configuration file" -# shellcheck source="../.env" -source .env + +if [ -f .env ]; then + echo "-- Source '.env' configuration file" + # shellcheck source="../.env" disable=SC1091 + source .env +fi ## and go back cd "$cwd" From 2779d294c0922cbaf0fd0b1d2d652da46ee5fea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Tarot=20=28=40silopolis=29?= Date: Thu, 28 Dec 2023 16:50:45 +0100 Subject: [PATCH 4/5] scripts: split Python requirements * Split Python setup and App requirements * Move global Python requirements installation from Python setup to bootstrap. (allows for docs only setup) --- requirements.app.in | 5 +++++ requirements.in | 11 +++++------ requirements.python.in | 1 + requirements.txt | 12 ++++++------ scripts/bootstrap.sh | 3 +++ scripts/python_setup.sh | 5 +++-- 6 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 requirements.app.in create mode 100644 requirements.python.in diff --git a/requirements.app.in b/requirements.app.in new file mode 100644 index 0000000..3d60ad8 --- /dev/null +++ b/requirements.app.in @@ -0,0 +1,5 @@ +asyncpg==0.27.0 +fastapi==0.89.1 +ormar==0.12.1 +psycopg2-binary==2.9.5 +uvicorn==0.20.0 diff --git a/requirements.in b/requirements.in index 58699c0..c8bf7e7 100644 --- a/requirements.in +++ b/requirements.in @@ -1,7 +1,6 @@ -asyncpg==0.27.0 -fastapi==0.89.1 -ormar==0.12.1 -psycopg2-binary==2.9.5 -uvicorn==0.20.0 -pip-tools==7.3.0 +# Compile project requirement with (pip-tools needed): +# pip-compile --output-file=requirements.txt requirements.in + +-r requirements.python.in +-r requirements.app.in -r docs/requirements.in diff --git a/requirements.python.in b/requirements.python.in new file mode 100644 index 0000000..15eed1b --- /dev/null +++ b/requirements.python.in @@ -0,0 +1 @@ +pip-tools==7.3.0 diff --git a/requirements.txt b/requirements.txt index 5f4c814..95c87c1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ anyio==4.0.0 # via starlette asyncpg==0.27.0 - # via -r requirements.in + # via -r requirements.app.in babel==2.13.1 # via # mkdocs-git-revision-date-localized-plugin @@ -40,7 +40,7 @@ databases==0.6.2 defusedxml==0.7.1 # via cairosvg fastapi==0.89.1 - # via -r requirements.in + # via -r requirements.app.in ghp-import==2.1.0 # via mkdocs gitdb==4.0.11 @@ -112,7 +112,7 @@ mkdocs-section-index==0.3.8 natsort==8.4.0 # via mkdocs-awesome-pages-plugin ormar==0.12.1 - # via -r requirements.in + # via -r requirements.app.in packaging==23.2 # via # build @@ -126,11 +126,11 @@ pillow==9.5.0 # cairosvg # mkdocs-material pip-tools==7.3.0 - # via -r requirements.in + # via -r requirements.python.in platformdirs==4.0.0 # via mkdocs psycopg2-binary==2.9.5 - # via -r requirements.in + # via -r requirements.app.in pycparser==2.21 # via cffi pydantic==1.10.4 @@ -193,7 +193,7 @@ typing-extensions==4.8.0 urllib3==2.1.0 # via requests uvicorn==0.20.0 - # via -r requirements.in + # via -r requirements.app.in verspec==0.1.0 # via mike watchdog==3.0.0 diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 2097e7e..78fc608 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -21,6 +21,9 @@ echo "-- Activate Python virtual environment" # shellcheck source="../.venv/bin/activate" source .venv/bin/activate +echo "-- Install project Python requirements in venv" +pip install -r requirements.txt + if [ -f .env ]; then echo "-- Source '.env' configuration file" # shellcheck source="../.env" disable=SC1091 diff --git a/scripts/python_setup.sh b/scripts/python_setup.sh index 62eac84..4ce5926 100755 --- a/scripts/python_setup.sh +++ b/scripts/python_setup.sh @@ -29,8 +29,9 @@ source .venv/bin/activate echo "-- Upgrage Python pip and setuptools in venv" pip install --upgrade setuptools pip -echo "-- Install Python requirements in venv" -pip install -r requirements.txt + +echo "-- Install Python setup requirements in venv" +pip install -r requirements.python.in ## and go back cd "$cwd" From 8e74e786fb5f85231b3a016578cb77aeb14dbf48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Tarot=20=28=40silopolis=29?= Date: Thu, 28 Dec 2023 17:03:28 +0100 Subject: [PATCH 5/5] scripts: Test if venv is already activated --- scripts/bootstrap.sh | 8 +++++--- scripts/python_setup.sh | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 78fc608..967a3bb 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -17,9 +17,11 @@ echo "-- Shell: Source profile in case it's been updated" # shellcheck source="$HOME/.profile" disable=SC1091 source "$HOME/.profile" -echo "-- Activate Python virtual environment" -# shellcheck source="../.venv/bin/activate" -source .venv/bin/activate +if [[ ! $(pip -V) =~ .*\.venv.* ]]; then + echo "-- Python: Activate '.venv' virtual environment" + # shellcheck source="../.venv/bin/activate" disable=SC1091 + source .venv/bin/activate +fi echo "-- Install project Python requirements in venv" pip install -r requirements.txt diff --git a/scripts/python_setup.sh b/scripts/python_setup.sh index 4ce5926..04dd888 100755 --- a/scripts/python_setup.sh +++ b/scripts/python_setup.sh @@ -23,9 +23,11 @@ if [ ! -d .venv ]; then python3 -m venv .venv fi -echo "-- Python: Activate '.venv' virtual environment" -# shellcheck source="../.venv/bin/activate" -source .venv/bin/activate +if [[ ! $(pip -V) =~ .*\.venv.* ]]; then + echo "-- Python: Activate '.venv' virtual environment" + # shellcheck source="../.venv/bin/activate" disable=SC1091 + source .venv/bin/activate +fi echo "-- Upgrage Python pip and setuptools in venv" pip install --upgrade setuptools pip