archae 2026.1.0b2__tar.gz → 2026.2.0__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.
- {archae-2026.1.0b2 → archae-2026.2.0}/PKG-INFO +26 -27
- {archae-2026.1.0b2 → archae-2026.2.0}/README.md +20 -24
- {archae-2026.1.0b2 → archae-2026.2.0}/pyproject.toml +6 -3
- archae-2026.2.0/src/archae/__init__.py +5 -0
- archae-2026.2.0/src/archae/cli.py +176 -0
- archae-2026.2.0/src/archae/config.py +107 -0
- archae-2026.2.0/src/archae/default_settings.toml +9 -0
- archae-2026.2.0/src/archae/extractor.py +249 -0
- archae-2026.2.0/src/archae/options.yaml +39 -0
- {archae-2026.1.0b2 → archae-2026.2.0}/src/archae/util/archiver/base_archiver.py +2 -2
- archae-2026.2.0/src/archae/util/converter/file_size.py +77 -0
- archae-2026.2.0/src/archae/util/file_tracker.py +93 -0
- archae-2026.2.0/src/archae/util/tool_manager.py +112 -0
- archae-2026.1.0b2/src/archae/__init__.py +0 -1
- archae-2026.1.0b2/src/archae/cli.py +0 -381
- {archae-2026.1.0b2 → archae-2026.2.0}/LICENSE +0 -0
- {archae-2026.1.0b2 → archae-2026.2.0}/src/archae/__main__.py +0 -0
- {archae-2026.1.0b2 → archae-2026.2.0}/src/archae/py.typed +0 -0
- {archae-2026.1.0b2 → archae-2026.2.0}/src/archae/util/__init__.py +0 -0
- {archae-2026.1.0b2 → archae-2026.2.0}/src/archae/util/archiver/__init__.py +0 -0
- {archae-2026.1.0b2 → archae-2026.2.0}/src/archae/util/archiver/peazip.py +0 -0
- {archae-2026.1.0b2 → archae-2026.2.0}/src/archae/util/archiver/seven_zip.py +0 -0
- {archae-2026.1.0b2 → archae-2026.2.0}/src/archae/util/archiver/unar.py +0 -0
- {archae-2026.1.0b2 → archae-2026.2.0}/src/archae/util/enum/__init__.py +0 -0
- {archae-2026.1.0b2 → archae-2026.2.0}/src/archae/util/enum/byte_scale.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: archae
|
|
3
|
-
Version: 2026.
|
|
3
|
+
Version: 2026.2.0
|
|
4
4
|
Summary: Archae explodes archives.
|
|
5
5
|
Keywords:
|
|
6
6
|
Author: Shawn McNaughton
|
|
@@ -32,16 +32,19 @@ Classifier: Intended Audience :: Developers
|
|
|
32
32
|
Classifier: License :: OSI Approved :: MIT License
|
|
33
33
|
Classifier: Programming Language :: Python
|
|
34
34
|
Classifier: Programming Language :: Python :: 3
|
|
35
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
36
35
|
Classifier: Programming Language :: Python :: 3.12
|
|
37
36
|
Classifier: Programming Language :: Python :: 3.13
|
|
38
37
|
Classifier: Programming Language :: Python :: 3.14
|
|
39
38
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
40
39
|
Classifier: Typing :: Typed
|
|
41
40
|
Requires-Dist: click
|
|
41
|
+
Requires-Dist: dynaconf>=3.2.12
|
|
42
|
+
Requires-Dist: platformdirs>=4.5.1
|
|
42
43
|
Requires-Dist: python-magic
|
|
44
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
43
45
|
Requires-Dist: rich-click
|
|
44
|
-
Requires-
|
|
46
|
+
Requires-Dist: types-pyyaml>=6
|
|
47
|
+
Requires-Python: >=3.12
|
|
45
48
|
Project-URL: Documentation, https://archae.readthedocs.io/en/stable/
|
|
46
49
|
Project-URL: Changelog, https://archae.readthedocs.io/en/stable/changelog.html
|
|
47
50
|
Project-URL: Source Code, https://github.com/shawngmc/archae
|
|
@@ -80,9 +83,11 @@ Every once and a while, I run into an issue: multiple layers of archives. The re
|
|
|
80
83
|
- Identifies file types via libmagic
|
|
81
84
|
- Detects duplicate archives
|
|
82
85
|
- Basic archive bomb protections
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
-
|
|
86
|
+
- MAX_ARCHIVE_SIZE_BYTES - ensures the uncompressed size of an archive is limited
|
|
87
|
+
- MAX_TOTAL_SIZE_BYTES - ensures the total extracted footprint isn't above a certain size
|
|
88
|
+
- MIN_ARCHIVE_RATIO - ensures very-high-compression-ratio archives are stopped
|
|
89
|
+
- MIN_DISK_FREE_SPACE - minimum free space at the extraction location
|
|
90
|
+
- MAX_DEPTH - allow setting a maximum archive depth to traverse
|
|
86
91
|
|
|
87
92
|
## Installation
|
|
88
93
|
|
|
@@ -102,6 +107,13 @@ Check out the [Archae documentation](https://archae.readthedocs.io/en/stable/) f
|
|
|
102
107
|
|
|
103
108
|
## Usage
|
|
104
109
|
|
|
110
|
+
Configuration values are supplied one of four ways, and any item lower in this list will overwrite a prior one:
|
|
111
|
+
|
|
112
|
+
- Default values are stored in the app
|
|
113
|
+
- A TOML file at ~/.config/archae/ will be created on first run and can override those values (ex. MIN_ARCHIVE_RATIO = 0.005)
|
|
114
|
+
- Env vars starts starting with "ARCHAE\_" are parsed (ex. ARCHAE_MIN_ARCHIVE_RATIO=0.005)
|
|
115
|
+
- Values can be passed in as flags (ex. --min_archive_ratio=0.005)
|
|
116
|
+
|
|
105
117
|
<!-- start docs-include-usage -->
|
|
106
118
|
|
|
107
119
|
Running `archae --help` or `python -m archae --help` shows a list of all of the available options and arguments:
|
|
@@ -119,28 +131,18 @@ cog.outl(f"\n```sh\narchae --help\n{help.rstrip()}\n```\n")
|
|
|
119
131
|
```sh
|
|
120
132
|
archae --help
|
|
121
133
|
|
|
122
|
-
Usage: archae [OPTIONS]
|
|
134
|
+
Usage: archae [OPTIONS] COMMAND [ARGS]...
|
|
123
135
|
|
|
124
136
|
Archae explodes archives.
|
|
125
137
|
|
|
126
|
-
╭─ Arguments ──────────────────────────────────────────────────────────────────────────╮
|
|
127
|
-
│ * ARCHIVE_PATH FILE Archive to examine [required] │
|
|
128
|
-
╰──────────────────────────────────────────────────────────────────────────────────────╯
|
|
129
138
|
╭─ Options ────────────────────────────────────────────────────────────────────────────╮
|
|
130
|
-
│ --
|
|
131
|
-
│
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
│
|
|
135
|
-
│
|
|
136
|
-
│
|
|
137
|
-
│ --min_archive_ratio FLOAT RANGE [0<=x<=1] Minimum allowed compression │
|
|
138
|
-
│ ratio for an archive. A │
|
|
139
|
-
│ floating-point value between │
|
|
140
|
-
│ 0.0 and 1.0, inclusive. Default │
|
|
141
|
-
│ is 0.005 [default: 0.005] │
|
|
142
|
-
│ --version -v Show the version and exit. │
|
|
143
|
-
│ --help -h Show this message and exit. │
|
|
139
|
+
│ --version -v Show the version and exit. │
|
|
140
|
+
│ --help -h Show this message and exit. │
|
|
141
|
+
╰──────────────────────────────────────────────────────────────────────────────────────╯
|
|
142
|
+
╭─ Commands ───────────────────────────────────────────────────────────────────────────╮
|
|
143
|
+
│ extract Extract and analyze an archive. │
|
|
144
|
+
│ listopts List all available configuration options. │
|
|
145
|
+
│ status Show archae status and available tools. │
|
|
144
146
|
╰──────────────────────────────────────────────────────────────────────────────────────╯
|
|
145
147
|
```
|
|
146
148
|
|
|
@@ -151,10 +153,7 @@ archae --help
|
|
|
151
153
|
## TODOs
|
|
152
154
|
|
|
153
155
|
- More archive bomb protections
|
|
154
|
-
- min_total_size_bytes - (NYI) ensures the total extracted footprint isn't above a certain size
|
|
155
|
-
- min_free_space - minimum free space at the extraction location
|
|
156
156
|
- delete_archives_as_exploded - remove archive files to reduce duplication (boolean)
|
|
157
|
-
- max_archive_depth - allow setting a maximum archive depth
|
|
158
157
|
- Improve archive type detection
|
|
159
158
|
- Separate between extractable and non-extractable archive types
|
|
160
159
|
- Detect password-protected archives
|
|
@@ -30,9 +30,11 @@ Every once and a while, I run into an issue: multiple layers of archives. The re
|
|
|
30
30
|
- Identifies file types via libmagic
|
|
31
31
|
- Detects duplicate archives
|
|
32
32
|
- Basic archive bomb protections
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
33
|
+
- MAX_ARCHIVE_SIZE_BYTES - ensures the uncompressed size of an archive is limited
|
|
34
|
+
- MAX_TOTAL_SIZE_BYTES - ensures the total extracted footprint isn't above a certain size
|
|
35
|
+
- MIN_ARCHIVE_RATIO - ensures very-high-compression-ratio archives are stopped
|
|
36
|
+
- MIN_DISK_FREE_SPACE - minimum free space at the extraction location
|
|
37
|
+
- MAX_DEPTH - allow setting a maximum archive depth to traverse
|
|
36
38
|
|
|
37
39
|
## Installation
|
|
38
40
|
|
|
@@ -52,6 +54,13 @@ Check out the [Archae documentation](https://archae.readthedocs.io/en/stable/) f
|
|
|
52
54
|
|
|
53
55
|
## Usage
|
|
54
56
|
|
|
57
|
+
Configuration values are supplied one of four ways, and any item lower in this list will overwrite a prior one:
|
|
58
|
+
|
|
59
|
+
- Default values are stored in the app
|
|
60
|
+
- A TOML file at ~/.config/archae/ will be created on first run and can override those values (ex. MIN_ARCHIVE_RATIO = 0.005)
|
|
61
|
+
- Env vars starts starting with "ARCHAE\_" are parsed (ex. ARCHAE_MIN_ARCHIVE_RATIO=0.005)
|
|
62
|
+
- Values can be passed in as flags (ex. --min_archive_ratio=0.005)
|
|
63
|
+
|
|
55
64
|
<!-- start docs-include-usage -->
|
|
56
65
|
|
|
57
66
|
Running `archae --help` or `python -m archae --help` shows a list of all of the available options and arguments:
|
|
@@ -69,28 +78,18 @@ cog.outl(f"\n```sh\narchae --help\n{help.rstrip()}\n```\n")
|
|
|
69
78
|
```sh
|
|
70
79
|
archae --help
|
|
71
80
|
|
|
72
|
-
Usage: archae [OPTIONS]
|
|
81
|
+
Usage: archae [OPTIONS] COMMAND [ARGS]...
|
|
73
82
|
|
|
74
83
|
Archae explodes archives.
|
|
75
84
|
|
|
76
|
-
╭─ Arguments ──────────────────────────────────────────────────────────────────────────╮
|
|
77
|
-
│ * ARCHIVE_PATH FILE Archive to examine [required] │
|
|
78
|
-
╰──────────────────────────────────────────────────────────────────────────────────────╯
|
|
79
85
|
╭─ Options ────────────────────────────────────────────────────────────────────────────╮
|
|
80
|
-
│ --
|
|
81
|
-
│
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
│
|
|
85
|
-
│
|
|
86
|
-
│
|
|
87
|
-
│ --min_archive_ratio FLOAT RANGE [0<=x<=1] Minimum allowed compression │
|
|
88
|
-
│ ratio for an archive. A │
|
|
89
|
-
│ floating-point value between │
|
|
90
|
-
│ 0.0 and 1.0, inclusive. Default │
|
|
91
|
-
│ is 0.005 [default: 0.005] │
|
|
92
|
-
│ --version -v Show the version and exit. │
|
|
93
|
-
│ --help -h Show this message and exit. │
|
|
86
|
+
│ --version -v Show the version and exit. │
|
|
87
|
+
│ --help -h Show this message and exit. │
|
|
88
|
+
╰──────────────────────────────────────────────────────────────────────────────────────╯
|
|
89
|
+
╭─ Commands ───────────────────────────────────────────────────────────────────────────╮
|
|
90
|
+
│ extract Extract and analyze an archive. │
|
|
91
|
+
│ listopts List all available configuration options. │
|
|
92
|
+
│ status Show archae status and available tools. │
|
|
94
93
|
╰──────────────────────────────────────────────────────────────────────────────────────╯
|
|
95
94
|
```
|
|
96
95
|
|
|
@@ -101,10 +100,7 @@ archae --help
|
|
|
101
100
|
## TODOs
|
|
102
101
|
|
|
103
102
|
- More archive bomb protections
|
|
104
|
-
- min_total_size_bytes - (NYI) ensures the total extracted footprint isn't above a certain size
|
|
105
|
-
- min_free_space - minimum free space at the extraction location
|
|
106
103
|
- delete_archives_as_exploded - remove archive files to reduce duplication (boolean)
|
|
107
|
-
- max_archive_depth - allow setting a maximum archive depth
|
|
108
104
|
- Improve archive type detection
|
|
109
105
|
- Separate between extractable and non-extractable archive types
|
|
110
106
|
- Detect password-protected archives
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "archae"
|
|
7
|
-
version = "2026.
|
|
7
|
+
version = "2026.2.0"
|
|
8
8
|
description = "Archae explodes archives."
|
|
9
9
|
authors = [{name = "Shawn McNaughton", email = "shawngmc@gmail.com"}]
|
|
10
10
|
readme = "README.md"
|
|
@@ -17,18 +17,21 @@ classifiers = [
|
|
|
17
17
|
"License :: OSI Approved :: MIT License",
|
|
18
18
|
"Programming Language :: Python",
|
|
19
19
|
"Programming Language :: Python :: 3",
|
|
20
|
-
"Programming Language :: Python :: 3.11",
|
|
21
20
|
"Programming Language :: Python :: 3.12",
|
|
22
21
|
"Programming Language :: Python :: 3.13",
|
|
23
22
|
"Programming Language :: Python :: 3.14",
|
|
24
23
|
"Programming Language :: Python :: 3 :: Only",
|
|
25
24
|
"Typing :: Typed",
|
|
26
25
|
]
|
|
27
|
-
requires-python = "
|
|
26
|
+
requires-python = ">=3.12"
|
|
28
27
|
dependencies = [
|
|
29
28
|
"click",
|
|
29
|
+
"dynaconf>=3.2.12",
|
|
30
|
+
"platformdirs>=4.5.1",
|
|
30
31
|
"python-magic",
|
|
32
|
+
"PyYAML>=6.0.3",
|
|
31
33
|
"rich_click",
|
|
34
|
+
"types-PyYAML>=6",
|
|
32
35
|
]
|
|
33
36
|
|
|
34
37
|
[dependency-groups]
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""Main CLI for archae."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
import pathlib
|
|
7
|
+
from importlib import metadata
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import rich_click as click
|
|
11
|
+
|
|
12
|
+
from archae.config import apply_options, convert_settings, get_options
|
|
13
|
+
from archae.extractor import ArchiveExtractor
|
|
14
|
+
from archae.util.tool_manager import ToolManager
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger("archae")
|
|
17
|
+
logger.setLevel(logging.INFO)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@click.group(
|
|
21
|
+
context_settings={"help_option_names": ["-h", "--help"], "show_default": True}
|
|
22
|
+
)
|
|
23
|
+
@click.rich_config(
|
|
24
|
+
help_config=click.RichHelpConfiguration(
|
|
25
|
+
width=88,
|
|
26
|
+
show_arguments=True,
|
|
27
|
+
text_markup=True,
|
|
28
|
+
),
|
|
29
|
+
)
|
|
30
|
+
@click.version_option(metadata.version("archae"), "-v", "--version")
|
|
31
|
+
def cli() -> None:
|
|
32
|
+
"""Archae explodes archives."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@cli.command()
|
|
36
|
+
@click.argument(
|
|
37
|
+
"archive_path",
|
|
38
|
+
type=click.Path(exists=True, dir_okay=False, readable=True, path_type=pathlib.Path),
|
|
39
|
+
default=Path.cwd() / "extracted",
|
|
40
|
+
help="Archive to examine",
|
|
41
|
+
)
|
|
42
|
+
@click.option(
|
|
43
|
+
"-o",
|
|
44
|
+
"--opt",
|
|
45
|
+
"options",
|
|
46
|
+
nargs=2,
|
|
47
|
+
type=click.Tuple([str, str]),
|
|
48
|
+
multiple=True,
|
|
49
|
+
help="Set config options as key value pairs. Use 'archae listopts' to see available options.",
|
|
50
|
+
)
|
|
51
|
+
@click.option(
|
|
52
|
+
"-e",
|
|
53
|
+
"--extract-dir",
|
|
54
|
+
"extract_dir",
|
|
55
|
+
nargs=1,
|
|
56
|
+
type=click.Path(
|
|
57
|
+
dir_okay=True,
|
|
58
|
+
file_okay=False,
|
|
59
|
+
readable=True,
|
|
60
|
+
writable=True,
|
|
61
|
+
path_type=pathlib.Path,
|
|
62
|
+
),
|
|
63
|
+
default=Path.cwd() / "extracted",
|
|
64
|
+
help="Set config options as key value pairs. Use 'archae listopts' to see available options.",
|
|
65
|
+
)
|
|
66
|
+
def extract(
|
|
67
|
+
archive_path: pathlib.Path,
|
|
68
|
+
options: list[tuple[str, str]] | None,
|
|
69
|
+
extract_dir: pathlib.Path,
|
|
70
|
+
) -> None:
|
|
71
|
+
"""Extract and analyze an archive."""
|
|
72
|
+
# Apply any options from the command line, then convert any convertible settings
|
|
73
|
+
if options:
|
|
74
|
+
apply_options(options)
|
|
75
|
+
convert_settings()
|
|
76
|
+
|
|
77
|
+
# Locate external tools
|
|
78
|
+
ToolManager.locate_tools()
|
|
79
|
+
extractor = ArchiveExtractor(extract_dir=extract_dir)
|
|
80
|
+
extractor.handle_file(archive_path)
|
|
81
|
+
print_tracked_files(extractor.get_tracked_files())
|
|
82
|
+
print_warnings(extractor.get_warnings())
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@cli.command()
|
|
86
|
+
def listopts() -> None:
|
|
87
|
+
"""List all available configuration options."""
|
|
88
|
+
options = get_options()
|
|
89
|
+
|
|
90
|
+
# Load default settings
|
|
91
|
+
defaults_path = Path(__file__).parent / "default_settings.toml"
|
|
92
|
+
defaults_content = defaults_path.read_text()
|
|
93
|
+
defaults = {}
|
|
94
|
+
in_default_section = False
|
|
95
|
+
for line in defaults_content.split("\n"):
|
|
96
|
+
if line.strip() == "[default]":
|
|
97
|
+
in_default_section = True
|
|
98
|
+
continue
|
|
99
|
+
if in_default_section and line.startswith("["):
|
|
100
|
+
break
|
|
101
|
+
if in_default_section and "=" in line:
|
|
102
|
+
key, value = line.split("=", 1)
|
|
103
|
+
defaults[key.strip()] = value.strip().strip('"')
|
|
104
|
+
|
|
105
|
+
logger.info("Available configuration options:")
|
|
106
|
+
logger.info("------------------------------------------------")
|
|
107
|
+
for option_name, option_def in sorted(options.items()):
|
|
108
|
+
logger.info("%s (%s)", option_name, option_def.get("type", "unknown"))
|
|
109
|
+
logger.info(" %s", option_def.get("help", "No description available"))
|
|
110
|
+
if option_name in defaults:
|
|
111
|
+
logger.info(" Default: %s", defaults[option_name])
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@cli.command()
|
|
115
|
+
def status() -> None:
|
|
116
|
+
"""Show archae status and available tools."""
|
|
117
|
+
logger.info("Archae status:")
|
|
118
|
+
logger.info("Version: %s", metadata.version("archae"))
|
|
119
|
+
ToolManager.locate_tools()
|
|
120
|
+
logger.info("Tools located and ready to use.")
|
|
121
|
+
logger.info("------------------------------------------------")
|
|
122
|
+
|
|
123
|
+
# Show supported extensions
|
|
124
|
+
supported_ext = ToolManager.get_supported_extensions()
|
|
125
|
+
logger.info("Supported file extensions (%d):", len(supported_ext))
|
|
126
|
+
if supported_ext:
|
|
127
|
+
logger.info(" %s", ", ".join(supported_ext))
|
|
128
|
+
else:
|
|
129
|
+
logger.info(" (none)")
|
|
130
|
+
|
|
131
|
+
# Show unsupported extensions
|
|
132
|
+
unsupported_ext = ToolManager.get_unsupported_extensions()
|
|
133
|
+
logger.info("Unsupported file extensions (%d):", len(unsupported_ext))
|
|
134
|
+
if unsupported_ext:
|
|
135
|
+
logger.info(" %s", ", ".join(unsupported_ext))
|
|
136
|
+
else:
|
|
137
|
+
logger.info(" (none)")
|
|
138
|
+
|
|
139
|
+
logger.info("------------------------------------------------")
|
|
140
|
+
|
|
141
|
+
# Show supported MIME types
|
|
142
|
+
supported_mime = ToolManager.get_supported_mime_types()
|
|
143
|
+
logger.info("Supported MIME types (%d):", len(supported_mime))
|
|
144
|
+
if supported_mime:
|
|
145
|
+
logger.info(" %s", ", ".join(supported_mime))
|
|
146
|
+
else:
|
|
147
|
+
logger.info(" (none)")
|
|
148
|
+
|
|
149
|
+
# Show unsupported MIME types
|
|
150
|
+
unsupported_mime = ToolManager.get_unsupported_mime_types()
|
|
151
|
+
logger.info("Unsupported MIME types (%d):", len(unsupported_mime))
|
|
152
|
+
if unsupported_mime:
|
|
153
|
+
logger.info(" %s", ", ".join(unsupported_mime))
|
|
154
|
+
else:
|
|
155
|
+
logger.info(" (none)")
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def print_tracked_files(tracked_files: dict[str, dict]) -> None:
|
|
159
|
+
"""Print the tracked files for debugging purposes."""
|
|
160
|
+
logger.info("------------------------------------------------")
|
|
161
|
+
for hash, info in tracked_files.items():
|
|
162
|
+
logger.info("Hash: %s", hash)
|
|
163
|
+
logger.info(" Size: %s bytes", info.get("size", "Unknown"))
|
|
164
|
+
for path in info.get("paths", []):
|
|
165
|
+
logger.info(" Path: %s", path)
|
|
166
|
+
logger.info(" Metadata:")
|
|
167
|
+
for key, value in info.get("metadata", {}).items():
|
|
168
|
+
logger.info(" %s: %s", key, value)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def print_warnings(warnings: list[str]) -> None:
|
|
172
|
+
"""Print accumulated warnings for debugging purposes."""
|
|
173
|
+
logger.info("------------------------------------------------")
|
|
174
|
+
logger.info("Accumulated Warnings:")
|
|
175
|
+
for warning in warnings: # type: ignore[attr-defined]
|
|
176
|
+
logger.info(warning)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Runtime config management (default, userconfig and envvars)."""
|
|
2
|
+
|
|
3
|
+
import importlib
|
|
4
|
+
import typing
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import platformdirs
|
|
8
|
+
import yaml
|
|
9
|
+
from dynaconf import Dynaconf
|
|
10
|
+
|
|
11
|
+
# Get the package directory for default settings
|
|
12
|
+
package_dir = Path(__file__).parent
|
|
13
|
+
default_settings_file = package_dir / "default_settings.toml"
|
|
14
|
+
|
|
15
|
+
# Get the config directory following XDG standards
|
|
16
|
+
config_dir = Path(platformdirs.user_config_dir("archae"))
|
|
17
|
+
config_dir.mkdir(parents=True, exist_ok=True)
|
|
18
|
+
|
|
19
|
+
# Define the user config file path
|
|
20
|
+
user_config_file = config_dir / "settings.toml"
|
|
21
|
+
|
|
22
|
+
# Create a default settings.toml if it doesn't exist
|
|
23
|
+
if not user_config_file.exists():
|
|
24
|
+
user_config_file.write_text("""# Archae configuration
|
|
25
|
+
# Override defaults from the package here
|
|
26
|
+
""")
|
|
27
|
+
|
|
28
|
+
settings = Dynaconf(
|
|
29
|
+
envvar_prefix="ARCHAE",
|
|
30
|
+
settings_files=[
|
|
31
|
+
str(default_settings_file), # Load package defaults first
|
|
32
|
+
str(user_config_file), # User settings override defaults
|
|
33
|
+
],
|
|
34
|
+
environments=True,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
default_settings = Dynaconf(
|
|
38
|
+
envvar_prefix="ARCHAE",
|
|
39
|
+
settings_files=[
|
|
40
|
+
str(default_settings_file), # Load package defaults first
|
|
41
|
+
],
|
|
42
|
+
environments=True,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
options_file = package_dir / "options.yaml"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def get_options() -> dict:
|
|
50
|
+
"""Return the contents of options.yaml."""
|
|
51
|
+
with Path.open(options_file) as f:
|
|
52
|
+
return yaml.safe_load(f)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def get_converter(converter_def: str) -> typing.Callable:
|
|
56
|
+
"""Dynamically import and instantiate a converter class.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
converter_def (str): Converter definition in format "module.path:ClassName" or a builtin type like "float" or "int".
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
Converter function.
|
|
63
|
+
"""
|
|
64
|
+
# Handle built-in types
|
|
65
|
+
if converter_def == "float":
|
|
66
|
+
return float
|
|
67
|
+
if converter_def == "int":
|
|
68
|
+
return int
|
|
69
|
+
|
|
70
|
+
# Split the definition into module path and class name
|
|
71
|
+
module_name, class_name = converter_def.split(":")
|
|
72
|
+
|
|
73
|
+
# Import the module
|
|
74
|
+
module = importlib.import_module(module_name)
|
|
75
|
+
|
|
76
|
+
# Get the class from the module
|
|
77
|
+
return getattr(module, class_name)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def apply_options(option_list: list[tuple[str, str]]) -> None:
|
|
81
|
+
"""Apply a list of options to the settings.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
option_list (list[tuple[str, str]]): List of key-value pairs to apply.
|
|
85
|
+
|
|
86
|
+
"""
|
|
87
|
+
options = get_options()
|
|
88
|
+
for key, value in option_list:
|
|
89
|
+
# Find the option definition by matching the key
|
|
90
|
+
option_def = None
|
|
91
|
+
for def_key in options:
|
|
92
|
+
option_def = options[def_key]
|
|
93
|
+
break
|
|
94
|
+
if option_def:
|
|
95
|
+
settings[key] = value
|
|
96
|
+
else:
|
|
97
|
+
pass
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def convert_settings() -> None:
|
|
101
|
+
"""Convert settings using their defined converters."""
|
|
102
|
+
options = get_options()
|
|
103
|
+
for key in options:
|
|
104
|
+
option_def = options[key]
|
|
105
|
+
if "converter" in option_def:
|
|
106
|
+
converter = get_converter(option_def["converter"])
|
|
107
|
+
settings[key] = converter(settings[key])
|