Skip to main content

Tidy up the logic in ts based on repo name

ID
badab58
date
2025-05-07 13:25:27+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
01cce41
message
Tidy up the logic in `ts` based on repo name
changed files
1 file, 44 additions, 34 deletions

Changed files

ts (2540) → ts (2986)

diff --git a/ts b/ts
index cacee96..75ab585 100755
--- a/ts
+++ b/ts
@@ -4,24 +4,34 @@ set -o errexit
 set -o nounset
 
 function run_python_tests() {
+    REPO_NAME="$(basename $(pwd))"
   
     # In the test suites for flickr.org work, I need a Flickr API key
     # to run certain tests.
     #
     # If I need an API key for my tests, retrieve it from the keychain.
-    if grep -rIq 'FLICKR_API_KEY' tests
+    if [[ "$REPO_NAME" = "commons.flickr.org" ]]
     then
-      export FLICKR_API_KEY=$(keyring get flickr_api key 2>/dev/null)
+        print_info 'export FLICKR_API_KEY=$(keyring get flickr_api key)'
+        export FLICKR_API_KEY=$(keyring get flickr_api key)
+        
+        echo ""
+    elif [[ "$REPO_NAME" = "data-lifeboat" ]]
+    then
+        print_info 'export FLICKR_API_KEY=$(keyring get data_lifeboat_creator flickr_client_key)'
+        export FLICKR_API_KEY=$(keyring get data_lifeboat_creator flickr_client_key)
+        
+        echo ""
     fi
 
     # Run ruff to do Python formatting
     if [[ "${1:-}" == "--fix" ]]
     then
-      print_info "-> ruff check --fix"
-      ruff check --fix .
+        print_info "-> ruff check --fix"
+        ruff check --fix .
     else
-      print_info "-> ruff check"
-      ruff check .
+        print_info "-> ruff check"
+        ruff check .
     fi
     
     echo ""
@@ -41,19 +51,19 @@ function run_python_tests() {
 
     # This is one repo which is a bit special -- I'm gradually trying to chase
     # the code into `src`, but for now I have to remmeber to look at *.py
-    if [[ "$(pwd)" == ~/repos/library-lookup ]]
+    if [[ "$REPO_NAME" = "library-lookup" ]]
     then
-      print_info '-> mypy *.py src tests'
-      mypy *.py src tests
+        print_info '-> mypy *.py src tests'
+        mypy *.py src tests
     else
-      print_info '-> mypy src tests'
+        print_info '-> mypy src tests'
       
-      if mypy src tests >/dev/null
-      then
-        mypy src tests --no-color-output
-      else
-        mypy src tests
-      fi
+        if mypy src tests >/dev/null
+        then
+            mypy src tests --no-color-output
+        else
+            mypy src tests
+        fi
     fi
     
     echo ""
@@ -63,30 +73,30 @@ function run_python_tests() {
     # I have a couple of repos which are a bit special and need a
     # different command because I use pytest-xdist, but not all
     # my repos work that way.
-    if [[ "$(pwd)" = ~/repos/commons.flickr.org ]]
+    if [[ "$REPO_NAME" = "commons.flickr.org" ]]
     then
-      print_info "-> pytest tests/ --ignore uptime_tests/ --quiet"
-      pytest --cov=src --cov=tests tests --ignore uptime_tests --quiet
-    elif [[ "$(pwd)" = ~/repos/data-lifeboat ]] ||
-         [[ "$(pwd)" = ~/repos/flickr-photos-api ]] ||
-         [[ "$(pwd)" = ~/repos/analytics.alexwlchan.net ]]
+        print_info "-> pytest tests/ --ignore uptime_tests/ --quiet"
+        pytest --cov=src --cov=tests tests --ignore uptime_tests --quiet
+    elif [[ "$REPO_NAME" = "data-lifeboat" ]] ||
+         [[ "$REPO_NAME" = "flickr-photos-api" ]] ||
+         [[ "$REPO_NAME" = "analytics.alexwlchan.net" ]]
     then
-      print_info "-> pytest tests"
-      pytest tests/ --quiet
+        print_info "-> pytest tests"
+        pytest tests/ --quiet
     else
-      print_info "-> coverage run -m pytest tests"
-      coverage run -m pytest tests --quiet
+        print_info "-> coverage run -m pytest tests"
+        coverage run -m pytest tests --quiet
       
-      echo ""
+        echo ""
     
-      print_info "-> coverage report"
+        print_info "-> coverage report"
     
-      if [[ $(coverage report --format=total) = "100" ]]
-      then
-        echo "100% coverage!"
-      else
-        coverage report
-      fi
+        if [[ $(coverage report --format=total) = "100" ]]
+        then
+            echo "100% coverage!"
+        else
+            coverage report
+        fi
     fi
 }