-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
734b984
commit 9c583dd
Showing
14 changed files
with
207 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
from typing import Any, Callable, Dict | ||
|
||
try: | ||
# Python 3.11 | ||
import tomllib | ||
except ImportError: # pragma: no cover | ||
# older Python | ||
import tomli as tomllib # noqa | ||
|
||
from configuration.common import ConfigurationSource | ||
from configuration.errors import MissingConfigurationFileError | ||
|
||
|
||
class TOMLFile(ConfigurationSource): | ||
def __init__( | ||
self, | ||
file_path: str, | ||
optional: bool = False, | ||
parse_float: Callable[[str], Any] = float, | ||
) -> None: | ||
super().__init__() | ||
self.file_path = file_path | ||
self.optional = optional | ||
self.parse_float = parse_float | ||
|
||
def get_values(self) -> Dict[str, Any]: | ||
if not os.path.exists(self.file_path): | ||
if self.optional: | ||
return {} | ||
raise MissingConfigurationFileError(self.file_path) | ||
|
||
with open(self.file_path, "rb") as source: | ||
return tomllib.load(source, parse_float=self.parse_float) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.