Coverage for mlos_bench/mlos_bench/os_environ.py: 56%
9 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-07 01:52 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-07 01:52 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""
6Simple platform agnostic abstraction for the OS environment variables. Meant as a
7replacement for os.environ vs nt.environ.
9Example
10-------
11from mlos_bench.os_env import environ
12environ['FOO'] = 'bar'
13environ.get('PWD')
14"""
16import os
17import sys
19if sys.version_info >= (3, 10):
20 from typing import TypeAlias
21else:
22 from typing_extensions import TypeAlias
24if sys.version_info >= (3, 9):
25 # pylint: disable=protected-access,disable=unsubscriptable-object
26 EnvironType: TypeAlias = os._Environ[str]
27else:
28 EnvironType: TypeAlias = os._Environ # pylint: disable=protected-access
30# Handle case sensitivity differences between platforms.
31# https://stackoverflow.com/a/19023293
32if sys.platform == "win32":
33 import nt # type: ignore[import-not-found] # pylint: disable=import-error # (3.8)
35 environ: EnvironType = nt.environ
36else:
37 environ: EnvironType = os.environ
39__all__ = ["environ"]