Skip to content
Snippets Groups Projects
Commit 102da6b5 authored by Em Zhan's avatar Em Zhan
Browse files

Add SIPSANC_DATA_DIR and SIPSANC_LOG_DIR env vars

Allows changing where `sipsanc init` saves its files and where any
errors in all `sipsanc` subcommands are saved, respectively

Uses these variables in tests to separate the test instance of `sipsanc`
from the local install
parent 6ad55fda
No related branches found
No related tags found
No related merge requests found
Pipeline #57700 passed
......@@ -10,6 +10,8 @@ wheels/
.venv
# Test data
/tests/data/
/tests/log/
/tests/tmp/
/tests/fails/
/plots*/
......
......@@ -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.
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"
......
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!")
......@@ -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)
......
......@@ -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=[
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment