python-simpleconf 0.8.0__tar.gz → 0.8.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (18) hide show
  1. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/PKG-INFO +1 -1
  2. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/pyproject.toml +1 -1
  3. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/__init__.py +1 -1
  4. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/loaders/__init__.py +2 -2
  5. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/loaders/dict.py +1 -1
  6. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/loaders/env.py +7 -3
  7. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/loaders/ini.py +9 -3
  8. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/loaders/json.py +7 -8
  9. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/loaders/osenv.py +1 -1
  10. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/loaders/toml.py +15 -14
  11. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/loaders/yaml.py +7 -8
  12. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/LICENSE +0 -0
  13. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/README.md +0 -0
  14. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/caster.py +0 -0
  15. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/config.py +0 -0
  16. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/exceptions.py +0 -0
  17. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/py.typed +0 -0
  18. {python_simpleconf-0.8.0 → python_simpleconf-0.8.2}/simpleconf/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-simpleconf
3
- Version: 0.8.0
3
+ Version: 0.8.2
4
4
  Summary: Simple configuration management with python.
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -4,7 +4,7 @@ build-backend = "poetry.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "python-simpleconf"
7
- version = "0.8.0"
7
+ version = "0.8.2"
8
8
  description = "Simple configuration management with python."
9
9
  authors = [ "pwwang <pwwang@pwwang.com>",]
10
10
  license = "MIT"
@@ -1,3 +1,3 @@
1
1
  from .config import Config, ProfileConfig
2
2
 
3
- __version__ = "0.8.0"
3
+ __version__ = "0.8.2"
@@ -52,7 +52,7 @@ class Loader(ABC):
52
52
  async def _a_exists(self, conf: str | Path, ignore_exist: bool) -> bool:
53
53
  """Asynchronously check if the configuration file exists"""
54
54
  path = self.__class__._convert_path(conf)
55
- exists = await path.a_exists()
55
+ exists = await path.a_exists() # type: ignore[attr-defined]
56
56
  if not ignore_exist and not exists:
57
57
  raise FileNotFoundError(f"{conf} does not exist")
58
58
  return exists
@@ -131,4 +131,4 @@ class NoConvertingPathMixin(ABC):
131
131
 
132
132
  async def a_loading(self, conf: Any, ignore_nonexist: bool) -> Dict[str, Any]:
133
133
  """Asynchronously load the configuration from a toml file"""
134
- return self.loading(conf, ignore_nonexist)
134
+ return self.loading(conf, ignore_nonexist) # type: ignore[attr-defined]
@@ -19,7 +19,7 @@ class DictLoader(Loader):
19
19
  return conf
20
20
 
21
21
 
22
- class DictsLoader(NoConvertingPathMixin, DictLoader):
22
+ class DictsLoader(NoConvertingPathMixin, DictLoader): # type: ignore[misc]
23
23
  """Dict string loader"""
24
24
 
25
25
  def loading(self, conf: Any, ignore_nonexist: bool) -> Dict[str, Any]:
@@ -44,7 +44,9 @@ class EnvLoader(Loader):
44
44
  if not self._exists(conf, ignore_nonexist):
45
45
  return {}
46
46
 
47
- return dotenv.main.DotEnv(conf).dict()
47
+ conf = self.__class__._convert_path(conf)
48
+ content = conf.read_text() # so that cloud paths work
49
+ return dotenv.dotenv_values(stream=io.StringIO(content))
48
50
 
49
51
  async def a_loading(self, conf, ignore_nonexist):
50
52
  """Asynchronously load the configuration from a .env file"""
@@ -59,7 +61,9 @@ class EnvLoader(Loader):
59
61
  if not await self._a_exists(conf, ignore_nonexist):
60
62
  return {}
61
63
 
62
- return dotenv.main.DotEnv(conf).dict()
64
+ conf = self.__class__._convert_path(conf)
65
+ content = await conf.a_read_text() # so that cloud paths work
66
+ return dotenv.dotenv_values(stream=io.StringIO(content))
63
67
 
64
68
  @classmethod
65
69
  def _convert_with_profiles( # type: ignore[override]
@@ -79,7 +83,7 @@ class EnvLoader(Loader):
79
83
  return cast(out, cls.CASTERS)
80
84
 
81
85
 
82
- class EnvsLoader(NoConvertingPathMixin, EnvLoader):
86
+ class EnvsLoader(NoConvertingPathMixin, EnvLoader): # type: ignore[misc]
83
87
  """Env string loader"""
84
88
 
85
89
  def loading(self, conf: Any, ignore_nonexist: bool = False) -> Dict[str, Any]:
@@ -45,7 +45,10 @@ class IniLoader(Loader):
45
45
  if not self._exists(conf, ignore_nonexist):
46
46
  return {"default": {}}
47
47
 
48
- return iniconfig.IniConfig(conf).sections
48
+ conf = self.__class__._convert_path(conf)
49
+ content = conf.read_text()
50
+
51
+ return iniconfig.IniConfig(conf, content).sections
49
52
 
50
53
  async def a_loading(self, conf: Any, ignore_nonexist: bool) -> Dict[str, Any]:
51
54
  """Asynchronously load the configuration from an ini-like file"""
@@ -60,7 +63,10 @@ class IniLoader(Loader):
60
63
  if not await self._a_exists(conf, ignore_nonexist):
61
64
  return {"default": {}}
62
65
 
63
- return iniconfig.IniConfig(conf).sections
66
+ conf = self.__class__._convert_path(conf)
67
+ content = await conf.a_read_text()
68
+
69
+ return iniconfig.IniConfig(conf, content).sections
64
70
 
65
71
  @classmethod
66
72
  def _convert( # type: ignore[override]
@@ -100,7 +106,7 @@ class IniLoader(Loader):
100
106
  return out
101
107
 
102
108
 
103
- class InisLoader(NoConvertingPathMixin, IniLoader):
109
+ class InisLoader(NoConvertingPathMixin, IniLoader): # type: ignore[misc]
104
110
  """Ini-like string loader"""
105
111
 
106
112
  def loading(self, conf: Any, ignore_nonexist: bool) -> Dict[str, Any]:
@@ -16,8 +16,9 @@ class JsonLoader(Loader):
16
16
  if not self._exists(conf, ignore_nonexist):
17
17
  return {}
18
18
 
19
- with open(conf) as f:
20
- return json.load(f)
19
+ conf = self.__class__._convert_path(conf)
20
+ content = conf.read_text()
21
+ return json.loads(content)
21
22
 
22
23
  async def a_loading(self, conf: Any, ignore_nonexist: bool) -> Dict[str, Any]:
23
24
  """Asynchronously load the configuration from a json file"""
@@ -32,14 +33,12 @@ class JsonLoader(Loader):
32
33
  if not await self._a_exists(conf, ignore_nonexist):
33
34
  return {}
34
35
 
35
- async with self.__class__._convert_path(conf).a_open() as f:
36
- content = await f.read()
37
- if isinstance(content, bytes): # pragma: no cover
38
- content = content.decode()
39
- return json.loads(content)
36
+ conf = self.__class__._convert_path(conf)
37
+ content = await conf.a_read_text()
38
+ return json.loads(content)
40
39
 
41
40
 
42
- class JsonsLoader(NoConvertingPathMixin, JsonLoader):
41
+ class JsonsLoader(NoConvertingPathMixin, JsonLoader): # type: ignore[misc]
43
42
  """Json string loader"""
44
43
 
45
44
  def loading(self, conf: Any, ignore_nonexist: bool) -> Dict[str, Any]:
@@ -18,7 +18,7 @@ from ..caster import (
18
18
  )
19
19
 
20
20
 
21
- class OsenvLoader(NoConvertingPathMixin, Loader):
21
+ class OsenvLoader(NoConvertingPathMixin, Loader): # type: ignore[misc]
22
22
  """Environment variable loader"""
23
23
 
24
24
  CASTERS = [
@@ -27,12 +27,13 @@ class TomlLoader(Loader):
27
27
  if not self._exists(conf, ignore_nonexist):
28
28
  return {}
29
29
 
30
- if toml.__name__ in ("tomli", "tomllib"): # pragma: no cover
31
- with open(conf, "rb") as f:
32
- return toml.load(f)
33
-
34
- with open(conf, "r") as f: # rtoml
35
- return toml.load(f)
30
+ conf = self.__class__._convert_path(conf)
31
+ content = conf.read_bytes()
32
+ try:
33
+ return toml.loads(content)
34
+ except TypeError:
35
+ content = content.decode()
36
+ return toml.loads(content)
36
37
 
37
38
  async def a_loading(self, conf: Any, ignore_nonexist: bool) -> Dict[str, Any]:
38
39
  """Asynchronously load the configuration from a toml file"""
@@ -47,16 +48,16 @@ class TomlLoader(Loader):
47
48
  if not await self._a_exists(conf, ignore_nonexist):
48
49
  return {}
49
50
 
50
- async with self.__class__._convert_path(conf).a_open("rb") as f:
51
- content = await f.read()
52
- try:
53
- return toml.loads(content)
54
- except TypeError:
55
- content = content.decode()
56
- return toml.loads(content)
51
+ conf = self.__class__._convert_path(conf)
52
+ content = await conf.a_read_bytes()
53
+ try:
54
+ return toml.loads(content)
55
+ except TypeError:
56
+ content = content.decode()
57
+ return toml.loads(content)
57
58
 
58
59
 
59
- class TomlsLoader(NoConvertingPathMixin, TomlLoader):
60
+ class TomlsLoader(NoConvertingPathMixin, TomlLoader): # type: ignore[misc]
60
61
  """Toml string loader"""
61
62
 
62
63
  def loading(self, conf: Any, ignore_nonexist: bool) -> Dict[str, Any]:
@@ -18,8 +18,9 @@ class YamlLoader(Loader):
18
18
  if not self._exists(conf, ignore_nonexist):
19
19
  return {}
20
20
 
21
- with open(conf) as f:
22
- return yaml.load(f, Loader=yaml.FullLoader)
21
+ conf = self.__class__._convert_path(conf)
22
+ content = conf.read_text()
23
+ return yaml.load(content, Loader=yaml.FullLoader)
23
24
 
24
25
  async def a_loading(self, conf: Any, ignore_nonexist: bool) -> Dict[str, Any]:
25
26
  """Asynchronously load the configuration from a yaml file"""
@@ -34,14 +35,12 @@ class YamlLoader(Loader):
34
35
  if not await self._a_exists(conf, ignore_nonexist):
35
36
  return {}
36
37
 
37
- async with self.__class__._convert_path(conf).a_open() as f:
38
- content = await f.read()
39
- if isinstance(content, bytes): # pragma: no cover
40
- content = content.decode()
41
- return yaml.load(content, Loader=yaml.FullLoader)
38
+ conf = self.__class__._convert_path(conf)
39
+ content = await conf.a_read_text()
40
+ return yaml.load(content, Loader=yaml.FullLoader)
42
41
 
43
42
 
44
- class YamlsLoader(NoConvertingPathMixin, YamlLoader):
43
+ class YamlsLoader(NoConvertingPathMixin, YamlLoader): # type: ignore[misc]
45
44
  """Yaml string loader"""
46
45
 
47
46
  def loading(self, conf: Any, ignore_nonexist: bool) -> Dict[str, Any]: