Skip to content

Commit

Permalink
Add public config_file attribute to Config classes (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa authored Dec 18, 2024
1 parent 3cc9ab5 commit 0af13bb
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ CI_CONDA_DIR=/tmp/conda
CI_CONDA_SH=$CI_CONDA_DIR/etc/profile.d/conda.sh

ci_conda_activate() {
source $CI_CONDA_SH
. $CI_CONDA_SH
conda activate
}
2 changes: 1 addition & 1 deletion .github/scripts/format-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ unformatted() {
return 0
}

source $(dirname ${BASH_SOURCE[0]})/common.sh
. $(dirname ${BASH_SOURCE[0]})/common.sh
ci_conda_activate
CONDEV_SHELL_CMD=unformatted condev-shell
2 changes: 1 addition & 1 deletion .github/scripts/install-conda.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set -eux
source $(dirname ${BASH_SOURCE[0]})/common.sh
. $(dirname ${BASH_SOURCE[0]})/common.sh
url=https://github.com/conda-forge/miniforge/releases/download/24.3.0-0/Miniforge3-Linux-x86_64.sh
installer=/tmp/$(basename $url)
wget --no-verbose -O $installer $url
Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/make-docs.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set -ae
source $(dirname ${BASH_SOURCE[0]})/common.sh
. $(dirname ${BASH_SOURCE[0]})/common.sh
ci_conda_activate
cd docs
source install-deps
. install-deps
make docs
2 changes: 1 addition & 1 deletion .github/scripts/make-package.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set -ae
source $(dirname ${BASH_SOURCE[0]})/common.sh
. $(dirname ${BASH_SOURCE[0]})/common.sh
ci_conda_activate
set -x
make package
2 changes: 1 addition & 1 deletion .github/scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set -ae
source $(dirname ${BASH_SOURCE[0]})/common.sh
. $(dirname ${BASH_SOURCE[0]})/common.sh
ci_conda_activate
set -ux
f=recipe/meta.json
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ run_tests() {
return $status
}

source $(dirname ${BASH_SOURCE[0]})/common.sh
. $(dirname ${BASH_SOURCE[0]})/common.sh
ci_conda_activate
for version in ${SUPPORTED_PYTHON_VERSIONS[*]}; do
PYTHON_VERSION=$version
Expand Down
2 changes: 1 addition & 1 deletion docs/deps
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ for dep in deps:
pkg, ver = m.groups()
if re.match(r"^\d", ver):
ver = f"={ver}"
specs.append(f"'{pkg}{ver}'")
specs.append(f"{pkg}{ver}")
print(" ".join(sorted(specs)))
2 changes: 1 addition & 1 deletion format
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ echo "=> Running docformatter"
(cd src && docformatter . || test $? -eq 3)

echo "=> Running jq"
for a in $(find src -type f -name "*.jsonschema"); do
for a in $(find src -not -path "*/.*" -type f -name "*.json*"); do
b=$(jq -S . $a) && echo "$b" >$a || (echo " in $a"; false)
done
2 changes: 1 addition & 1 deletion recipe/meta.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"build": "py_0",
"buildnum": "0",
"buildnum": 0,
"name": "uwtools",
"packages": {
"dev": [
Expand Down
7 changes: 7 additions & 0 deletions src/uwtools/config/formats/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ def compare_config(
log.info(diffline.rstrip())
return False

@property
def config_file(self) -> Optional[Path]:
"""
Return the path to the config file from which this object was instantiated, if applicable.
"""
return self._config_file

def dereference(self, context: Optional[dict] = None) -> None:
"""
Render as much Jinja2 syntax as possible.
Expand Down
4 changes: 2 additions & 2 deletions src/uwtools/resources/info.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "2.5.0",
"buildnum": "0"
"buildnum": "0",
"version": "2.5.0"
}
5 changes: 5 additions & 0 deletions src/uwtools/tests/config/formats/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ def test_compare_config_ini(caplog, salad_base):
assert not logged(caplog, line)


def test_config_file(config):
assert config.config_file.name == "config.yaml"
assert config.config_file.is_file()


def test_dereference(tmp_path):
# Test demonstrates that:
# - Config dereferencing ignores environment variables.
Expand Down

0 comments on commit 0af13bb

Please sign in to comment.