Skip to content

Commit 18e4d2b

Browse files
committed
add convert backends to give the user a choice of using their preferred tool
1 parent 35ffbb0 commit 18e4d2b

22 files changed

+621
-254
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
downloads/
22
env*
33
requirements_optional.txt
4+
tests/data
45

5-
# DepHell stuff
66
poetry.lock
77

88
# Byte-compiled / optimized / DLL files

.pre-commit-config.yaml

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
11
repos:
2-
- repo: https://github.com/FHPythonUtils/Blackt
3-
rev: '2022.0.3'
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.3.3
44
hooks:
5-
- id: blackt
5+
- id: ruff
6+
args: [ --fix ]
7+
- id: ruff-format
68

7-
- repo: https://github.com/pycqa/isort
8-
rev: 5.12.0
9+
- repo: https://github.com/RobertCraigie/pyright-python
10+
rev: v1.1.354
911
hooks:
10-
- id: isort
12+
- id: pyright
1113

12-
- repo: https://github.com/pycqa/pylint
13-
rev: v3.0.0a6
14+
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
15+
rev: v1.3.3
1416
hooks:
15-
- id: pylint
16-
exclude: "tests/"
17-
args: [--disable=import-error,--jobs=0]
17+
- id: python-safety-dependencies-check
18+
files: pyproject.toml
1819

1920
- repo: https://github.com/pre-commit/pre-commit-hooks
20-
rev: v4.4.0
21+
rev: v4.5.0
2122
hooks:
2223
- id: trailing-whitespace
23-
exclude: "tests/"
2424
- id: end-of-file-fixer
25-
exclude: "tests/"
25+
- id: check-case-conflict
26+
- id: check-executables-have-shebangs
27+
- id: check-json
28+
- id: check-merge-conflict
29+
- id: check-shebang-scripts-are-executable
30+
- id: check-symlinks
31+
- id: check-toml
32+
- id: check-vcs-permalinks
33+
- id: check-yaml
34+
- id: detect-private-key
35+
- id: mixed-line-ending
2636

27-
- repo: https://github.com/asottile/pyupgrade
28-
rev: v3.7.0
29-
hooks:
30-
- id: pyupgrade
31-
args: [--py38-plus]
3237
- repo: https://github.com/boidolr/pre-commit-images
33-
rev: v1.2.1
38+
rev: v1.5.2
3439
hooks:
35-
- id: optimize-avif
36-
exclude: "tests/"
3740
- id: optimize-jpg
38-
exclude: "tests/"
3941
- id: optimize-png
40-
exclude: "tests/"
4142
- id: optimize-svg
42-
exclude: "tests/"
4343
- id: optimize-webp
44-
exclude: "tests/"
44+
45+
exclude: "tests/data|documentation/reference"

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
All major and minor version changes will be documented in this file. Details of
44
patch-level version changes can be found in [commit messages](../../commits/master).
55

6+
## 2024 - 2024/03/17
7+
8+
- add convert backends to give the user a choice of using their preferred tool
9+
- ruff
10+
- code quality improvements
11+
612
## 2022.1.1 - 2022/06/25
713

814
- Fix: add `parents=True` to `Path.mkdir()`

documentation/reference/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ A full list of `Tstickers` project modules.
88
- [Module](tstickers/module.md#module)
99
- [Caching](tstickers/caching.md#caching)
1010
- [Convert](tstickers/convert.md#convert)
11+
- [Convert Pyrlottie](tstickers/convert_pyrlottie.md#convert-pyrlottie)
12+
- [Convert Rlottie Python](tstickers/convert_rlottie_python.md#convert-rlottie-python)
1113
- [Downloader](tstickers/downloader.md#downloader)
Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,59 @@
11
# Caching
22

3-
[Tstickers Index](../README.md#tstickers-index) /
4-
[Tstickers](./index.md#tstickers) /
5-
Caching
3+
[Tstickers Index](../README.md#tstickers-index) / [Tstickers](./index.md#tstickers) / Caching
64

75
> Auto-generated documentation for [tstickers.caching](../../../tstickers/caching.py) module.
86
97
#### Attributes
108

11-
- `cachedSession` - requests_cache: `CachedSession('.cache/tstickers.requests.sqlite', backend='sqlite', expire_after=60 * 60 * 12, allowable_codes=(200), allowable_methods=('GET', 'POST'))`
9+
- `cachedSession` - requests_cache: CachedSession('.cache/tstickers.requests.sqlite', backend='sqlite', expire_after=60 * 60 * 12, allowable_codes=(200), allowable_methods=('GET', 'POST'))
1210

1311

1412
- [Caching](#caching)
13+
- [_verifyConvertedV1](#_verifyconvertedv1)
1514
- [createConverted](#createconverted)
1615
- [verifyConverted](#verifyconverted)
1716

17+
## _verifyConvertedV1
18+
19+
[Show source in caching.py:47](../../../tstickers/caching.py#L47)
20+
21+
Verify the cache for a packName using cache data.
22+
23+
#### Arguments
24+
25+
----
26+
data (dict[str, Any]) packName cache data to verify
27+
28+
#### Returns
29+
30+
-------
31+
- `bool` - if the converted cache has been verified
32+
33+
#### Signature
34+
35+
```python
36+
def _verifyConvertedV1(data: dict[str, Any]): ...
37+
```
38+
39+
40+
1841
## createConverted
1942

20-
[Show source in caching.py:60](../../../tstickers/caching.py#L60)
43+
[Show source in caching.py:66](../../../tstickers/caching.py#L66)
2144

22-
Write cache data to a file identified by packName
45+
Write cache data to a file identified by packName.
2346

2447
#### Arguments
2548

26-
- `packName` *str* - name of the sticker pack eg. "DonutTheDog"
27-
- `data` *dict* - packName cache data to write to cache
49+
----
50+
- `packName` *str* - name of the sticker pack eg. "DonutTheDog"
51+
- `data` *dict* - packName cache data to write to cache
2852

2953
#### Signature
3054

3155
```python
32-
def createConverted(packName: str, data: dict):
33-
...
56+
def createConverted(packName: str, data: dict) -> None: ...
3457
```
3558

3659

@@ -40,21 +63,20 @@ def createConverted(packName: str, data: dict):
4063
[Show source in caching.py:21](../../../tstickers/caching.py#L21)
4164

4265
Verify the cache for a packName eg. "DonutTheDog". Uses the cache "version"
43-
to call the verify function for that version
66+
to call the verify function for that version.
4467

4568
#### Arguments
4669

47-
- `packName` *str* - name of the sticker pack eg. "DonutTheDog"
70+
----
71+
- `packName` *str* - name of the sticker pack eg. "DonutTheDog"
4872

4973
#### Returns
5074

51-
- `bool` - if the converted cache has been verified
75+
-------
76+
- `bool` - if the converted cache has been verified
5277

5378
#### Signature
5479

5580
```python
56-
def verifyConverted(packName: str) -> bool:
57-
...
58-
```
59-
60-
81+
def verifyConverted(packName: str) -> bool: ...
82+
```
Lines changed: 77 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,148 @@
11
# Convert
22

3-
[Tstickers Index](../README.md#tstickers-index) /
4-
[Tstickers](./index.md#tstickers) /
5-
Convert
3+
[Tstickers Index](../README.md#tstickers-index) / [Tstickers](./index.md#tstickers) / Convert
64

75
> Auto-generated documentation for [tstickers.convert](../../../tstickers/convert.py) module.
86
97
- [Convert](#convert)
8+
- [Backend](#backend)
109
- [assureDirExists](#assuredirexists)
11-
- [convertTgs](#converttgs)
12-
- [convertWebp](#convertwebp)
10+
- [convertAnimated](#convertanimated)
11+
- [convertFunc](#convertfunc)
12+
- [convertStatic](#convertstatic)
1313
- [convertWithPIL](#convertwithpil)
1414

15+
## Backend
16+
17+
[Show source in convert.py:15](../../../tstickers/convert.py#L15)
18+
19+
#### Signature
20+
21+
```python
22+
class Backend(IntEnum): ...
23+
```
24+
25+
26+
1527
## assureDirExists
1628

17-
[Show source in convert.py:13](../../../tstickers/convert.py#L13)
29+
[Show source in convert.py:33](../../../tstickers/convert.py#L33)
1830

19-
make the dir if not exists
31+
Make the dir if not exists.
2032

2133
#### Arguments
2234

23-
- `root` *Path* - the path of the root directory
24-
- `directory` *Path|str* - the directory name
35+
----
36+
- `root` *Path* - the path of the root directory
37+
- `directory` *Path|str* - the directory name
2538

2639
#### Returns
2740

28-
- `Path` - the full path
41+
-------
42+
- `Path` - the full path
2943

3044
#### Signature
3145

3246
```python
33-
def assureDirExists(root: Path, directory: Path | str) -> Path:
34-
...
47+
def assureDirExists(root: Path, directory: Path | str) -> Path: ...
3548
```
3649

3750

3851

39-
## convertTgs
52+
## convertAnimated
4053

41-
[Show source in convert.py:72](../../../tstickers/convert.py#L72)
54+
[Show source in convert.py:101](../../../tstickers/convert.py#L101)
4255

43-
Convert animated stickers to webp, gif and png
56+
Convert animated stickers to webp, gif and png.
4457

4558
#### Arguments
4659

47-
- `swd` *Path* - the sticker working directory (downloads/packName)
48-
- `threads` *int, optional* - number of threads to pass to ThreadPoolExecutor. Defaults to 4.
49-
- `frameSkip` *int, optional* - skip n number of frames in the interest of
50-
optimisation with a quality trade-off. Defaults to 1.
51-
- `scale` *float, optional* - upscale/ downscale the images produced. Intended
52-
for optimisation with a quality trade-off. Defaults to 1.
60+
----
61+
- `swd` *Path* - the sticker working directory (downloads/packName)
62+
- `threads` *int, optional* - number of threads to pass to ThreadPoolExecutor. Defaults to number of cores/ logical processors.
63+
- `frameSkip` *int, optional* - skip n number of frames in the interest of
64+
optimisation with a quality trade-off. Defaults to 1.
65+
- `scale` *float, optional* - upscale/ downscale the images produced. Intended
66+
for optimisation with a quality trade-off. Defaults to 1.
5367

5468
#### Returns
5569

56-
- `int` - number of stickers successfully converted
70+
-------
71+
- `int` - number of stickers successfully converted
5772

5873
#### Signature
5974

6075
```python
61-
def convertTgs(swd: Path, threads: int = 4, frameSkip: int = 1, scale: float = 1) -> int:
62-
...
76+
def convertAnimated(
77+
swd: Path,
78+
threads: int = multiprocessing.cpu_count(),
79+
frameSkip: int = 1,
80+
scale: float = 1,
81+
backend: Backend = Backend.UNDEFINED,
82+
) -> int: ...
6383
```
6484

85+
#### See also
6586

87+
- [Backend](#backend)
6688

67-
## convertWebp
6889

69-
[Show source in convert.py:44](../../../tstickers/convert.py#L44)
7090

71-
Convert static stickers to png and gif
91+
## convertFunc
92+
93+
[Show source in convert.py:21](../../../tstickers/convert.py#L21)
94+
95+
#### Signature
96+
97+
```python
98+
def convertFunc(_x, _y, _z, _a) -> int: ...
99+
```
100+
101+
102+
103+
## convertStatic
104+
105+
[Show source in convert.py:70](../../../tstickers/convert.py#L70)
106+
107+
Convert static stickers to png and gif.
72108

73109
#### Arguments
74110

75-
- `swd` *Path* - the sticker working directory (downloads/packName)
76-
- `threads` *int, optional* - number of threads to pass to ThreadPoolExecutor. Defaults to 4.
111+
----
112+
- `swd` *Path* - the sticker working directory (downloads/packName)
113+
- `threads` *int, optional* - number of threads to pass to ThreadPoolExecutor. Defaults to 4.
77114

78115
#### Returns
79116

80-
- `int` - number of stickers successfully converted
117+
-------
118+
- `int` - number of stickers successfully converted
81119

82120
#### Signature
83121

84122
```python
85-
def convertWebp(swd: Path, threads: int = 4) -> int:
86-
...
123+
def convertStatic(swd: Path, threads: int = 4) -> int: ...
87124
```
88125

89126

90127

91128
## convertWithPIL
92129

93-
[Show source in convert.py:27](../../../tstickers/convert.py#L27)
130+
[Show source in convert.py:50](../../../tstickers/convert.py#L50)
94131

95-
Convert the webp file to png
132+
Convert the webp file to png.
96133

97134
#### Arguments
98135

99-
- `inputFile` *str* - path to input file
136+
----
137+
- `inputFile` *str* - path to input file
100138

101139
#### Returns
102140

103-
- `str` - path to input file
141+
-------
142+
- `str` - path to input file
104143

105144
#### Signature
106145

107146
```python
108-
def convertWithPIL(inputFile: str) -> str:
109-
...
110-
```
111-
112-
147+
def convertWithPIL(inputFile: str) -> str: ...
148+
```

0 commit comments

Comments
 (0)