diff --git a/.gitignore b/.gitignore index 89af34bcf893189f09f838c81256678ee5ad278c..bb4e3f142062d3ec0663c9e4c0d6ed567be2392b 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ wheels/ .venv # Test data +/tests/data/ +/tests/log/ /tests/tmp/ /tests/fails/ /plots*/ diff --git a/README.md b/README.md index 6397faaad7573ac063a8c0c9731efde6c763fb6d..cd5fc7eabdfbdf3ae9f5ce3b1d1cbd1efdd71060 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,17 @@ To upgrade an existing install, run: uv tool upgrade sipsanc ``` +## Environment Variables + +By default, `sipsanc` will save files in [standard user data directories](https://github.com/tox-dev/platformdirs). These locations can be configured by setting the following environment variables: + +```sh +export SIPSANC_DATA_DIR=my/custom/path/ +export SIPSANC_LOG_DIR=another/custom/path # can be the same as SIPSANC_DATA_DIR +``` + +This is useful for testing or making self-contained code deliveries. + ## Contributing See [CONTRIBUTING.md](https://gitlab.ssec.wisc.edu/emzhan/sipsanc/-/blob/main/CONTRIBUTING.md) for how to set up a development environment. diff --git a/src/sipsanc/cli.py b/src/sipsanc/cli.py index bff7b6e38bcd2920d9fcf6dc14986bbf8fda922e..cd7d5662c22259c6d8b90984742ecaf753de1c6f 100644 --- a/src/sipsanc/cli.py +++ b/src/sipsanc/cli.py @@ -1,4 +1,5 @@ import logging +import os import shutil import sys import traceback @@ -17,8 +18,11 @@ Source = Literal["release", "sipssci1", "dev"] DIRS = PlatformDirs("sipsanc", "SSEC") INIT_DIR_VERSION = 1 -INIT_DIR = DIRS.user_data_path / f"v{INIT_DIR_VERSION}" -LOG_DIR = DIRS.user_log_path + +DATA_DIR = Path(os.environ.get("SIPSANC_DATA_DIR") or DIRS.user_data_dir) +LOG_DIR = Path(os.environ.get("SIPSANC_LOG_DIR") or DIRS.user_log_dir) + +INIT_DIR = DATA_DIR / f"v{INIT_DIR_VERSION}" LOG_DIR.mkdir(parents=True, exist_ok=True) LOG_FILE = LOG_DIR / "errors.txt" diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000000000000000000000000000000000000..c8a3dab4ca68cb7cd990a2afff339f4a558e2a20 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,18 @@ +import os +from subprocess import run + + +def pytest_sessionstart(session): + print("Setting environment variables and running `sipsanc init all`...") + + os.environ["SIPSANC_DATA_DIR"] = "tests/data/" + os.environ["SIPSANC_LOG_DIR"] = "tests/log/" + + print() + print(f"SIPSANC_DATA_DIR={os.environ['SIPSANC_DATA_DIR']}") + print(f"SIPSANC_LOG_DIR={os.environ['SIPSANC_LOG_DIR']}") + print() + + run(["sipsanc", "init", "all"], check=True) + + print("\nPre-test setup complete!") diff --git a/tests/test_cli_output.py b/tests/test_cli_output.py index cfad174e5d1a7ef0e631efa02773e2b99f4bc25c..73718ae6f5d844c0d93a8f560b96ffc88ad39f1e 100644 --- a/tests/test_cli_output.py +++ b/tests/test_cli_output.py @@ -35,7 +35,6 @@ def test_truth(product: str, version: str, date: str, tmp_path: Path): output = str(tmp_path / "out.nc") plots = str(tmp_path / "plots") - run(["sipsanc", "init", "all"], check=True) cmd = ["sipsanc", "regrid", "all", l1b_file, "--output", output, "--plot", plots] run(cmd, check=True) diff --git a/tests/test_output.py b/tests/test_output.py index 023e840a8adf4ab439138c49f9c757490bc0b155..7c0b63d6581503ee1e5dc27caa366a7e883b28bb 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -16,11 +16,6 @@ pytestmark = pytest.mark.skipif( ) -@pytest.fixture(scope="session", autouse=True) -def ensure_init(): - run(["sipsanc", "init", "all"], check=True) - - @pytest.fixture( scope="module", params=[