Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and willGraham01 committed Aug 21, 2023
1 parent f70aab9 commit 2f88b1e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- name: Checkout repository
Expand Down
4 changes: 2 additions & 2 deletions src/brainreg/backend/niftyreg/niftyreg_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def get_binary(program_name: str) -> Path:
bin_path = packaged_binaries_folder / os_folder_name / program_name

# Append exe label to Windows executables
# It looks like subprocess is actually able to cope without the .exe appended,
# but just to be safe we'll include it on Windows OS calls
# It looks like subprocess is actually able to cope without the .exe
# appended, but just to be safe we'll include it on Windows OS calls
if _IS_WINDOWS_OS:
bin_path = bin_path.parent / f"{bin_path.stem}.exe"
return bin_path
52 changes: 38 additions & 14 deletions tests/tests/test_backend/test_niftyreg_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ def packaged_binaries_are_used() -> Tuple[bool, Path]:
"""
Return a (bool, Path) tuple which has the values:
boolean:
TRUE if the get_binary function points to one of the niftyreg binaries
that are included with the package.
TRUE if the get_binary function points to one of the niftyreg
binaries that are included with the package.
FALSE otherwise.
Path:
The path to the folder containing the niftyreg binaries that were found
The path to the folder containing the niftyreg binaries that
were found.
"""
using_binary = get_binary("reg_aladin")
return (
Expand All @@ -29,31 +30,54 @@ def packaged_binaries_are_used() -> Tuple[bool, Path]:
def test_conda_with_niftyreg():
"""
Check the following:
- If we are not in a conda environment, the packaged niftyreg binaries are used by the backend
- If we are in a conda environment and niftyreg is not conda-installed, the packaged niftyreg binaries are used by the backend
- If we are in a conda environment and niftyreg IS conda-installed, the conda-installed binaries are used by the backend.
- If we are not in a conda environment, the packaged niftyreg binaries
are used by the backend
- If we are in a conda environment and niftyreg is not conda-installed,
the packaged niftyreg binaries are used by the backend
- If we are in a conda environment and niftyreg IS conda-installed,
the conda-installed binaries are used by the backend.
We need the assert_msg's to get round mypy thinking we're passing tuples
to assert (since Tuples always evaluate to true, and mypy wants to split
long code lines).
"""
if "CONDA_PREFIX" not in os.environ:
# We are not in a conda envrionment
# _CONDA_NIFTYREG_BINARY_PATH should be none
assert (
_CONDA_NIFTYREG_BINARY_PATH is None
), f"Not in a conda environment but _CONDA_NIFTYREG_BINARY_PATH is non-None: {_CONDA_NIFTYREG_BINARY_PATH}"
assert_msg = (
"Not in a conda environment but "
"_CONDA_NIFTYREG_BINARY_PATH is non-None: "
f"{_CONDA_NIFTYREG_BINARY_PATH}"
)
assert _CONDA_NIFTYREG_BINARY_PATH is None, assert_msg

using_packaged_binaries, bin_folder = packaged_binaries_are_used()
assert (
using_packaged_binaries
), f"There is no CONDA_PREFIX, but non-packaged binaries in {bin_folder} are being used!"
assert_msg = (
"There is no CONDA_PREFIX, "
f"but non-packaged binaries in {bin_folder} "
"are being used!"
)
assert using_packaged_binaries, assert_msg
else:
# We are in a conda environment.
# Either this environment does not have niftyreg installed, or it does.
if _CONDA_NIFTYREG_BINARY_PATH is None:
# Apparently niftyreg is not installed in this environment
# Assert the located binaries are the packaged ones
using_packaged_binaries, bin_folder = packaged_binaries_are_used()
assert using_packaged_binaries, f"Conda environment without niftyreg installed exists, but non-packaged binaries in {bin_folder} are being used."
assert_msg = (
"Conda environment without niftyreg installed exists, "
f"but non-packaged binaries in {bin_folder} "
"are being used."
)
assert using_packaged_binaries, assert_msg
else:
# We are in a conda environment that _has_ niftyreg conda-installed
# Assert that we are using the CONDA-installed binaries
using_packaged_binaries, bin_folder = packaged_binaries_are_used()
assert not using_packaged_binaries, f"Packaged binaries are being used despite appearing to be installed by CONDA at {_CONDA_NIFTYREG_BINARY_PATH}"
assert_msg = (
"Packaged binaries are being used, "
"despite niftyreg appearing to be installed by CONDA "
f" at {_CONDA_NIFTYREG_BINARY_PATH}"
)
assert not using_packaged_binaries, assert_msg

0 comments on commit 2f88b1e

Please sign in to comment.