sleepyconvert 2.2.0__tar.gz → 2.3.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.
- sleepyconvert-2.3.2/PKG-INFO +148 -0
- sleepyconvert-2.3.2/README.md +103 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/pyproject.toml +22 -3
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/core/config.py +2 -2
- sleepyconvert-2.3.2/sleepyconvert/core/sleepy_params.py +110 -0
- sleepyconvert-2.3.2/sleepyconvert/core/version.py +84 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/main.py +15 -2
- 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.2}/LICENSE +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/__init__.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/cli/__init__.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/cli/command_logic.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/core/__init__.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/core/logging.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/__init__.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/csv_json.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/csv_parquet.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/csv_pkl.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/csv_xlsx.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/data_shared.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/doc_shared.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/html_md.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/html_pdf.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/image_shared.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/json_parquet.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/json_pkl.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/json_xlsx.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/md_pdf.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/parquet_pkl.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/parquet_xlsx.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/pkl_xlsx.py +0 -0
- {sleepyconvert-2.2.0 → sleepyconvert-2.3.2}/sleepyconvert/utils/png_jpg.py +0 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sleepyconvert
|
|
3
|
+
Version: 2.3.2
|
|
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
|
+
> `-v` / `--version` prints the version and best-effort checks PyPI for a newer release — it works even when placed alongside the paths.
|
|
66
|
+
|
|
67
|
+
## Configure
|
|
68
|
+
|
|
69
|
+
`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.
|
|
70
|
+
|
|
71
|
+
```yaml
|
|
72
|
+
# sleepyconvert
|
|
73
|
+
convert_output_archive_dir: null # a dir → also save a dated copy of every output; null → off
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- **`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>`.
|
|
77
|
+
|
|
78
|
+
## Supported conversions
|
|
79
|
+
|
|
80
|
+
| Category | Extensions |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| **Data** | `csv`, `parquet`, `json`, `pkl`, `xlsx` |
|
|
83
|
+
| **Images** | `png`, `jpg`, `jpeg` |
|
|
84
|
+
| **Documents** | `html`, `pdf`, `md` |
|
|
85
|
+
|
|
86
|
+
Any pair **within the same category** is valid (in either direction); cross-category conversions are rejected.
|
|
87
|
+
|
|
88
|
+
## Usage
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
sleepyconvert <input_path> <output_path>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Both paths resolve relative to the current directory, and their extensions decide the conversion.
|
|
95
|
+
|
|
96
|
+
**Data** — round-trip between tabular formats:
|
|
97
|
+
|
|
98
|
+
```console
|
|
99
|
+
$ sleepyconvert sales.csv sales.parquet
|
|
100
|
+
Created /Users/dingus/work/sales.parquet
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Images** — re-encode between raster formats:
|
|
104
|
+
|
|
105
|
+
```console
|
|
106
|
+
$ sleepyconvert photo.png photo.jpg
|
|
107
|
+
Created /Users/dingus/pics/photo.jpg
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Documents** — convert between markup and PDF:
|
|
111
|
+
|
|
112
|
+
```console
|
|
113
|
+
$ sleepyconvert notes.md notes.pdf
|
|
114
|
+
Created /Users/dingus/docs/notes.pdf
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
With `convert_output_archive_dir` set, each conversion also writes a dated archive copy:
|
|
118
|
+
|
|
119
|
+
```console
|
|
120
|
+
$ sleepyconvert sales.csv sales.parquet
|
|
121
|
+
Created /Users/dingus/work/sales.parquet
|
|
122
|
+
Archived copy written to /Users/dingus/archive/2026_02_09_sales.parquet
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Mixing categories fails fast with a clear message:
|
|
126
|
+
|
|
127
|
+
```console
|
|
128
|
+
$ sleepyconvert data.csv chart.png
|
|
129
|
+
Error: Input and output extensions must belong to the same type group.
|
|
130
|
+
Use `convert --help` to see the supported categories.
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Development
|
|
134
|
+
|
|
135
|
+
```sh
|
|
136
|
+
uv venv
|
|
137
|
+
uv pip install -e ".[dev]"
|
|
138
|
+
uv run pytest # or ./tools/test.sh
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Documentation
|
|
142
|
+
|
|
143
|
+
- [Specification](docs/SPEC.md) — what the tool does
|
|
144
|
+
- [Project outline](docs/OUTLINE.md) — repository layout
|
|
145
|
+
- [Test drive](docs/test_drive.md) — setup, testing, and CLI usage
|
|
146
|
+
- [Adding a conversion](docs/new_command.md) — how to add a new format pair
|
|
147
|
+
- [Publishing](docs/publish.md) — release to PyPI
|
|
148
|
+
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
> `-v` / `--version` prints the version and best-effort checks PyPI for a newer release — it works even when placed alongside the paths.
|
|
22
|
+
|
|
23
|
+
## Configure
|
|
24
|
+
|
|
25
|
+
`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.
|
|
26
|
+
|
|
27
|
+
```yaml
|
|
28
|
+
# sleepyconvert
|
|
29
|
+
convert_output_archive_dir: null # a dir → also save a dated copy of every output; null → off
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- **`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>`.
|
|
33
|
+
|
|
34
|
+
## Supported conversions
|
|
35
|
+
|
|
36
|
+
| Category | Extensions |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| **Data** | `csv`, `parquet`, `json`, `pkl`, `xlsx` |
|
|
39
|
+
| **Images** | `png`, `jpg`, `jpeg` |
|
|
40
|
+
| **Documents** | `html`, `pdf`, `md` |
|
|
41
|
+
|
|
42
|
+
Any pair **within the same category** is valid (in either direction); cross-category conversions are rejected.
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
sleepyconvert <input_path> <output_path>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Both paths resolve relative to the current directory, and their extensions decide the conversion.
|
|
51
|
+
|
|
52
|
+
**Data** — round-trip between tabular formats:
|
|
53
|
+
|
|
54
|
+
```console
|
|
55
|
+
$ sleepyconvert sales.csv sales.parquet
|
|
56
|
+
Created /Users/dingus/work/sales.parquet
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Images** — re-encode between raster formats:
|
|
60
|
+
|
|
61
|
+
```console
|
|
62
|
+
$ sleepyconvert photo.png photo.jpg
|
|
63
|
+
Created /Users/dingus/pics/photo.jpg
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Documents** — convert between markup and PDF:
|
|
67
|
+
|
|
68
|
+
```console
|
|
69
|
+
$ sleepyconvert notes.md notes.pdf
|
|
70
|
+
Created /Users/dingus/docs/notes.pdf
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
With `convert_output_archive_dir` set, each conversion also writes a dated archive copy:
|
|
74
|
+
|
|
75
|
+
```console
|
|
76
|
+
$ sleepyconvert sales.csv sales.parquet
|
|
77
|
+
Created /Users/dingus/work/sales.parquet
|
|
78
|
+
Archived copy written to /Users/dingus/archive/2026_02_09_sales.parquet
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Mixing categories fails fast with a clear message:
|
|
82
|
+
|
|
83
|
+
```console
|
|
84
|
+
$ sleepyconvert data.csv chart.png
|
|
85
|
+
Error: Input and output extensions must belong to the same type group.
|
|
86
|
+
Use `convert --help` to see the supported categories.
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Development
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
uv venv
|
|
93
|
+
uv pip install -e ".[dev]"
|
|
94
|
+
uv run pytest # or ./tools/test.sh
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Documentation
|
|
98
|
+
|
|
99
|
+
- [Specification](docs/SPEC.md) — what the tool does
|
|
100
|
+
- [Project outline](docs/OUTLINE.md) — repository layout
|
|
101
|
+
- [Test drive](docs/test_drive.md) — setup, testing, and CLI usage
|
|
102
|
+
- [Adding a conversion](docs/new_command.md) — how to add a new format pair
|
|
103
|
+
- [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.2
|
|
7
|
+
version = "2.3.2"
|
|
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]
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Version reporting and a best-effort PyPI update check.
|
|
2
|
+
|
|
3
|
+
The ``-v``/``--version`` flag is handled by a pre-scan of ``sys.argv`` in the CLI
|
|
4
|
+
entrypoint (see ``run``), so it works even when it appears alongside the
|
|
5
|
+
input/output paths (e.g. ``sleepyconvert a.csv b.parquet --version``) — the rest
|
|
6
|
+
of the command is ignored. The update check is best-effort and never fails the CLI.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import urllib.request
|
|
13
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
14
|
+
from typing import Callable, Optional, Sequence
|
|
15
|
+
|
|
16
|
+
DIST_NAME = "sleepyconvert"
|
|
17
|
+
_PYPI_JSON_URL = f"https://pypi.org/pypi/{DIST_NAME}/json"
|
|
18
|
+
_UPDATE_CHECK_TIMEOUT_SECONDS = 2.0
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def getVersion() -> str:
|
|
22
|
+
"""Return the installed distribution version, or ``"unknown"`` if unavailable."""
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
return version(DIST_NAME)
|
|
26
|
+
except PackageNotFoundError:
|
|
27
|
+
return "unknown"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def latestVersion() -> Optional[str]:
|
|
31
|
+
"""Best-effort fetch of the latest version on PyPI; ``None`` on any failure."""
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
with urllib.request.urlopen(
|
|
35
|
+
_PYPI_JSON_URL, timeout=_UPDATE_CHECK_TIMEOUT_SECONDS
|
|
36
|
+
) as response:
|
|
37
|
+
payload = json.load(response)
|
|
38
|
+
return str(payload["info"]["version"])
|
|
39
|
+
except Exception: # noqa: BLE001 - the check is best-effort; never fail the CLI
|
|
40
|
+
return None
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _asTuple(value: str) -> tuple[int, ...]:
|
|
44
|
+
return tuple(int(part) for part in value.split(".") if part.isdigit())
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def isNewer(candidate: str, current: str) -> bool:
|
|
48
|
+
"""Return whether ``candidate`` is a newer release than ``current``."""
|
|
49
|
+
|
|
50
|
+
candidate_parts, current_parts = _asTuple(candidate), _asTuple(current)
|
|
51
|
+
if candidate_parts and current_parts:
|
|
52
|
+
return candidate_parts > current_parts
|
|
53
|
+
return candidate != current # fall back to inequality if unparseable
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def wantsVersion(args: Sequence[str]) -> bool:
|
|
57
|
+
"""Return whether ``-v``/``--version`` appears anywhere in the given args."""
|
|
58
|
+
|
|
59
|
+
return any(arg in ("-v", "--version") for arg in args)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def printVersion(fetch_latest: Callable[[], Optional[str]] = latestVersion) -> None:
|
|
63
|
+
"""Print the current version and, best-effort, whether a newer one exists.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
fetch_latest: Callable returning the latest published version (or ``None``
|
|
67
|
+
when it can't be determined). Injectable for tests.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
None.
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
current = getVersion()
|
|
74
|
+
print(f"{DIST_NAME} {current}")
|
|
75
|
+
|
|
76
|
+
latest = fetch_latest()
|
|
77
|
+
if latest is None:
|
|
78
|
+
return # offline / lookup failed — stay quiet
|
|
79
|
+
if current == "unknown":
|
|
80
|
+
print(f"latest on PyPI: {latest}")
|
|
81
|
+
elif isNewer(latest, current):
|
|
82
|
+
print(f"⬆️ a newer version is available: {latest} (upgrade: uv tool upgrade {DIST_NAME})")
|
|
83
|
+
else:
|
|
84
|
+
print("✅ you're on the latest version")
|
|
@@ -2,13 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import sys
|
|
6
|
+
|
|
5
7
|
import typer
|
|
6
8
|
|
|
7
9
|
from sleepyconvert.cli.command_logic import runConversion
|
|
10
|
+
from sleepyconvert.core.version import printVersion, wantsVersion
|
|
8
11
|
|
|
9
12
|
app = typer.Typer(
|
|
10
13
|
add_completion=False,
|
|
11
|
-
help=
|
|
14
|
+
help=(
|
|
15
|
+
"Convert files between supported formats by passing an input and output path. "
|
|
16
|
+
"Pass -v/--version to print the version."
|
|
17
|
+
),
|
|
12
18
|
)
|
|
13
19
|
|
|
14
20
|
|
|
@@ -20,8 +26,15 @@ def main(input_path: str, output_path: str) -> None:
|
|
|
20
26
|
|
|
21
27
|
|
|
22
28
|
def run() -> None:
|
|
23
|
-
"""Run the Typer application.
|
|
29
|
+
"""Run the Typer application.
|
|
30
|
+
|
|
31
|
+
``-v``/``--version`` is honored before Typer parses, so it works even when it
|
|
32
|
+
appears alongside the paths; the conversion is skipped.
|
|
33
|
+
"""
|
|
24
34
|
|
|
35
|
+
if wantsVersion(sys.argv[1:]):
|
|
36
|
+
printVersion()
|
|
37
|
+
return
|
|
25
38
|
app()
|
|
26
39
|
|
|
27
40
|
|