From caea16ef8b96d69c4e47e4fde713d6fc8b8609bc Mon Sep 17 00:00:00 2001 From: Philip Cook Date: Sun, 18 Feb 2024 16:26:30 -0500 Subject: [PATCH 1/3] ENH: Set path to source for coverage tests --- .github/workflows/code-coverage.yml | 10 +++++++++- tests/run_tests.sh | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index 7515958b..49861e5f 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -24,8 +24,16 @@ jobs: - name: Install coverage run: python -m pip install coverage + - name: Find installed package path + id: find_package_path + run: > + echo "PACKAGE_PATH=$(python -c 'import importlib.util; + package_name=\"ants\"; package_spec=importlib.util.find_spec(package_name); + print(package_spec.submodule_search_locations[0] if package_spec else \"\")')" + >> $GITHUB_ENV + - name: Unit tests - run: tests/run_tests.sh -c + run: tests/run_tests.sh -c -s ${PACKAGE_PATH} - name: Coveralls uses: coverallsapp/github-action@v2 diff --git a/tests/run_tests.sh b/tests/run_tests.sh index fa6c947c..a43cdb2f 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -3,10 +3,12 @@ set -e PYCMD=${PYCMD:="python3"} COVERAGE=0 +SOURCE="ants" while [[ "$#" -gt 0 ]]; do case "$1" in -p|--python) PYCMD=$2; shift 2 ;; -c|--coverage) COVERAGE=1; shift 1;; + -s|--source) SOURCE=$2; shift 2 ;; --) shift; break ;; *) echo "Invalid argument: $1!" ; exit 1 ;; esac @@ -14,7 +16,7 @@ done if [[ $COVERAGE -eq 1 ]]; then coverage erase - PYCMD="coverage run --parallel-mode --source ants " + PYCMD="coverage run --parallel-mode --source $SOURCE " echo "coverage flag found. Setting command to: \"$PYCMD\"" fi @@ -50,6 +52,7 @@ $PYCMD test_bugs.py $@ if [[ $COVERAGE -eq 1 ]]; then coverage combine coverage html + coverage xml fi From 5b6d69bb33f7423cbfcaa0a685839c4b50859e72 Mon Sep 17 00:00:00 2001 From: Philip Cook Date: Sun, 18 Feb 2024 16:31:32 -0500 Subject: [PATCH 2/3] [skip ci] ENH: Remove unnecessary parameter Github already lets you choose the branch to run on, seems there's no need to do it explicitly --- .github/workflows/code-coverage.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index 49861e5f..ea2f66ba 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -4,10 +4,6 @@ on: - master workflow_dispatch: - inputs: - branch: - description: 'Branch name' - required: true name: codecov From f90e610308f8aadd63c6bf1ccee040fcde0e6bdc Mon Sep 17 00:00:00 2001 From: Philip Cook Date: Sun, 18 Feb 2024 17:31:04 -0500 Subject: [PATCH 3/3] [skip ci] BUG: Attempt at inline python script didn't work so well --- .github/workflows/code-coverage.yml | 7 ++----- tests/find_package_path.py | 7 +++++++ 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 tests/find_package_path.py diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index ea2f66ba..844e0789 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -22,11 +22,8 @@ jobs: - name: Find installed package path id: find_package_path - run: > - echo "PACKAGE_PATH=$(python -c 'import importlib.util; - package_name=\"ants\"; package_spec=importlib.util.find_spec(package_name); - print(package_spec.submodule_search_locations[0] if package_spec else \"\")')" - >> $GITHUB_ENV + run: | + echo "PACKAGE_PATH=$(python tests/find_package_path.py)" >> $GITHUB_ENV - name: Unit tests run: tests/run_tests.sh -c -s ${PACKAGE_PATH} diff --git a/tests/find_package_path.py b/tests/find_package_path.py new file mode 100644 index 00000000..23b3e253 --- /dev/null +++ b/tests/find_package_path.py @@ -0,0 +1,7 @@ +import importlib.util + +# This is used for CI scripts to find the location of the installed package + +package_name = 'ants' +package_spec = importlib.util.find_spec(package_name) +print(package_spec.submodule_search_locations[0] if package_spec else '') \ No newline at end of file