Skip to content

Commit

Permalink
fix(config): rename invalid bash environment vars
Browse files Browse the repository at this point in the history
Avoid the usage of "-" inside envs
  • Loading branch information
matthiasschaub committed Dec 7, 2023
1 parent 4f56cd1 commit d237f0e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ file.

The default path of the configuration file is `config/config.toml`.
A sample configuration file can be found in the same directory: `config/sample.config.toml`.
All configuration files in this directory (`config`) will be ignored by Git. To change the default configuration file path for OQT set the environment variable `SMT-CONFIG` to the desired path.
All configuration files in this directory (`config`) will be ignored by Git. To change the default configuration file path for OQT set the environment variable `SMT_CONFIG` to the desired path.

To create a new configuration file simply copy the sample configuration file and change the values.

Expand All @@ -18,4 +18,4 @@ cp sample.config.toml config.toml

## Required Configuration

Except of the API token (`SMT-NEPTUNE-API-TOKEN`) for neptune.ai all configuration values come with defaults for development purposes. Please make sure to configure the API token for your environment.
Except of the API token (`SMT_NEPTUNE_API_TOKEN`) for neptune.ai all configuration values come with defaults for development purposes. Please make sure to configure the API token for your environment.
30 changes: 15 additions & 15 deletions sketch_map_tool/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
def get_config_path() -> str:
"""Get configuration file path
Read value of the environment variable 'OQT-CONFIG' or use default 'config.toml'
Read value of the environment variable 'SMT_CONFIG' or use default 'config.toml'
"""
default = str(get_project_root() / "config" / "config.toml")
return os.getenv("SMT-CONFIG", default=default)
return os.getenv("SMT_CONFIG", default=default)


def load_config_default() -> Dict[str, str | int | float]:
Expand Down Expand Up @@ -48,19 +48,19 @@ def load_config_from_file(path: str) -> Dict[str, str]:
def load_config_from_env() -> Dict[str, str]:
"""Load configuration from environment variables."""
cfg = {
"data-dir": os.getenv("SMT-DATA-DIR"),
"user-agent": os.getenv("SMT-USER-AGENT"),
"broker-url": os.getenv("SMT-BROKER-URL"),
"result-backend": os.getenv("SMT-RESULT-BACKEND"),
"wms-url": os.getenv("SMT-WMS-URL"),
"wms-layers": os.getenv("SMT-WMS-LAYERS"),
"wms-read-timeout": os.getenv("SMT-WMS-READ-TIMEOUT"),
"max-nr-simultaneous-uploads": os.getenv("SMT-MAX-NR-SIM-UPLOADS"),
"max_pixel_per_image": os.getenv("MAX-PIXEL-PER-IMAGE"),
"neptune_project": os.getenv("SMT-NEPTUNE-PROJECT"),
"neptune_api_token": os.getenv("SMT-NEPTUNE-API-TOKEN"),
"neptune_model_id_yolo": os.getenv("SMT-NEPTUNE-MODEL-ID-YOLO"),
"neptune_model_id_sam": os.getenv("SMT-NEPTUNE-MODEL-ID-SAM"),
"data-dir": os.getenv("SMT_DATA_DIR"),
"user-agent": os.getenv("SMT_USER_AGENT"),
"broker-url": os.getenv("SMT_BROKER_URL"),
"result-backend": os.getenv("SMT_RESULT_BACKEND"),
"wms-url": os.getenv("SMT_WMS_URL"),
"wms-layers": os.getenv("SMT_WMS_LAYERS"),
"wms-read-timeout": os.getenv("SMT_WMS_READ_TIMEOUT"),
"max-nr-simultaneous-uploads": os.getenv("SMT_MAX_NR_SIM_UPLOADS"),
"max_pixel_per_image": os.getenv("SMT_MAX_PIXEL_PER_IMAGE"),
"neptune_project": os.getenv("SMT_NEPTUNE_PROJECT"),
"neptune_api_token": os.getenv("SMT_NEPTUNE_API_TOKEN"),
"neptune_model_id_yolo": os.getenv("SMT_NEPTUNE_MODEL_ID_YOLO"),
"neptune_model_id_sam": os.getenv("SMT_NEPTUNE_MODEL_ID_SAM"),
}
return {k: v for k, v in cfg.items() if v is not None}

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def postgres_container(monkeypatch_session):
port=postgres.get_exposed_port(5432), # 5432 is default port of postgres
database=postgres.POSTGRES_DB,
)
monkeypatch_session.setenv("SMT-RESULT-BACKEND", conn)
monkeypatch_session.setenv("SMT_RESULT_BACKEND", conn)
yield {"connection_url": conn}
# cleanup

Expand All @@ -53,7 +53,7 @@ def redis_container(monkeypatch_session):
with RedisContainer("redis:7") as redis:
port = redis.get_exposed_port(6379) # 6379 is default port of redis
conn = f"redis://127.0.0.1:{port}"
monkeypatch_session.setenv("SMT-BROKER-URL", conn)
monkeypatch_session.setenv("SMT_BROKER_URL", conn)
yield {"connection_url": conn}
# cleanup

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sketch_map_tool.exceptions import UploadLimitsExceededError


@mock.patch.dict(os.environ, {"SMT-MAX-NR-SIM-UPLOADS": "2"})
@mock.patch.dict(os.environ, {"SMT_MAX_NR_SIM_UPLOADS": "2"})
def test_max_nr_sim_uploades(flask_client, sketch_map_buffer):
with pytest.raises(UploadLimitsExceededError):
flask_client.post(
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def config_keys():


def test_get_config_path_empty_env(monkeypatch):
monkeypatch.delenv("SMT-CONFIG", raising=False)
monkeypatch.delenv("SMT_CONFIG", raising=False)
assert config.get_config_path() == os.path.abspath(
os.path.join(
os.path.dirname(__file__),
Expand All @@ -49,19 +49,19 @@ def test_get_config_path_empty_env(monkeypatch):


def test_get_config_path_set_env(monkeypatch):
monkeypatch.setenv("SMT-CONFIG", "/some/absolute/path")
monkeypatch.setenv("SMT_CONFIG", "/some/absolute/path")
assert config.get_config_path() == "/some/absolute/path"


def test_config_default(monkeypatch, config_keys):
monkeypatch.delenv("SMT-CONFIG", raising=False)
monkeypatch.delenv("SMT_CONFIG", raising=False)
cfg = config.load_config_default()
assert tuple(cfg.keys()) == config_keys


def test_load_config_from_file(monkeypatch):
monkeypatch.setenv(
"SMT-CONFIG",
"SMT_CONFIG",
os.path.join(
os.path.dirname(os.path.abspath(__file__)), "fixtures", "config.toml"
),
Expand All @@ -80,7 +80,7 @@ def test_load_config_from_env_empty():

@mock.patch.dict(
"os.environ",
{"SMT-DATA-DIR": "foo", "SMT-USER-AGENT": "bar"},
{"SMT_DATA_DIR": "foo", "SMT_USER_AGENT": "bar"},
clear=True,
)
def test_load_config_from_env_set():
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_get_config_value(config_keys):

@mock.patch.dict(
"os.environ",
{"SMT-CONFIG": ""},
{"SMT_CONFIG": ""},
clear=True,
)
def test_get_config_env_empty_str(config_keys):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_validate_type_invalid(type_):

def test_validate_file_by_pixel_count(files, monkeypatch):
with pytest.raises(UploadLimitsExceededError):
monkeypatch.setenv("MAX-PIXEL-PER-IMAGE", "10")
monkeypatch.setenv("SMT_MAX_PIXEL_PER_IMAGE", "10")
validate_uploaded_sketchmaps(files)


Expand Down

0 comments on commit d237f0e

Please sign in to comment.