sleepyconvert 2.2.0__tar.gz → 2.3.1__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.
- sleepyconvert-2.3.1/PKG-INFO +146 -0
- sleepyconvert-2.3.1/README.md +101 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/pyproject.toml +22 -3
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/core/config.py +2 -2
- sleepyconvert-2.3.1/sleepyconvert/core/sleepy_params.py +110 -0
- sleepyconvert-2.2.0/PKG-INFO +0 -770
- sleepyconvert-2.2.0/README.md +0 -62
- sleepyconvert-2.2.0/sleepyconvert/core/sleepy_params.py +0 -102
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/LICENSE +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/__init__.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/cli/__init__.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/cli/command_logic.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/core/__init__.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/core/logging.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/main.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/__init__.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/csv_json.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/csv_parquet.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/csv_pkl.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/csv_xlsx.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/data_shared.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/doc_shared.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/html_md.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/html_pdf.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/image_shared.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/json_parquet.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/json_pkl.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/json_xlsx.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/md_pdf.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/parquet_pkl.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/parquet_xlsx.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/pkl_xlsx.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.1}/sleepyconvert/utils/png_jpg.py +0 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sleepyconvert
|
|
3
|
+
Version: 2.3.1
|
|
4
|
+
Summary: Convert data files, images, and documents between formats from a single terse CLI.
|
|
5
|
+
License-Expression: GPL-3.0-or-later
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: pandas,data,documents,images,converter,cli
|
|
8
|
+
Author: Isaac Yep
|
|
9
|
+
Author-email: anthonybenchyep@gmail.com
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Utilities
|
|
20
|
+
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
|
|
21
|
+
Classifier: Topic :: Text Processing :: Markup
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: beautifulsoup4 (>=4.12.0)
|
|
25
|
+
Requires-Dist: black (>=24.10.0) ; extra == "dev"
|
|
26
|
+
Requires-Dist: markdown (>=3.7)
|
|
27
|
+
Requires-Dist: markdownify (>=0.13.1)
|
|
28
|
+
Requires-Dist: openpyxl (>=3.1.0)
|
|
29
|
+
Requires-Dist: pandas (>=2.2.0)
|
|
30
|
+
Requires-Dist: pillow (>=11.0.0)
|
|
31
|
+
Requires-Dist: pyarrow (>=18.0.0)
|
|
32
|
+
Requires-Dist: pypdf (>=5.0.0)
|
|
33
|
+
Requires-Dist: pytest (>=8.3.0) ; extra == "dev"
|
|
34
|
+
Requires-Dist: pyyaml (>=6.0)
|
|
35
|
+
Requires-Dist: reportlab (>=4.2.0)
|
|
36
|
+
Requires-Dist: shfmt-py (>=3.8.0) ; extra == "dev"
|
|
37
|
+
Requires-Dist: typer (>=0.16.0)
|
|
38
|
+
Project-URL: Changelog, https://github.com/anthonybench/convert/releases
|
|
39
|
+
Project-URL: Documentation, https://github.com/anthonybench/convert#readme
|
|
40
|
+
Project-URL: Homepage, https://github.com/anthonybench/convert
|
|
41
|
+
Project-URL: Issues, https://github.com/anthonybench/convert/issues
|
|
42
|
+
Project-URL: Source, https://github.com/anthonybench/convert
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
|
|
45
|
+
<div align="center">
|
|
46
|
+
|
|
47
|
+
# 🔄 sleepyconvert
|
|
48
|
+
|
|
49
|
+
**Convert data, images, and documents between formats from one terse CLI.**
|
|
50
|
+
|
|
51
|
+
[](https://pypi.org/project/sleepyconvert/)
|
|
52
|
+
[](https://pypi.org/project/sleepyconvert/)
|
|
53
|
+
[](LICENSE)
|
|
54
|
+
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
`sleepyconvert` is a [Typer](https://typer.tiangolo.com/) CLI that converts files between formats, inferring intent **solely from the input and output extensions** — no subcommands, no flags to memorize. Point it at a source and a destination and it does the right thing.
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
uv tool install sleepyconvert # or: pipx install sleepyconvert
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Configure
|
|
66
|
+
|
|
67
|
+
`sleepyconvert` is a _sleepy util_ and reads its settings from the shared `~/sleepyconfig/params.yml`, using the `convert_` key prefix. If the file is absent it writes **only its own section** (below) and says so; if a value it needs is missing it prints this snippet and asks you to verify your config.
|
|
68
|
+
|
|
69
|
+
```yaml
|
|
70
|
+
# sleepyconvert
|
|
71
|
+
convert_output_archive_dir: null # a dir → also save a dated copy of every output; null → off
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
- **`convert_output_archive_dir`** — when set to a directory, every conversion also drops a dated copy of its output there as `<archive_dir>/<yyyy>_<mm>_<dd>_<output_filename>`.
|
|
75
|
+
|
|
76
|
+
## Supported conversions
|
|
77
|
+
|
|
78
|
+
| Category | Extensions |
|
|
79
|
+
| --- | --- |
|
|
80
|
+
| **Data** | `csv`, `parquet`, `json`, `pkl`, `xlsx` |
|
|
81
|
+
| **Images** | `png`, `jpg`, `jpeg` |
|
|
82
|
+
| **Documents** | `html`, `pdf`, `md` |
|
|
83
|
+
|
|
84
|
+
Any pair **within the same category** is valid (in either direction); cross-category conversions are rejected.
|
|
85
|
+
|
|
86
|
+
## Usage
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
sleepyconvert <input_path> <output_path>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Both paths resolve relative to the current directory, and their extensions decide the conversion.
|
|
93
|
+
|
|
94
|
+
**Data** — round-trip between tabular formats:
|
|
95
|
+
|
|
96
|
+
```console
|
|
97
|
+
$ sleepyconvert sales.csv sales.parquet
|
|
98
|
+
Created /Users/dingus/work/sales.parquet
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Images** — re-encode between raster formats:
|
|
102
|
+
|
|
103
|
+
```console
|
|
104
|
+
$ sleepyconvert photo.png photo.jpg
|
|
105
|
+
Created /Users/dingus/pics/photo.jpg
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Documents** — convert between markup and PDF:
|
|
109
|
+
|
|
110
|
+
```console
|
|
111
|
+
$ sleepyconvert notes.md notes.pdf
|
|
112
|
+
Created /Users/dingus/docs/notes.pdf
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
With `convert_output_archive_dir` set, each conversion also writes a dated archive copy:
|
|
116
|
+
|
|
117
|
+
```console
|
|
118
|
+
$ sleepyconvert sales.csv sales.parquet
|
|
119
|
+
Created /Users/dingus/work/sales.parquet
|
|
120
|
+
Archived copy written to /Users/dingus/archive/2026_02_09_sales.parquet
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Mixing categories fails fast with a clear message:
|
|
124
|
+
|
|
125
|
+
```console
|
|
126
|
+
$ sleepyconvert data.csv chart.png
|
|
127
|
+
Error: Input and output extensions must belong to the same type group.
|
|
128
|
+
Use `convert --help` to see the supported categories.
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Development
|
|
132
|
+
|
|
133
|
+
```sh
|
|
134
|
+
uv venv
|
|
135
|
+
uv pip install -e ".[dev]"
|
|
136
|
+
uv run pytest # or ./tools/test.sh
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Documentation
|
|
140
|
+
|
|
141
|
+
- [Specification](docs/SPEC.md) — what the tool does
|
|
142
|
+
- [Project outline](docs/OUTLINE.md) — repository layout
|
|
143
|
+
- [Test drive](docs/test_drive.md) — setup, testing, and CLI usage
|
|
144
|
+
- [Adding a conversion](docs/new_command.md) — how to add a new format pair
|
|
145
|
+
- [Publishing](docs/publish.md) — release to PyPI
|
|
146
|
+
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 🔄 sleepyconvert
|
|
4
|
+
|
|
5
|
+
**Convert data, images, and documents between formats from one terse CLI.**
|
|
6
|
+
|
|
7
|
+
[](https://pypi.org/project/sleepyconvert/)
|
|
8
|
+
[](https://pypi.org/project/sleepyconvert/)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
`sleepyconvert` is a [Typer](https://typer.tiangolo.com/) CLI that converts files between formats, inferring intent **solely from the input and output extensions** — no subcommands, no flags to memorize. Point it at a source and a destination and it does the right thing.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
uv tool install sleepyconvert # or: pipx install sleepyconvert
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Configure
|
|
22
|
+
|
|
23
|
+
`sleepyconvert` is a _sleepy util_ and reads its settings from the shared `~/sleepyconfig/params.yml`, using the `convert_` key prefix. If the file is absent it writes **only its own section** (below) and says so; if a value it needs is missing it prints this snippet and asks you to verify your config.
|
|
24
|
+
|
|
25
|
+
```yaml
|
|
26
|
+
# sleepyconvert
|
|
27
|
+
convert_output_archive_dir: null # a dir → also save a dated copy of every output; null → off
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- **`convert_output_archive_dir`** — when set to a directory, every conversion also drops a dated copy of its output there as `<archive_dir>/<yyyy>_<mm>_<dd>_<output_filename>`.
|
|
31
|
+
|
|
32
|
+
## Supported conversions
|
|
33
|
+
|
|
34
|
+
| Category | Extensions |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| **Data** | `csv`, `parquet`, `json`, `pkl`, `xlsx` |
|
|
37
|
+
| **Images** | `png`, `jpg`, `jpeg` |
|
|
38
|
+
| **Documents** | `html`, `pdf`, `md` |
|
|
39
|
+
|
|
40
|
+
Any pair **within the same category** is valid (in either direction); cross-category conversions are rejected.
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
sleepyconvert <input_path> <output_path>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Both paths resolve relative to the current directory, and their extensions decide the conversion.
|
|
49
|
+
|
|
50
|
+
**Data** — round-trip between tabular formats:
|
|
51
|
+
|
|
52
|
+
```console
|
|
53
|
+
$ sleepyconvert sales.csv sales.parquet
|
|
54
|
+
Created /Users/dingus/work/sales.parquet
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Images** — re-encode between raster formats:
|
|
58
|
+
|
|
59
|
+
```console
|
|
60
|
+
$ sleepyconvert photo.png photo.jpg
|
|
61
|
+
Created /Users/dingus/pics/photo.jpg
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Documents** — convert between markup and PDF:
|
|
65
|
+
|
|
66
|
+
```console
|
|
67
|
+
$ sleepyconvert notes.md notes.pdf
|
|
68
|
+
Created /Users/dingus/docs/notes.pdf
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
With `convert_output_archive_dir` set, each conversion also writes a dated archive copy:
|
|
72
|
+
|
|
73
|
+
```console
|
|
74
|
+
$ sleepyconvert sales.csv sales.parquet
|
|
75
|
+
Created /Users/dingus/work/sales.parquet
|
|
76
|
+
Archived copy written to /Users/dingus/archive/2026_02_09_sales.parquet
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Mixing categories fails fast with a clear message:
|
|
80
|
+
|
|
81
|
+
```console
|
|
82
|
+
$ sleepyconvert data.csv chart.png
|
|
83
|
+
Error: Input and output extensions must belong to the same type group.
|
|
84
|
+
Use `convert --help` to see the supported categories.
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Development
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
uv venv
|
|
91
|
+
uv pip install -e ".[dev]"
|
|
92
|
+
uv run pytest # or ./tools/test.sh
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Documentation
|
|
96
|
+
|
|
97
|
+
- [Specification](docs/SPEC.md) — what the tool does
|
|
98
|
+
- [Project outline](docs/OUTLINE.md) — repository layout
|
|
99
|
+
- [Test drive](docs/test_drive.md) — setup, testing, and CLI usage
|
|
100
|
+
- [Adding a conversion](docs/new_command.md) — how to add a new format pair
|
|
101
|
+
- [Publishing](docs/publish.md) — release to PyPI
|
|
@@ -4,13 +4,28 @@ build-backend = "poetry.core.masonry.api"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "sleepyconvert"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.3.1"
|
|
8
8
|
description = "Convert data files, images, and documents between formats from a single terse CLI."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
11
|
-
license =
|
|
11
|
+
license = "GPL-3.0-or-later"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
12
13
|
keywords = ["pandas", "data", "documents", "images", "converter", "cli"]
|
|
13
14
|
authors = [{ name = "Isaac Yep", email = "anthonybenchyep@gmail.com" }]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 5 - Production/Stable",
|
|
17
|
+
"Environment :: Console",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Topic :: Utilities",
|
|
25
|
+
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
|
|
26
|
+
"Topic :: Text Processing :: Markup",
|
|
27
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
28
|
+
]
|
|
14
29
|
dependencies = [
|
|
15
30
|
"beautifulsoup4>=4.12.0",
|
|
16
31
|
"markdown>=3.7",
|
|
@@ -33,7 +48,11 @@ dev = [
|
|
|
33
48
|
]
|
|
34
49
|
|
|
35
50
|
[project.urls]
|
|
36
|
-
|
|
51
|
+
Homepage = "https://github.com/anthonybench/convert"
|
|
52
|
+
Documentation = "https://github.com/anthonybench/convert#readme"
|
|
53
|
+
Source = "https://github.com/anthonybench/convert"
|
|
54
|
+
Issues = "https://github.com/anthonybench/convert/issues"
|
|
55
|
+
Changelog = "https://github.com/anthonybench/convert/releases"
|
|
37
56
|
|
|
38
57
|
[project.scripts]
|
|
39
58
|
sleepyconvert = "sleepyconvert.main:run"
|
|
@@ -6,7 +6,7 @@ from dataclasses import dataclass
|
|
|
6
6
|
from pathlib import Path
|
|
7
7
|
import os
|
|
8
8
|
|
|
9
|
-
from sleepyconvert.core.sleepy_params import loadSleepyParams
|
|
9
|
+
from sleepyconvert.core.sleepy_params import loadSleepyParams, requireParam
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
@dataclass(frozen=True)
|
|
@@ -61,7 +61,7 @@ def loadAppConfig() -> AppConfig:
|
|
|
61
61
|
log_level = os.getenv("CONVERT_LOG_LEVEL", "INFO").upper()
|
|
62
62
|
|
|
63
63
|
params = loadSleepyParams()
|
|
64
|
-
raw_archive_dir = params
|
|
64
|
+
raw_archive_dir = requireParam(params, "convert_output_archive_dir")
|
|
65
65
|
output_archive_dir = Path(raw_archive_dir).expanduser() if raw_archive_dir else None
|
|
66
66
|
|
|
67
67
|
return AppConfig(
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""sleepyconvert's slice of the shared "sleepy utils" configuration.
|
|
2
|
+
|
|
3
|
+
All sleepy utilities read their parameters from a single shared file at
|
|
4
|
+
``~/sleepyconfig/params.yml``, but each tool owns only its own
|
|
5
|
+
``<tool_shorthand>_<name>`` keys and never references another tool's keys. For
|
|
6
|
+
sleepyconvert the shorthand is ``convert``.
|
|
7
|
+
|
|
8
|
+
Behavior:
|
|
9
|
+
- When the file does not exist, this tool writes ONLY its own section (and says
|
|
10
|
+
so on the console).
|
|
11
|
+
- When the file exists but a value this tool needs is absent, the tool prints
|
|
12
|
+
its config snippet and asks the user to verify their sleepyconfig.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import os
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any, Callable
|
|
20
|
+
|
|
21
|
+
import typer
|
|
22
|
+
import yaml
|
|
23
|
+
|
|
24
|
+
# Environment override for the params file location. Primarily used by tests to
|
|
25
|
+
# avoid touching the real home directory.
|
|
26
|
+
PARAMS_PATH_ENV_VAR = "SLEEPYCONFIG_PARAMS_PATH"
|
|
27
|
+
|
|
28
|
+
# Human-facing tool name used in console messages.
|
|
29
|
+
TOOL_NAME = "sleepyconvert"
|
|
30
|
+
|
|
31
|
+
# In-memory defaults for this tool's own parameters.
|
|
32
|
+
DEFAULT_PARAMS: dict[str, Any] = {
|
|
33
|
+
"convert_output_archive_dir": None,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# This tool's own section of ``~/sleepyconfig/params.yml``. Written verbatim when
|
|
37
|
+
# the file is absent, and printed when a required value is missing.
|
|
38
|
+
DEFAULT_PARAMS_SNIPPET = """# sleepyconvert
|
|
39
|
+
convert_output_archive_dir: null
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def getParamsPath() -> Path:
|
|
44
|
+
"""Return the resolved path to the shared sleepy params file.
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
The params file path, honoring the ``SLEEPYCONFIG_PARAMS_PATH``
|
|
48
|
+
environment override when set.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
override = os.getenv(PARAMS_PATH_ENV_VAR)
|
|
52
|
+
if override:
|
|
53
|
+
return Path(override).expanduser()
|
|
54
|
+
return Path.home() / "sleepyconfig" / "params.yml"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def loadSleepyParams(echo: Callable[[str], None] = typer.echo) -> dict[str, Any]:
|
|
58
|
+
"""Load parameters from the shared sleepy config.
|
|
59
|
+
|
|
60
|
+
Writes only this tool's own section when the file is absent.
|
|
61
|
+
|
|
62
|
+
Parameters:
|
|
63
|
+
echo: Callable used to report that defaults were written. Defaults to
|
|
64
|
+
``typer.echo``.
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
The parameters present in the file (or this tool's defaults when the
|
|
68
|
+
file was just created). Values are not merged with defaults; missing
|
|
69
|
+
keys are surfaced lazily by :func:`requireParam`.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
params_path = getParamsPath()
|
|
73
|
+
|
|
74
|
+
if not params_path.exists():
|
|
75
|
+
params_path.parent.mkdir(parents=True, exist_ok=True)
|
|
76
|
+
params_path.write_text(DEFAULT_PARAMS_SNIPPET, encoding="utf-8")
|
|
77
|
+
echo(f"No sleepy config found; wrote {TOOL_NAME} defaults to {params_path}")
|
|
78
|
+
return dict(DEFAULT_PARAMS)
|
|
79
|
+
|
|
80
|
+
loaded = yaml.safe_load(params_path.read_text(encoding="utf-8")) or {}
|
|
81
|
+
return loaded if isinstance(loaded, dict) else {}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def requireParam(params: dict[str, Any], key: str, echo: Callable[..., None] = typer.echo) -> Any:
|
|
85
|
+
"""Return a required parameter, or guide the user to fix their config.
|
|
86
|
+
|
|
87
|
+
When the key is absent, prints this tool's config snippet and exits so the
|
|
88
|
+
user can verify their sleepyconfig.
|
|
89
|
+
|
|
90
|
+
Parameters:
|
|
91
|
+
params: The loaded parameters.
|
|
92
|
+
key: The required parameter key.
|
|
93
|
+
echo: Callable used to print the guidance. Defaults to ``typer.echo``.
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
The parameter value.
|
|
97
|
+
|
|
98
|
+
Raises:
|
|
99
|
+
typer.Exit: With code 1 when the key is missing.
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
if key not in params:
|
|
103
|
+
echo(
|
|
104
|
+
f"Missing '{key}' in {getParamsPath()}.\n"
|
|
105
|
+
f"Please verify your sleepyconfig is correct — the {TOOL_NAME} section "
|
|
106
|
+
f"should look like:\n\n{DEFAULT_PARAMS_SNIPPET}",
|
|
107
|
+
err=True,
|
|
108
|
+
)
|
|
109
|
+
raise typer.Exit(1)
|
|
110
|
+
return params[key]
|