|
| 1 | +#!/bin/bash |
| 2 | +set -ex |
| 3 | + |
| 4 | +PROJECT_NAME=$(basename $1) |
| 5 | +CCDS_ROOT=$(dirname $0) |
| 6 | +MODULE_NAME=$2 |
| 7 | + |
| 8 | +# Check if poetry is installed |
| 9 | +if ! command -v poetry &> /dev/null; then |
| 10 | + echo "poetry is not installed. Please install poetry first:" |
| 11 | + echo " curl -sSL https://install.python-poetry.org | python3 -" |
| 12 | + echo " Or visit: https://python-poetry.org/docs/#installation" |
| 13 | + exit 1 |
| 14 | +fi |
| 15 | + |
| 16 | +# Configure exit / teardown behavior |
| 17 | +function finish { |
| 18 | + # Cleanup poetry environment if it exists |
| 19 | + if poetry env list | grep -q "$(basename $(pwd))"; then |
| 20 | + poetry env remove --all |
| 21 | + fi |
| 22 | +} |
| 23 | +trap finish EXIT |
| 24 | + |
| 25 | +# Source the steps in the test |
| 26 | +source $CCDS_ROOT/test_functions.sh |
| 27 | + |
| 28 | +cd $1 |
| 29 | + |
| 30 | +# Setup and run tests |
| 31 | +make |
| 32 | +make create_environment |
| 33 | +make requirements |
| 34 | + |
| 35 | +# Run poetry-specific tests with simpler commands |
| 36 | +poetry run python --version |
| 37 | +echo "Testing basic import..." |
| 38 | +poetry run python -c "import $MODULE_NAME" |
| 39 | + |
| 40 | +# Test config importable if scaffolded |
| 41 | +if [ -f "$MODULE_NAME/config.py" ]; then |
| 42 | + echo "Testing config import..." |
| 43 | + poetry run python -c "from $MODULE_NAME import config" |
| 44 | +fi |
| 45 | + |
| 46 | +# Run linting and formatting through poetry |
| 47 | +poetry run make lint |
| 48 | +poetry run make format |
| 49 | + |
| 50 | +# Custom poetry test function to avoid issues with test_functions.sh |
| 51 | +# Check that python is available in poetry environment |
| 52 | +echo "Testing poetry python availability..." |
| 53 | +if poetry run python -c "import sys" > /dev/null 2>&1; then |
| 54 | + echo "Python is available in poetry environment" |
| 55 | +else |
| 56 | + echo "ERROR: Python not available in poetry environment" |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | + |
| 60 | +echo "All done!" |
0 commit comments