#!/bin/bash

# Get current script path
SCRIPT_PATH="$(dirname -- "$(readlink -f -- "${0}")")"
# Activate OctoDNS Python venv
source "${SCRIPT_PATH}/common.sh"

SOURCES="$(find *.py octodns tests docs -name '*.py') $(grep --files-with-matches '^#!.*python' script/*)"

PRAGMA_OUTPUT=$(grep -r -I --line-number "\<p\?print(" octodns/ tests/ || echo)
PRAGMA_COUNT=$(echo "$PRAGMA_OUTPUT" | grep -c . || true)
PRAGMA_ALLOWED=3
if [ "$PRAGMA_COUNT" -ne "$PRAGMA_ALLOWED" ]; then
  echo "Found $PRAGMA_COUNT instances of 'print(' (no more than $PRAGMA_ALLOWED allowed):"
  echo "$PRAGMA_OUTPUT"
  echo "print( should not be used in library code, only in commands"
  exit 1
fi

pyflakes $SOURCES
