python-module/pre-commit.sh
2023-07-31 15:57:05 -07:00

21 lines
864 B
Bash
Executable file

#!/bin/bash
PROJECT_ROOT=$(git rev-parse --show-toplevel)
VERSION=$(grep 'version =' $PROJECT_ROOT/pyproject.toml | head -1 | cut -d '"' -f 2)
INIT_FILE="$PROJECT_ROOT/${REPO_NAME_SNAKE}/${REPO_NAME_SNAKE}/__init__.py"
PYPROJECT_FILE="$PROJECT_ROOT/pyproject.toml"
# Modify the CLI line to remove quotes in pyproject.toml
sed -i.bak "s/\"${REPO_NAME_SNAKE}\" = \"${REPO_NAME_SNAKE}\.cli:run\"/${REPO_NAME_SNAKE} = \"${REPO_NAME_SNAKE}\.cli:run\"/" $PYPROJECT_FILE && \
rm "$PYPROJECT_FILE.bak"
# Check if __init__.py file exists for template purposes
# This can be removed now that the template is cloned
if [ ! -f "$INIT_FILE" ]; then
echo "__init__.py does not exist yet, exiting."
exit 0
fi
# Portable workaround for macOS/Linux sed differences
sed -i.bak "s/__version__ = .*/__version__ = \"$VERSION\"/" $INIT_FILE && \
rm "$INIT_FILE.bak"