Skip to content

settings

Functions:

Attributes:

APP_AUTHOR module-attribute

APP_AUTHOR = 'vsjet'

APP_NAME module-attribute

APP_NAME = 'vsscale'

ENV_KEYS module-attribute

ENV_KEYS = ('VSSCALE_GLOBAL', 'VSSCALE_{}_GLOBAL')

TOML_CONFIG module-attribute

TOML_CONFIG = ('vsjet.toml', 'pyproject.toml')

TOML_KEYS module-attribute

TOML_KEYS: tuple[list[str], ...] = (['vsscale'], ['tool', 'vsscale'])

TRUTHY module-attribute

TRUTHY = frozenset({'1', 'true', 'yes', 'on'})

get_artifacts_folder cached

get_artifacts_folder(*, global_: bool = False) -> Path

Linux: ~/.cache/vsscale/artifact

macOS: ~/Library/Caches/vsscale/artifact

Windows: ...\AppData\Local\vsjet\vsscale\Cache\artifact

Source code in vsscale/mlrt/settings.py
67
68
69
70
71
72
73
74
75
76
@cache
def get_artifacts_folder(*, global_: bool = False) -> Path:
    r"""
    Linux: ~/.cache/vsscale/artifact

    macOS: ~/Library/Caches/vsscale/artifact

    Windows: ...\AppData\Local\vsjet\vsscale\Cache\artifact
    """
    return get_cache("artifact", global_=global_) / "artifact"

get_cache cached

get_cache(thing: str, *, global_: bool = False) -> Path
Source code in vsscale/mlrt/settings.py
44
45
46
47
48
49
50
51
52
@cache
def get_cache(thing: str, *, global_: bool = False) -> Path:
    if global_ or is_global_in_env(thing):
        return get_global_cache()

    if get_toml_config().get("global", False):
        return get_global_cache()

    return get_local_cache()

get_global_cache cached

get_global_cache() -> Path
Source code in vsscale/mlrt/settings.py
34
35
36
@cache
def get_global_cache() -> Path:
    return platformdirs.user_cache_path(APP_NAME, APP_AUTHOR)

get_local_cache cached

get_local_cache() -> Path
Source code in vsscale/mlrt/settings.py
39
40
41
@cache
def get_local_cache() -> Path:
    return PackageStorage(package_name=f"{__name__}").folder

get_model_folder

get_model_folder(provider: str, version: str | None = None) -> Path
Source code in vsscale/mlrt/settings.py
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def get_model_folder(provider: str, version: str | None = None) -> Path:
    folder = get_provider_folder() / provider.lower()

    if version is None:
        latest = sorted(folder.glob("*"), reverse=True)

        if not latest:
            raise FileNotExistsError("The folder doesn't exist", get_model_folder)

        return latest[0]

    folder /= version

    if not folder.exists():
        raise FileNotExistsError("The folder doesn't exist", get_model_folder)

    return folder

get_provider_folder cached

get_provider_folder(*, global_: bool = False) -> Path

Linux: ~/.cache/vsscale/provider

macOS: ~/Library/Caches/vsscale/provider

Windows: ...\AppData\Local\vsjet\vsscale\Cache\provider

Source code in vsscale/mlrt/settings.py
55
56
57
58
59
60
61
62
63
64
@cache
def get_provider_folder(*, global_: bool = False) -> Path:
    r"""
    Linux: ~/.cache/vsscale/provider

    macOS: ~/Library/Caches/vsscale/provider

    Windows: ...\AppData\Local\vsjet\vsscale\Cache\provider
    """
    return get_cache("provider", global_=global_) / "provider"

get_toml_config

get_toml_config() -> dict[str, Any]
Source code in vsscale/mlrt/settings.py
20
21
22
23
24
25
26
27
28
29
30
31
def get_toml_config() -> dict[str, Any]:
    for config_file, keys in zip(TOML_CONFIG, TOML_KEYS):
        file = Path(config_file).expanduser().resolve().absolute()
        if file.exists():
            with file.open("rb") as f:
                config = tomllib.load(f)

            for key in keys:
                config = config.get(key, {})
            return config

    return {}

is_global_in_env

is_global_in_env(filetype: str) -> bool
Source code in vsscale/mlrt/settings.py
79
80
def is_global_in_env(filetype: str) -> bool:
    return any(env.lower() in TRUTHY for env in (os.getenv(k.format(filetype), "") for k in ENV_KEYS))