sleepyconvert 2.0.0__tar.gz → 2.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.
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/PKG-INFO +20 -6
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/README.md +18 -5
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/pyproject.toml +2 -1
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/cli/command_logic.py +27 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/core/config.py +20 -2
- sleepyconvert-2.2.0/sleepyconvert/core/sleepy_params.py +102 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/LICENSE +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/__init__.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/cli/__init__.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/core/__init__.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/core/logging.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/main.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/__init__.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/csv_json.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/csv_parquet.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/csv_pkl.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/csv_xlsx.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/data_shared.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/doc_shared.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/html_md.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/html_pdf.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/image_shared.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/json_parquet.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/json_pkl.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/json_xlsx.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/md_pdf.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/parquet_pkl.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/parquet_xlsx.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/pkl_xlsx.py +0 -0
- {sleepyconvert-2.0.0 → sleepyconvert-2.2.0}/sleepyconvert/utils/png_jpg.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sleepyconvert
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Convert data files, images, and documents between formats from a single terse CLI.
|
|
5
5
|
License: GNU GENERAL PUBLIC LICENSE
|
|
6
6
|
Version 3, 29 June 2007
|
|
@@ -698,6 +698,7 @@ Requires-Dist: pillow (>=11.0.0)
|
|
|
698
698
|
Requires-Dist: pyarrow (>=18.0.0)
|
|
699
699
|
Requires-Dist: pypdf (>=5.0.0)
|
|
700
700
|
Requires-Dist: pytest (>=8.3.0) ; extra == "dev"
|
|
701
|
+
Requires-Dist: pyyaml (>=6.0)
|
|
701
702
|
Requires-Dist: reportlab (>=4.2.0)
|
|
702
703
|
Requires-Dist: shfmt-py (>=3.8.0) ; extra == "dev"
|
|
703
704
|
Requires-Dist: typer (>=0.16.0)
|
|
@@ -718,8 +719,10 @@ Formats can only be converted within the same category.
|
|
|
718
719
|
|
|
719
720
|
## Install
|
|
720
721
|
|
|
722
|
+
Install the CLI globally with [uv](https://docs.astral.sh/uv/):
|
|
723
|
+
|
|
721
724
|
```sh
|
|
722
|
-
|
|
725
|
+
uv tool install sleepyconvert
|
|
723
726
|
```
|
|
724
727
|
|
|
725
728
|
## Usage
|
|
@@ -739,13 +742,24 @@ sleepyconvert --help
|
|
|
739
742
|
|
|
740
743
|
## Development
|
|
741
744
|
|
|
745
|
+
Create the environment and install in editable mode with [uv](https://docs.astral.sh/uv/):
|
|
746
|
+
|
|
742
747
|
```sh
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
pip install -e ".[dev]"
|
|
748
|
+
uv venv
|
|
749
|
+
uv pip install -e ".[dev]"
|
|
746
750
|
```
|
|
747
751
|
|
|
748
|
-
Then run `pytest`, or `./tools/test.sh` to exercise the CLI end to end. Tear down with `
|
|
752
|
+
Then run `uv run pytest`, or `./tools/test.sh` to exercise the CLI end to end. Tear down with `rm -rf .venv`.
|
|
753
|
+
|
|
754
|
+
## Configuration
|
|
755
|
+
|
|
756
|
+
`sleepyconvert` is a *sleepy util* and reads shared settings from
|
|
757
|
+
`~/sleepyconfig/params.yml`. On first run the file is created with defaults and
|
|
758
|
+
a note is printed to the console. Relevant key:
|
|
759
|
+
|
|
760
|
+
- `convert_output_archive_dir` — when set to a directory, every conversion also
|
|
761
|
+
writes a dated copy of its output there as
|
|
762
|
+
`<archive_dir>/<yyyy>_<mm>_<dd>_<output_filename>`. Leave as `null` to disable.
|
|
749
763
|
|
|
750
764
|
## Documentation
|
|
751
765
|
|
|
@@ -12,8 +12,10 @@ Formats can only be converted within the same category.
|
|
|
12
12
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
15
|
+
Install the CLI globally with [uv](https://docs.astral.sh/uv/):
|
|
16
|
+
|
|
15
17
|
```sh
|
|
16
|
-
|
|
18
|
+
uv tool install sleepyconvert
|
|
17
19
|
```
|
|
18
20
|
|
|
19
21
|
## Usage
|
|
@@ -33,13 +35,24 @@ sleepyconvert --help
|
|
|
33
35
|
|
|
34
36
|
## Development
|
|
35
37
|
|
|
38
|
+
Create the environment and install in editable mode with [uv](https://docs.astral.sh/uv/):
|
|
39
|
+
|
|
36
40
|
```sh
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
pip install -e ".[dev]"
|
|
41
|
+
uv venv
|
|
42
|
+
uv pip install -e ".[dev]"
|
|
40
43
|
```
|
|
41
44
|
|
|
42
|
-
Then run `pytest`, or `./tools/test.sh` to exercise the CLI end to end. Tear down with `
|
|
45
|
+
Then run `uv run pytest`, or `./tools/test.sh` to exercise the CLI end to end. Tear down with `rm -rf .venv`.
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
`sleepyconvert` is a *sleepy util* and reads shared settings from
|
|
50
|
+
`~/sleepyconfig/params.yml`. On first run the file is created with defaults and
|
|
51
|
+
a note is printed to the console. Relevant key:
|
|
52
|
+
|
|
53
|
+
- `convert_output_archive_dir` — when set to a directory, every conversion also
|
|
54
|
+
writes a dated copy of its output there as
|
|
55
|
+
`<archive_dir>/<yyyy>_<mm>_<dd>_<output_filename>`. Leave as `null` to disable.
|
|
43
56
|
|
|
44
57
|
## Documentation
|
|
45
58
|
|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "sleepyconvert"
|
|
7
|
-
version = "2.
|
|
7
|
+
version = "2.2.0"
|
|
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"
|
|
@@ -20,6 +20,7 @@ dependencies = [
|
|
|
20
20
|
"pillow>=11.0.0",
|
|
21
21
|
"pyarrow>=18.0.0",
|
|
22
22
|
"pypdf>=5.0.0",
|
|
23
|
+
"pyyaml>=6.0",
|
|
23
24
|
"reportlab>=4.2.0",
|
|
24
25
|
"typer>=0.16.0",
|
|
25
26
|
]
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import shutil
|
|
6
|
+
from datetime import date
|
|
5
7
|
from pathlib import Path
|
|
6
8
|
from typing import Callable
|
|
7
9
|
|
|
@@ -83,6 +85,27 @@ def _prepareOutputDirectory(output_file_path: Path) -> None:
|
|
|
83
85
|
output_file_path.parent.mkdir(parents=True, exist_ok=True)
|
|
84
86
|
|
|
85
87
|
|
|
88
|
+
def _archiveOutput(output_file_path: Path, archive_dir: Path) -> Path:
|
|
89
|
+
"""Write a dated copy of the conversion output into the archive directory.
|
|
90
|
+
|
|
91
|
+
The archived file is named ``<yyyy>_<mm>_<dd>_<output_filename>`` and placed
|
|
92
|
+
inside ``archive_dir``.
|
|
93
|
+
|
|
94
|
+
Parameters:
|
|
95
|
+
output_file_path: The freshly written conversion output.
|
|
96
|
+
archive_dir: The directory to receive the dated copy.
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
The path of the archived copy.
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
archive_dir.mkdir(parents=True, exist_ok=True)
|
|
103
|
+
stamp = date.today().strftime("%Y_%m_%d")
|
|
104
|
+
archive_path = archive_dir / f"{stamp}_{output_file_path.name}"
|
|
105
|
+
shutil.copy2(output_file_path, archive_path)
|
|
106
|
+
return archive_path
|
|
107
|
+
|
|
108
|
+
|
|
86
109
|
def runConversion(input_path: str, output_path: str) -> None:
|
|
87
110
|
"""Validate arguments and perform the requested conversion.
|
|
88
111
|
|
|
@@ -124,3 +147,7 @@ def runConversion(input_path: str, output_path: str) -> None:
|
|
|
124
147
|
)
|
|
125
148
|
handler(input_file_path, output_file_path)
|
|
126
149
|
typer.echo(f"Created {output_file_path}")
|
|
150
|
+
|
|
151
|
+
if config.output_archive_dir is not None:
|
|
152
|
+
archive_path = _archiveOutput(output_file_path, config.output_archive_dir)
|
|
153
|
+
typer.echo(f"Archived copy written to {archive_path}")
|
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
|
+
from pathlib import Path
|
|
6
7
|
import os
|
|
7
8
|
|
|
9
|
+
from sleepyconvert.core.sleepy_params import loadSleepyParams
|
|
10
|
+
|
|
8
11
|
|
|
9
12
|
@dataclass(frozen=True)
|
|
10
13
|
class AppConfig:
|
|
@@ -13,10 +16,13 @@ class AppConfig:
|
|
|
13
16
|
Parameters:
|
|
14
17
|
supported_extensions: Mapping of category names to supported file extensions.
|
|
15
18
|
log_level: The configured logging level name.
|
|
19
|
+
output_archive_dir: Optional directory to receive a dated copy of every
|
|
20
|
+
conversion output. ``None`` disables archiving.
|
|
16
21
|
"""
|
|
17
22
|
|
|
18
23
|
supported_extensions: dict[str, tuple[str, ...]]
|
|
19
24
|
log_level: str
|
|
25
|
+
output_archive_dir: Path | None = None
|
|
20
26
|
|
|
21
27
|
def getCategoryForExtension(self, extension: str) -> str | None:
|
|
22
28
|
"""Return the category associated with a supported extension.
|
|
@@ -35,7 +41,10 @@ class AppConfig:
|
|
|
35
41
|
|
|
36
42
|
|
|
37
43
|
def loadAppConfig() -> AppConfig:
|
|
38
|
-
"""Load application configuration from defaults and
|
|
44
|
+
"""Load application configuration from defaults, environment, and shared params.
|
|
45
|
+
|
|
46
|
+
The optional output archive directory is sourced from the shared sleepy
|
|
47
|
+
config at ``~/sleepyconfig/params.yml`` (created with defaults on first run).
|
|
39
48
|
|
|
40
49
|
Parameters:
|
|
41
50
|
None.
|
|
@@ -50,4 +59,13 @@ def loadAppConfig() -> AppConfig:
|
|
|
50
59
|
"doc": ("html", "pdf", "md"),
|
|
51
60
|
}
|
|
52
61
|
log_level = os.getenv("CONVERT_LOG_LEVEL", "INFO").upper()
|
|
53
|
-
|
|
62
|
+
|
|
63
|
+
params = loadSleepyParams()
|
|
64
|
+
raw_archive_dir = params.get("convert_output_archive_dir")
|
|
65
|
+
output_archive_dir = Path(raw_archive_dir).expanduser() if raw_archive_dir else None
|
|
66
|
+
|
|
67
|
+
return AppConfig(
|
|
68
|
+
supported_extensions=supported_extensions,
|
|
69
|
+
log_level=log_level,
|
|
70
|
+
output_archive_dir=output_archive_dir,
|
|
71
|
+
)
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""Shared "sleepy utils" global configuration.
|
|
2
|
+
|
|
3
|
+
All sleepy utilities (sleepydatapeek, sleepyconvert, sleepybricks, and future
|
|
4
|
+
tools) read their user-tunable parameters from a single shared file at
|
|
5
|
+
``~/sleepyconfig/params.yml``. When the file is missing it is created with the
|
|
6
|
+
default template below and a message is printed to the console.
|
|
7
|
+
|
|
8
|
+
The schema in this module is intentionally duplicated across each sleepy
|
|
9
|
+
utility package: the tools ship as independent distributions and cannot share
|
|
10
|
+
an importable library, so each carries an identical copy of the shared
|
|
11
|
+
contract. Keep the template and defaults here in sync with the other tools.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import os
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Any, Callable
|
|
19
|
+
|
|
20
|
+
import typer
|
|
21
|
+
import yaml
|
|
22
|
+
|
|
23
|
+
# Environment override for the params file location. Primarily used by tests to
|
|
24
|
+
# avoid touching the real home directory.
|
|
25
|
+
PARAMS_PATH_ENV_VAR = "SLEEPYCONFIG_PARAMS_PATH"
|
|
26
|
+
|
|
27
|
+
# In-memory fallbacks for every known sleepy-utils parameter.
|
|
28
|
+
DEFAULT_PARAMS: dict[str, Any] = {
|
|
29
|
+
# sleepydatapeek
|
|
30
|
+
"datapeek_sample_size": 5,
|
|
31
|
+
"datapeek_table_style": "rounded_grid",
|
|
32
|
+
# sleepyconvert
|
|
33
|
+
"convert_output_archive_dir": None,
|
|
34
|
+
# sleepybricks
|
|
35
|
+
"bricks_table_style": "simple",
|
|
36
|
+
"serverless_warehouse_name": "<env>_serverless_warehouse",
|
|
37
|
+
"env_emojis": {"dev": "👩💻", "stg": "🔧", "us": "🇺🇸"},
|
|
38
|
+
"display_names": {"dev": "Development", "stg": "Staging", "us": "United States"},
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
# Verbatim contents written when the params file does not yet exist. This is
|
|
42
|
+
# written by whichever sleepy utility runs first, seeding keys for all tools.
|
|
43
|
+
DEFAULT_PARAMS_TEMPLATE = """# sleepydatapeek
|
|
44
|
+
datapeek_sample_size: 5
|
|
45
|
+
datapeek_table_style: rounded_grid
|
|
46
|
+
|
|
47
|
+
# sleepyconvert
|
|
48
|
+
convert_output_archive_dir: null
|
|
49
|
+
|
|
50
|
+
# sleepybricks
|
|
51
|
+
bricks_table_style: simple
|
|
52
|
+
serverless_warehouse_name: <env>_serverless_warehouse
|
|
53
|
+
env_emojis:
|
|
54
|
+
dev: "👩💻"
|
|
55
|
+
stg: "🔧"
|
|
56
|
+
us: "🇺🇸"
|
|
57
|
+
display_names:
|
|
58
|
+
dev: "Development"
|
|
59
|
+
stg: "Staging"
|
|
60
|
+
us: "United States"
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def getParamsPath() -> Path:
|
|
65
|
+
"""Return the resolved path to the shared sleepy params file.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
The params file path, honoring the ``SLEEPYCONFIG_PARAMS_PATH``
|
|
69
|
+
environment override when set.
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
override = os.getenv(PARAMS_PATH_ENV_VAR)
|
|
73
|
+
if override:
|
|
74
|
+
return Path(override).expanduser()
|
|
75
|
+
return Path.home() / "sleepyconfig" / "params.yml"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def loadSleepyParams(echo: Callable[[str], None] = typer.echo) -> dict[str, Any]:
|
|
79
|
+
"""Load shared sleepy parameters, creating the file with defaults if absent.
|
|
80
|
+
|
|
81
|
+
Parameters:
|
|
82
|
+
echo: Callable used to report that defaults were written. Defaults to
|
|
83
|
+
``typer.echo``.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
A mapping of parameter names to values, with defaults filled in for any
|
|
87
|
+
keys missing from the file.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
params_path = getParamsPath()
|
|
91
|
+
|
|
92
|
+
if not params_path.exists():
|
|
93
|
+
params_path.parent.mkdir(parents=True, exist_ok=True)
|
|
94
|
+
params_path.write_text(DEFAULT_PARAMS_TEMPLATE, encoding="utf-8")
|
|
95
|
+
echo(f"No sleepy config found; wrote defaults to {params_path}")
|
|
96
|
+
return dict(DEFAULT_PARAMS)
|
|
97
|
+
|
|
98
|
+
loaded = yaml.safe_load(params_path.read_text(encoding="utf-8")) or {}
|
|
99
|
+
merged = dict(DEFAULT_PARAMS)
|
|
100
|
+
if isinstance(loaded, dict):
|
|
101
|
+
merged.update(loaded)
|
|
102
|
+
return merged
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|