Coverage for bioimageio/spec/_internal/_settings.py: 91%
35 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-02-05 13:53 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-02-05 13:53 +0000
1from pathlib import Path
2from typing import Optional, Union
4import pooch # pyright: ignore [reportMissingTypeStubs]
5from pydantic import Field
6from pydantic_settings import BaseSettings, SettingsConfigDict
7from typing_extensions import Annotated
10class Settings(BaseSettings, extra="ignore"):
11 """environment variables for bioimageio.spec"""
13 model_config = SettingsConfigDict(
14 env_prefix="BIOIMAGEIO_", env_file=".env", env_file_encoding="utf-8"
15 )
17 cache_path: Path = pooch.os_cache("bioimageio")
18 """bioimageio cache location"""
20 id_map: str = (
21 "https://uk1s3.embassy.ebi.ac.uk/public-datasets/bioimage.io/id_map.json"
22 )
23 """url to bioimageio id_map.json to resolve resource IDs.
24 """
26 id_map_draft: str = (
27 "https://uk1s3.embassy.ebi.ac.uk/public-datasets/bioimage.io/id_map_draft.json"
28 )
29 """url to bioimageio id_map_draft.json to resolve draft IDs ending with '/draft'."""
31 resolve_draft: bool = True
32 """Flag to resolve draft resource versions following the pattern
33 <resource id>/draft.
34 Note that anyone may stage a new draft and that such a draft version
35 may not have been reviewed yet.
36 Set this flag to False to avoid this potential security risk
37 and disallow loading draft versions."""
39 perform_io_checks: bool = True
40 """wether or not to perform validation that requires file io,
41 e.g. downloading a remote files.
43 Existence of any local absolute file paths is still being checked."""
45 log_warnings: bool = True
46 """log validation warnings to console"""
48 github_username: Optional[str] = None
49 """GitHub username for API requests"""
51 github_token: Optional[str] = None
52 """GitHub token for API requests"""
54 CI: Annotated[Union[bool, str], Field(alias="CI")] = False
55 """wether or not the execution happens in a continuous integration (CI) environment"""
57 user_agent: Optional[str] = None
58 """user agent for http requests"""
60 @property
61 def github_auth(self):
62 if self.github_username is None or self.github_token is None:
63 return None
64 else:
65 return (self.github_username, self.github_token)
68settings = Settings()
69"""parsed environment variables for bioimageio.spec"""