diff --git a/README.md b/README.md index 9659dcc..90fcc04 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ test ./tests/validate.sh hello ./src/hello.sh env ./src/env.sh manifest ./src/manifest.sh -python-info PYTHONPATH=lib/python python -m base_demo_cli +python-info ./bin/base-demo-python-info $ basectl run base-demo hello hello from base-demo @@ -80,6 +80,8 @@ because activation sources `.base/activate.sh` into the project shell. for `basectl run`. - `lib/python/base_demo_cli` is a tiny Python command target that runs inside the Base-managed project environment. +- `bin/base-demo-python-info` is the Bash launcher that delegates the Python + package to `base-wrapper`. - `demo/demo.sh` is the interactive walkthrough. - `tests/validate.sh` verifies that the repository baseline is intact. diff --git a/base_manifest.yaml b/base_manifest.yaml index a942476..9ca0e6c 100644 --- a/base_manifest.yaml +++ b/base_manifest.yaml @@ -13,7 +13,7 @@ commands: hello: ./src/hello.sh env: ./src/env.sh manifest: ./src/manifest.sh - python-info: PYTHONPATH=lib/python python -m base_demo_cli + python-info: ./bin/base-demo-python-info test: command: ./tests/validate.sh diff --git a/bin/base-demo-python-info b/bin/base-demo-python-info new file mode 100755 index 0000000..2b51ee3 --- /dev/null +++ b/bin/base-demo-python-info @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +if [[ -z "${BASE_HOME:-}" ]]; then + printf 'ERROR: BASE_HOME is not set. Run this through basectl or an activated Base shell.\n' >&2 + exit 1 +fi + +if [[ -z "${BASE_PROJECT_ROOT:-}" ]]; then + printf 'ERROR: BASE_PROJECT_ROOT is not set. Run this through basectl or an activated Base shell.\n' >&2 + exit 1 +fi + +if [[ -n "${PYTHONPATH:-}" ]]; then + PYTHONPATH="$BASE_PROJECT_ROOT/lib/python:$PYTHONPATH" +else + PYTHONPATH="$BASE_PROJECT_ROOT/lib/python" +fi +export PYTHONPATH + +exec "$BASE_HOME/bin/base-wrapper" --project "${BASE_PROJECT:-base-demo}" base_demo_cli "$@" diff --git a/demo/demo.sh b/demo/demo.sh index 7e2348e..cb49971 100755 --- a/demo/demo.sh +++ b/demo/demo.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -set -euo pipefail BASE_DEMO_PROJECT="${BASE_PROJECT:-base-demo}" BASE_DEMO_ROOT="${BASE_PROJECT_ROOT:-}" @@ -19,13 +18,19 @@ demo_project_root() { cd -- "$(demo_script_dir)/.." && pwd -P } -BASE_DEMO_ROOT="$(demo_project_root)" +BASE_DEMO_ROOT="$(demo_project_root)" || { + printf 'ERROR: Unable to resolve base-demo project root.\n' >&2 + exit 1 +} demo_workspace_root() { cd -- "$BASE_DEMO_ROOT/.." && pwd -P } -BASE_DEMO_WORKSPACE="$(demo_workspace_root)" +BASE_DEMO_WORKSPACE="$(demo_workspace_root)" || { + printf 'ERROR: Unable to resolve base-demo workspace root.\n' >&2 + exit 1 +} usage() { cat <<'EOF' @@ -120,6 +125,7 @@ project_shape_step() { step 1 "Project Shape" run_command test -f "$BASE_DEMO_ROOT/base_manifest.yaml" run_command test -f "$BASE_DEMO_ROOT/Brewfile" + run_command test -x "$BASE_DEMO_ROOT/bin/base-demo-python-info" run_command test -x "$BASE_DEMO_ROOT/src/hello.sh" run_command test -x "$BASE_DEMO_ROOT/src/env.sh" run_command test -x "$BASE_DEMO_ROOT/src/manifest.sh" @@ -133,7 +139,7 @@ manifest_step() { run_command grep -n "hello: ./src/hello.sh" "$BASE_DEMO_ROOT/base_manifest.yaml" run_command grep -n "env: ./src/env.sh" "$BASE_DEMO_ROOT/base_manifest.yaml" run_command grep -n "manifest: ./src/manifest.sh" "$BASE_DEMO_ROOT/base_manifest.yaml" - run_command grep -n "python-info: PYTHONPATH=lib/python python -m base_demo_cli" "$BASE_DEMO_ROOT/base_manifest.yaml" + run_command grep -n "python-info: ./bin/base-demo-python-info" "$BASE_DEMO_ROOT/base_manifest.yaml" run_command grep -n "command: ./tests/validate.sh" "$BASE_DEMO_ROOT/base_manifest.yaml" run_command grep -n "script: ./demo/demo.sh" "$BASE_DEMO_ROOT/base_manifest.yaml" pause @@ -142,7 +148,7 @@ manifest_step() { activation_step() { step 5 "Project Activation Source" # shellcheck source=/dev/null - source "$BASE_DEMO_ROOT/.base/activate.sh" + source "$BASE_DEMO_ROOT/.base/activate.sh" || return 1 printf 'BASE_DEMO_ENV=%s\n' "${BASE_DEMO_ENV:-unset}" printf 'BASE_DEMO_ACTIVATED=%s\n' "${BASE_DEMO_ACTIVATED:-unset}" printf 'BASE_DEMO_PROJECT_KIND=%s\n' "${BASE_DEMO_PROJECT_KIND:-unset}" @@ -240,7 +246,7 @@ main() { return "$status" } - cd -- "$BASE_DEMO_ROOT" + cd -- "$BASE_DEMO_ROOT" || return 1 intro project_shape_step manifest_step diff --git a/src/env.sh b/src/env.sh index 8bf462a..b55cc33 100755 --- a/src/env.sh +++ b/src/env.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -set -euo pipefail print_var() { local name="$1" diff --git a/src/hello.sh b/src/hello.sh index 7c712a3..f31564b 100755 --- a/src/hello.sh +++ b/src/hello.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -set -euo pipefail printf 'hello from base-demo\n' printf 'BASE_PROJECT=%s\n' "${BASE_PROJECT:-unset}" diff --git a/src/manifest.sh b/src/manifest.sh index dcacd1b..6ecfbfd 100755 --- a/src/manifest.sh +++ b/src/manifest.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -set -euo pipefail manifest="${BASE_PROJECT_MANIFEST:-base_manifest.yaml}" diff --git a/tests/demo_test.bats b/tests/demo_test.bats index 4ea58dd..fbd4b2e 100755 --- a/tests/demo_test.bats +++ b/tests/demo_test.bats @@ -45,7 +45,7 @@ case "$*" in printf 'hello ./src/hello.sh\n' printf 'env ./src/env.sh\n' printf 'manifest ./src/manifest.sh\n' - printf 'python-info PYTHONPATH=lib/python python -m base_demo_cli\n' + printf 'python-info ./bin/base-demo-python-info\n' ;; run\ base-demo\ --workspace\ *\ hello) printf 'hello from base-demo\n' diff --git a/tests/validate.sh b/tests/validate.sh index 899b216..92ffa0b 100755 --- a/tests/validate.sh +++ b/tests/validate.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -set -euo pipefail required_files=( README.md @@ -10,6 +9,7 @@ required_files=( base_manifest.yaml Brewfile .base/activate.sh + bin/base-demo-python-info src/hello.sh src/env.sh src/manifest.sh @@ -27,7 +27,7 @@ for file in "${required_files[@]}"; do } done -for executable in tests/validate.sh .base/activate.sh src/hello.sh src/env.sh src/manifest.sh demo/demo.sh; do +for executable in tests/validate.sh .base/activate.sh bin/base-demo-python-info src/hello.sh src/env.sh src/manifest.sh demo/demo.sh; do [[ -x "$executable" ]] || { printf 'Required file is not executable: %s\n' "$executable" >&2 exit 1 @@ -64,7 +64,7 @@ grep -Fq 'manifest: ./src/manifest.sh' base_manifest.yaml || { exit 1 } -grep -Fq 'python-info: PYTHONPATH=lib/python python -m base_demo_cli' base_manifest.yaml || { +grep -Fq 'python-info: ./bin/base-demo-python-info' base_manifest.yaml || { printf 'base_manifest.yaml does not declare the python-info command.\n' >&2 exit 1 }