hungerlib 4.1__tar.gz → 4.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 (30) hide show
  1. {hungerlib-4.1/src/hungerlib.egg-info → hungerlib-4.2}/PKG-INFO +1 -1
  2. {hungerlib-4.1 → hungerlib-4.2}/pyproject.toml +1 -1
  3. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/configloader.py +28 -9
  4. {hungerlib-4.1 → hungerlib-4.2/src/hungerlib.egg-info}/PKG-INFO +1 -1
  5. {hungerlib-4.1 → hungerlib-4.2}/LICENSE +0 -0
  6. {hungerlib-4.1 → hungerlib-4.2}/README.md +0 -0
  7. {hungerlib-4.1 → hungerlib-4.2}/setup.cfg +0 -0
  8. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/__init__.py +0 -0
  9. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/api/__init__.py +0 -0
  10. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/api/backups.py +0 -0
  11. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/api/command.py +0 -0
  12. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/api/databases.py +0 -0
  13. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/api/filemanager.py +0 -0
  14. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/api/schedule.py +0 -0
  15. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/api/startup.py +0 -0
  16. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/bridgeclient.py +0 -0
  17. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/datamap.py +0 -0
  18. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/messagerouter.py +0 -0
  19. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/panel.py +0 -0
  20. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/servers/__init__.py +0 -0
  21. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/servers/generic.py +0 -0
  22. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/servers/minecraft.py +0 -0
  23. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/utils/__init__.py +0 -0
  24. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/utils/colormaps.py +0 -0
  25. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/utils/time.py +0 -0
  26. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib/utils/utils.py +0 -0
  27. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib.egg-info/SOURCES.txt +0 -0
  28. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib.egg-info/dependency_links.txt +0 -0
  29. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib.egg-info/requires.txt +0 -0
  30. {hungerlib-4.1 → hungerlib-4.2}/src/hungerlib.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hungerlib
3
- Version: 4.1
3
+ Version: 4.2
4
4
  Summary: Powerful automation library for Pterodactyl.
5
5
  Author: iFamished
6
6
  License: MIT
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "hungerlib"
10
- version = "4.1"
10
+ version = "4.2"
11
11
  description = "Powerful automation library for Pterodactyl."
12
12
  readme = "README.md"
13
13
  requires-python = ">=3.9"
@@ -6,14 +6,14 @@ from dataclasses import fields, MISSING
6
6
 
7
7
  # yaml helpers
8
8
  def load_yaml(path: str) -> dict:
9
- '''Loads a YAML file and always returns a dict.'''
9
+ """Loads a YAML file and always returns a dict."""
10
10
  with open(path, "r") as f:
11
11
  data = yaml.safe_load(f)
12
12
  return data if isinstance(data, dict) else {}
13
13
 
14
14
 
15
15
  def deep_get(data: dict, path: str):
16
- '''Resolve dotted YAML paths like 'server.port\''''
16
+ """Resolve dotted YAML paths like 'server.port'."""
17
17
  cur = data
18
18
  for part in path.split("."):
19
19
  if not isinstance(cur, dict):
@@ -25,7 +25,7 @@ def deep_get(data: dict, path: str):
25
25
 
26
26
 
27
27
  def convert_value(value, annotation):
28
- '''Convert YAML values to the dataclass field type.'''
28
+ """Convert YAML values to the dataclass field type."""
29
29
  try:
30
30
  if annotation is int:
31
31
  return int(value)
@@ -40,11 +40,13 @@ def convert_value(value, annotation):
40
40
 
41
41
  # main loader
42
42
  def loadConfig(schema, runtime_path: str | None = None):
43
- '''
43
+ """
44
44
  Loads a config dataclass using:
45
- - schema.__config_path__ for default file
45
+ - schema.__user_config_path__ for runtime file
46
+ - schema.__default_config_path__ for packaged default
46
47
  - dataclass defaults as YAML key paths (mode="config")
47
- '''
48
+ - tuple defaults: (yaml_path, fallback)
49
+ """
48
50
 
49
51
  # 1. Resolve runtime path
50
52
  if runtime_path is None:
@@ -60,7 +62,7 @@ def loadConfig(schema, runtime_path: str | None = None):
60
62
  if default_rel:
61
63
  module = importlib.import_module(schema.__module__)
62
64
  schema_file = os.path.abspath(module.__file__)
63
- package_dir = os.path.dirname(schema_file)
65
+ package_dir = os.path.dirname(os.path.dirname(schema_file))
64
66
  abs_default = os.path.join(package_dir, default_rel.lstrip("/"))
65
67
 
66
68
  # 3. Ensure runtime config exists
@@ -69,8 +71,8 @@ def loadConfig(schema, runtime_path: str | None = None):
69
71
  with open(abs_default, "r") as src, open(abs_runtime, "w") as dst:
70
72
  dst.write(src.read())
71
73
  else:
72
- with open(abs_runtime, "w") as f:
73
- f.write("# No default config found.\n")
74
+ # Create empty file — no placeholder
75
+ open(abs_runtime, "a").close()
74
76
 
75
77
  # 4. Load YAML
76
78
  raw = load_yaml(abs_runtime)
@@ -85,6 +87,23 @@ def loadConfig(schema, runtime_path: str | None = None):
85
87
 
86
88
  default = f.default
87
89
 
90
+ # tuple default: (yaml_path, fallback)
91
+ if isinstance(default, tuple) and len(default) == 2:
92
+ yaml_path, fallback = default
93
+ value = deep_get(raw, yaml_path)
94
+
95
+ resolved = convert_value(value if value is not None else fallback, f.type)
96
+
97
+ # wrap resolved value so we can attach .fallback
98
+ class _V(str):
99
+ pass
100
+
101
+ wrapped = _V(resolved)
102
+ wrapped.fallback = fallback
103
+
104
+ values[f.name] = wrapped
105
+ continue
106
+
88
107
  # mode="config": default string = YAML path
89
108
  if mode == "config" and isinstance(default, str):
90
109
  yaml_path = default
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hungerlib
3
- Version: 4.1
3
+ Version: 4.2
4
4
  Summary: Powerful automation library for Pterodactyl.
5
5
  Author: iFamished
6
6
  License: MIT
File without changes
File without changes
File without changes
File without changes