Coverage for bioimageio/spec/_internal/_settings.py: 97%

39 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-02 14:21 +0000

1from pathlib import Path 

2from typing import Optional, Union 

3 

4import pooch # pyright: ignore [reportMissingTypeStubs] 

5from pydantic import Field 

6from pydantic_settings import BaseSettings, SettingsConfigDict 

7from typing_extensions import Annotated 

8 

9 

10class Settings(BaseSettings, extra="ignore"): 

11 """environment variables for bioimageio.spec""" 

12 

13 model_config = SettingsConfigDict( 

14 env_prefix="BIOIMAGEIO_", env_file=".env", env_file_encoding="utf-8" 

15 ) 

16 

17 allow_pickle: bool = False 

18 """Sets the `allow_pickle` argument for `numpy.load()`/`numpy.save()`""" 

19 

20 cache_path: Path = pooch.os_cache("bioimageio") 

21 """bioimageio cache location""" 

22 

23 collection_http_pattern: str = ( 

24 "https://hypha.aicell.io/bioimage-io/artifacts/{bioimageio_id}/files/rdf.yaml" 

25 ) 

26 """A pattern to map bioimageio IDs to bioimageio.yaml URLs. 

27 Notes: 

28 - '{bioimageio_id}' is replaced with user query, 

29 e.g. "affable-shark" when calling `load_description("affable-shark")`. 

30 - This method takes precedence over resolving via **id_map**. 

31 - If this endpoints fails, we fall back to **id_map**. 

32 """ 

33 

34 id_map: str = ( 

35 "https://uk1s3.embassy.ebi.ac.uk/public-datasets/bioimage.io/id_map.json" 

36 ) 

37 """URL to bioimageio id_map.json to resolve resource IDs.""" 

38 

39 id_map_draft: str = ( 

40 "https://uk1s3.embassy.ebi.ac.uk/public-datasets/bioimage.io/id_map_draft.json" 

41 ) 

42 """URL to bioimageio id_map_draft.json to resolve draft IDs ending with '/draft'.""" 

43 

44 resolve_draft: bool = True 

45 """Flag to resolve draft resource versions following the pattern 

46 <resource id>/draft. 

47 Note that anyone may stage a new draft and that such a draft version 

48 may not have been reviewed yet. 

49 Set this flag to False to avoid this potential security risk 

50 and disallow loading draft versions.""" 

51 

52 perform_io_checks: bool = True 

53 """Wether or not to perform validation that requires file io, 

54 e.g. downloading a remote files. 

55 

56 Existence of any local absolute file paths is still being checked.""" 

57 

58 log_warnings: bool = True 

59 """Log validation warnings to console.""" 

60 

61 github_username: Optional[str] = None 

62 """GitHub username for API requests""" 

63 

64 github_token: Optional[str] = None 

65 """GitHub token for API requests""" 

66 

67 CI: Annotated[Union[bool, str], Field(alias="CI")] = False 

68 """Wether or not the execution happens in a continuous integration (CI) environment.""" 

69 

70 user_agent: Optional[str] = None 

71 """user agent for http requests""" 

72 

73 @property 

74 def github_auth(self): 

75 if self.github_username is None or self.github_token is None: 

76 return None 

77 else: 

78 return (self.github_username, self.github_token) 

79 

80 

81settings = Settings() 

82"""parsed environment variables for bioimageio.spec"""