|
7 | 7 | import shutil |
8 | 8 | import sys |
9 | 9 | import tempfile |
10 | | -from typing import (Dict, Iterator, List, Match, Optional, # noqa |
| 10 | +from typing import (Any, Dict, Iterator, List, Match, Optional, # noqa |
11 | 11 | Pattern, Union, TYPE_CHECKING, Text, IO, Tuple) |
12 | 12 | import warnings |
13 | 13 | from collections import OrderedDict |
|
32 | 32 |
|
33 | 33 | class DotEnv(): |
34 | 34 |
|
35 | | - def __init__(self, dotenv_path, verbose=False, encoding=None): |
36 | | - # type: (Union[Text, _PathLike, _StringIO], bool, Union[None, Text]) -> None |
| 35 | + def __init__(self, dotenv_path, verbose=False, encoding=None, override=False): |
| 36 | + # type: (Union[Text, _PathLike, _StringIO], bool, Union[None, Text], bool) -> None |
37 | 37 | self.dotenv_path = dotenv_path # type: Union[Text,_PathLike, _StringIO] |
38 | 38 | self._dict = None # type: Optional[Dict[Text, Text]] |
39 | 39 | self.verbose = verbose # type: bool |
40 | 40 | self.encoding = encoding # type: Union[None, Text] |
| 41 | + self.override = override # type: bool |
41 | 42 |
|
42 | 43 | @contextmanager |
43 | 44 | def _get_stream(self): |
@@ -69,18 +70,16 @@ def parse(self): |
69 | 70 | if mapping.key is not None and mapping.value is not None: |
70 | 71 | yield mapping.key, mapping.value |
71 | 72 |
|
72 | | - def set_as_environment_variables(self, override=False): |
73 | | - # type: (bool) -> bool |
| 73 | + def set_as_environment_variables(self): |
| 74 | + # type: () -> None |
74 | 75 | """ |
75 | 76 | Load the current dotenv as system environemt variable. |
76 | 77 | """ |
77 | 78 | for k, v in self.dict().items(): |
78 | | - if k in os.environ and not override: |
| 79 | + if k in os.environ and not self.override: |
79 | 80 | continue |
80 | 81 | os.environ[to_env(k)] = to_env(v) |
81 | 82 |
|
82 | | - return True |
83 | | - |
84 | 83 | def get(self, key): |
85 | 84 | # type: (Text) -> Optional[Text] |
86 | 85 | """ |
@@ -265,13 +264,13 @@ def find_dotenv(filename='.env', raise_error_if_not_found=False, usecwd=False): |
265 | 264 | return '' |
266 | 265 |
|
267 | 266 |
|
268 | | -def load_dotenv(dotenv_path=None, stream=None, verbose=False, override=False, **kwargs): |
269 | | - # type: (Union[Text, _PathLike, None], Optional[_StringIO], bool, bool, Union[None, Text]) -> bool |
| 267 | +def load_dotenv(dotenv_path=None, stream=None, **kwargs): |
| 268 | + # type: (Union[Text, _PathLike, None], Optional[_StringIO], **Any) -> None |
270 | 269 | f = dotenv_path or stream or find_dotenv() |
271 | | - return DotEnv(f, verbose=verbose, **kwargs).set_as_environment_variables(override=override) |
| 270 | + return DotEnv(f, **kwargs).set_as_environment_variables() |
272 | 271 |
|
273 | 272 |
|
274 | | -def dotenv_values(dotenv_path=None, stream=None, verbose=False, **kwargs): |
275 | | - # type: (Union[Text, _PathLike, None], Optional[_StringIO], bool, Union[None, Text]) -> Dict[Text, Text] |
| 273 | +def dotenv_values(dotenv_path=None, stream=None, **kwargs): |
| 274 | + # type: (Union[Text, _PathLike, None], Optional[_StringIO], **Any) -> Dict[Text, Text] |
276 | 275 | f = dotenv_path or stream or find_dotenv() |
277 | | - return DotEnv(f, verbose=verbose, **kwargs).dict() |
| 276 | + return DotEnv(f, **kwargs).dict() |
0 commit comments