single-cell-data / TileDB-SOMA

Python and R SOMA APIs using TileDB’s cloud-native format. Ideal for single-cell data at any scale.
https://tiledbsoma.readthedocs.io
MIT License
90 stars 25 forks source link

shellcheck `scripts/bld` #2927

Closed ryan-williams closed 1 month ago

ryan-williams commented 1 month ago

Issue and/or context

#2218 (comment)
> `$"LD_LIBRARY_PATH"` evaluates to the string `LD_LIBRARY_PATH`; the `$` needs to be inside the quotes: > > ```bash > docker run --rm bash -c 'foo=1; echo $"foo" "$foo"' > # foo 1 > ``` > > `[ -z $"LD_LIBRARY_PATH" ]` is always false, so we've inadvertently been doing what @bkmartinjr suggested (always prepending `${tiledb}:`). I think this is also why the `set +u` seemed necessary; the "append" block was running even with `LD_LIBRARY_PATH` unset, which `set -u` was flagging as an error. > > A common way of doing these two `if` blocks is: > ```bash > export LD_LIBRARY_PATH="$tiledb${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" > export DYLD_LIBRARY_PATH="$tiledb${DYLD_LIBRARY_PATH:+:$DYLD_LIBRARY_PATH}" > ``` > cf. [SO](https://stackoverflow.com/a/46892074). This also works in `sh`: > ```bash > test() { > docker run --rm --entrypoint sh ubuntu -c "set -u; $1" > } > > test 'echo "prepended_val${foo:+:$foo}"' # `foo` unset > # prepended_val > test 'foo=; echo "prepended_val${foo:+:$foo}"' # `foo` empty > # prepended_val > test 'foo=val; echo "prepended_val${foo:+:$foo}"' # `foo` nonempty > # prepended_val:val > test 'echo "prepended_val${foo:+:}$foo"' # `foo` unset, and used outside `${foo:+…}` guard ⟹ `set -u` errors (as expected) > # sh: 1: foo: parameter not set > ``` > though I'd think this file's shebang line ensures we're always running `bash`.

Changes

Fix "$ outside quotes" issue, replace ifs with ${var:+…}, remove set +u/set -u:

-if [ -z $"LD_LIBRARY_PATH" ]; then
-  export LD_LIBRARY_PATH="${tiledb}"
-else
-  export LD_LIBRARY_PATH="${tiledb}:${LD_LIBRARY_PATH}"
-fi
+export LD_LIBRARY_PATH="$tiledb${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"

Use echo instead of printf (per SC2059):

-printf "Building ${build} build\n"
+echo "Building ${build} build"
codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 90.03%. Comparing base (9ac3b4a) to head (8acd769). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2927 +/- ## ========================================== + Coverage 89.88% 90.03% +0.15% ========================================== Files 37 37 Lines 3925 3925 ========================================== + Hits 3528 3534 +6 + Misses 397 391 -6 ``` | [Flag](https://app.codecov.io/gh/single-cell-data/TileDB-SOMA/pull/2927/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=single-cell-data) | Coverage Δ | | |---|---|---| | [python](https://app.codecov.io/gh/single-cell-data/TileDB-SOMA/pull/2927/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=single-cell-data) | `90.03% <ø> (+0.15%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=single-cell-data#carryforward-flags-in-the-pull-request-comment) to find out more. | [Components](https://app.codecov.io/gh/single-cell-data/TileDB-SOMA/pull/2927/components?src=pr&el=components&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=single-cell-data) | Coverage Δ | | |---|---|---| | [python_api](https://app.codecov.io/gh/single-cell-data/TileDB-SOMA/pull/2927/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=single-cell-data) | `90.03% <ø> (+0.15%)` | :arrow_up: | | [libtiledbsoma](https://app.codecov.io/gh/single-cell-data/TileDB-SOMA/pull/2927/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=single-cell-data) | `∅ <ø> (∅)` | |
ryan-williams commented 1 month ago

(R CI failure is unrelated, #2906)