Skip to content

Commit 7fb2d55

Browse files
committed
refactor: use internal stgpytools
1 parent fa38d84 commit 7fb2d55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2751
-43
lines changed

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
VapourSynth>=68
2-
stgpytools>=1.2.0
32
rich>=12.6.0

vstools/enums/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from stgpytools import CustomEnum, CustomIntEnum, CustomStrEnum, SelfEnum
3+
from vstools.stgpytools import CustomEnum, CustomIntEnum, CustomStrEnum, SelfEnum
44

55
__all__ = [
66
'SelfEnum',

vstools/enums/color.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any, NamedTuple, TypeAlias, Union
44

55
import vapoursynth as vs
6-
from stgpytools import FuncExceptT, classproperty
6+
from vstools.stgpytools import FuncExceptT, classproperty
77

88
from ..exceptions import (
99
ReservedMatrixError, ReservedPrimariesError, ReservedTransferError, UndefinedMatrixError, UndefinedPrimariesError,

vstools/enums/funcs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import Literal, TypeAlias, Union
44

5-
from stgpytools import CustomIntEnum, CustomStrEnum
5+
from vstools.stgpytools import CustomIntEnum, CustomStrEnum
66

77
__all__ = [
88
'ConvMode',

vstools/enums/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import TYPE_CHECKING, Any, TypeAlias, Union
44

55
import vapoursynth as vs
6-
from stgpytools import FuncExceptT
6+
from vstools.stgpytools import FuncExceptT
77

88
from ..exceptions import (
99
UndefinedChromaLocationError, UndefinedFieldBasedError, UnsupportedChromaLocationError,

vstools/enums/other.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Callable, Iterable, Literal, NamedTuple, TypeVar, overload
66

77
import vapoursynth as vs
8-
from stgpytools import Coordinate, CustomIntEnum, CustomStrEnum, FuncExceptT, Position, Sentinel, Size
8+
from vstools.stgpytools import Coordinate, CustomIntEnum, CustomStrEnum, FuncExceptT, Position, Sentinel, Size
99

1010
from ..types import HoldsPropValueT
1111

vstools/enums/stubs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import TYPE_CHECKING, Any, Iterable, TypeVar, overload
55

66
import vapoursynth as vs
7-
from stgpytools import MISSING, CustomError, CustomIntEnum, FuncExceptT, classproperty
7+
from vstools.stgpytools import MISSING, CustomError, CustomIntEnum, FuncExceptT, classproperty
88

99
__all__ = [
1010
'PropEnum',

vstools/exceptions/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from stgpytools import (
3+
from vstools.stgpytools import (
44
CustomError, CustomIndexError, CustomKeyError, CustomNotImplementedError, CustomOverflowError,
55
CustomPermissionError, CustomRuntimeError, CustomTypeError, CustomValueError
66
)

vstools/exceptions/color.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any
44

55
import vapoursynth as vs
6-
from stgpytools import CustomPermissionError, CustomValueError, FuncExceptT, SupportsString
6+
from vstools.stgpytools import CustomPermissionError, CustomValueError, FuncExceptT, SupportsString
77

88
__all__ = [
99
'InvalidColorspacePathError',

vstools/exceptions/enum.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from stgpytools import CustomValueError, NotFoundEnumValue
3+
from vstools.stgpytools import CustomValueError, NotFoundEnumValue
44

55
__all__ = [
66
'UndefinedChromaLocationError',

vstools/exceptions/file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from stgpytools import (
3+
from vstools.stgpytools import (
44
FileIsADirectoryError, FileNotExistsError, FilePermissionError, FileTypeMismatchError, FileWasNotFoundError
55
)
66

vstools/exceptions/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import TYPE_CHECKING, Any, Iterable, Sized
55

66
import vapoursynth as vs
7-
from stgpytools import (
7+
from vstools.stgpytools import (
88
CustomKeyError, CustomOverflowError, CustomValueError, FuncExceptT, MismatchError, MismatchRefError, SupportsString
99
)
1010

vstools/exceptions/module.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import Any
44

5-
from stgpytools import CustomImportError, DependencyNotFoundError, FuncExceptT, SupportsString
5+
from vstools.stgpytools import CustomImportError, DependencyNotFoundError, FuncExceptT, SupportsString
66

77
__all__ = [
88
'CustomImportError',

vstools/functions/check.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Any, Callable, TypeGuard, cast, overload
66

77
import vapoursynth as vs
8-
from stgpytools import CustomError, F, FuncExceptT
8+
from vstools.stgpytools import CustomError, F, FuncExceptT
99

1010
from ..exceptions import (
1111
FormatsRefClipMismatchError, ResolutionsRefClipMismatchError, VariableFormatError, VariableResolutionError

vstools/functions/file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import inspect
44
from pathlib import Path
55

6-
from stgpytools import CustomRuntimeError, SPath, get_script_path
6+
from vstools.stgpytools import CustomRuntimeError, SPath, get_script_path
77

88
__all__ = [
99
'PackageStorage'

vstools/functions/funcs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Iterable, Sequence
44

55
import vapoursynth as vs
6-
from stgpytools import FuncExceptT, T, cachedproperty, fallback, iterate, kwargs_fallback, normalize_seq, to_arr
6+
from vstools.stgpytools import FuncExceptT, T, cachedproperty, fallback, iterate, kwargs_fallback, normalize_seq, to_arr
77

88
from vstools.exceptions.color import InvalidColorspacePathError
99

vstools/functions/heuristics.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any, Literal, overload
44

55
import vapoursynth as vs
6-
from stgpytools import KwargsT
6+
from vstools.stgpytools import KwargsT
77
from vstools import PropEnum
88

99
from ..enums import ChromaLocation, ColorRange, Matrix, Primaries, Transfer

vstools/functions/normalize.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from typing import Any, Iterable, Sequence, overload
44

55
import vapoursynth as vs
6-
from stgpytools import T, norm_display_name, norm_func_name, normalize_list_to_ranges, to_arr
7-
from stgpytools import (
6+
from vstools.stgpytools import T, norm_display_name, norm_func_name, normalize_list_to_ranges, to_arr
7+
from vstools.stgpytools import (
88
flatten as stg_flatten,
99
invert_ranges as stg_invert_ranges,
1010
normalize_range as normalize_franges,

vstools/functions/packets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import Self, TypedDict
1010

1111
import vapoursynth as vs
12-
from stgpytools import CustomValueError, DependencyNotFoundError, FuncExceptT, SPath, SPathLike
12+
from vstools.stgpytools import CustomValueError, DependencyNotFoundError, FuncExceptT, SPath, SPathLike
1313

1414
from .file import PackageStorage
1515
from .timecodes import Keyframes

vstools/functions/render.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from typing import BinaryIO, Callable, Literal, overload
88

99
import vapoursynth as vs
10-
from stgpytools import CustomRuntimeError, CustomValueError, Sentinel, T, normalize_list_to_ranges
11-
from stgpytools.types.funcs import SentinelDispatcher
10+
from vstools.stgpytools import CustomRuntimeError, CustomValueError, Sentinel, T, normalize_list_to_ranges
11+
from vstools.stgpytools.types.funcs import SentinelDispatcher
1212

1313
from ..exceptions import InvalidColorFamilyError
1414
from .progress import get_render_progress

vstools/functions/timecodes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import Any, ClassVar, Iterable, NamedTuple, TypeVar, overload
88

99
import vapoursynth as vs
10-
from stgpytools import CustomValueError, FilePathType, FuncExceptT, LinearRangeLut, Sentinel, SPath, inject_self
10+
from vstools.stgpytools import CustomValueError, FilePathType, FuncExceptT, LinearRangeLut, Sentinel, SPath, inject_self
1111

1212
from ..enums import Matrix, SceneChangeMode
1313
from ..exceptions import FramesLengthError, InvalidTimecodeVersionError

vstools/functions/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from weakref import WeakValueDictionary
66

77
import vapoursynth as vs
8-
from stgpytools import CustomIndexError, CustomStrEnum, CustomValueError
8+
from vstools.stgpytools import CustomIndexError, CustomStrEnum, CustomValueError
99

1010
from ..enums import ColorRange, ColorRangeT, Matrix
1111
from ..exceptions import ClipLengthError, InvalidColorFamilyError

vstools/stgpytools/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .enums import * # noqa: F401, F403
2+
from .exceptions import * # noqa: F401, F403
3+
from .functions import * # noqa: F401, F403
4+
from .types import * # noqa: F401, F403
5+
from .utils import * # noqa: F401, F403

vstools/stgpytools/_metadata.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Collection of stuff that's useful in general python programming"""
2+
3+
__version__ = '1.2.2'
4+
5+
__author__ = 'Setsugen no ao <[email protected]>'
6+
__maintainer__ = __author__
7+
8+
__author_name__, __author_email__ = [x[:-1] for x in __author__.split('<')]
9+
__maintainer_name__, __maintainer_email__ = [x[:-1] for x in __maintainer__.split('<')]
10+
11+
if __name__ == '__github__':
12+
print(__version__)

vstools/stgpytools/enums/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .base import * # noqa: F401, F403
2+
from .other import * # noqa: F401, F403

vstools/stgpytools/enums/base.py

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from __future__ import annotations
2+
3+
from enum import Enum
4+
from typing import Any, TypeVar
5+
6+
from ..exceptions import CustomValueError, NotFoundEnumValue
7+
from ..types import FuncExceptT
8+
9+
__all__ = [
10+
'SelfEnum',
11+
'CustomEnum', 'CustomIntEnum', 'CustomStrEnum'
12+
]
13+
14+
15+
class CustomEnum(Enum):
16+
"""Base class for custom enums."""
17+
18+
@classmethod
19+
def _missing_(cls: type[SelfEnum], value: Any) -> SelfEnum | None:
20+
return cls.from_param(value)
21+
22+
@classmethod
23+
def from_param(cls: type[SelfEnum], value: Any, func_except: FuncExceptT | None = None) -> SelfEnum | None:
24+
"""
25+
Return the enum value from a parameter.
26+
27+
:param value: Value to instantiate the enum class.
28+
:param func_except: Exception function.
29+
30+
:return: Enum value.
31+
32+
:raises NotFoundEnumValue: Variable not found in the given enum.
33+
"""
34+
35+
if value is None:
36+
return None
37+
38+
if func_except is None:
39+
func_except = cls.from_param
40+
41+
if isinstance(value, cls):
42+
return value
43+
44+
if value is cls:
45+
raise CustomValueError('You must select a member, not pass the enum!', func_except)
46+
47+
try:
48+
return cls(value)
49+
except Exception:
50+
pass
51+
52+
if isinstance(func_except, tuple):
53+
func_name, var_name = func_except
54+
else:
55+
func_name, var_name = func_except, cls
56+
57+
raise NotFoundEnumValue(
58+
'The given value for "{var_name}" argument must be a valid {enum_name}, not "{value}"!\n'
59+
'Valid values are: [{readable_enum}].', func_name,
60+
var_name=var_name, enum_name=cls, value=value,
61+
readable_enum=iter([f'{x.name} ({x.value})' for x in cls]),
62+
reason=value
63+
)
64+
65+
66+
class CustomIntEnum(int, CustomEnum):
67+
"""Base class for custom int enums."""
68+
69+
value: int
70+
71+
72+
class CustomStrEnum(str, CustomEnum):
73+
"""Base class for custom str enums."""
74+
75+
value: str
76+
77+
78+
SelfEnum = TypeVar('SelfEnum', bound=CustomEnum)

vstools/stgpytools/enums/other.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from __future__ import annotations
2+
3+
from typing import TypeVar, overload
4+
5+
__all__ = [
6+
'Coordinate',
7+
'Position',
8+
'Size'
9+
]
10+
11+
12+
class Coordinate:
13+
"""
14+
Positive set of (x, y) coordinates.
15+
16+
:raises ValueError: Negative values were passed.
17+
"""
18+
19+
x: int
20+
"""Horizontal coordinate."""
21+
22+
y: int
23+
"""Vertical coordinate."""
24+
25+
@overload
26+
def __init__(self: SelfCoord, other: tuple[int, int] | SelfCoord, /) -> None:
27+
...
28+
29+
@overload
30+
def __init__(self: SelfCoord, x: int, y: int, /) -> None:
31+
...
32+
33+
def __init__(self: SelfCoord, x_or_self: int | tuple[int, int] | SelfCoord, y: int | None = None, /) -> None:
34+
from ..exceptions import CustomValueError
35+
36+
if isinstance(x_or_self, int):
37+
x = x_or_self
38+
else:
39+
x, y = x_or_self if isinstance(x_or_self, tuple) else (x_or_self.x, x_or_self.y)
40+
41+
if y is None:
42+
raise CustomValueError("y coordinate must be defined!", self.__class__)
43+
44+
if x < 0 or y < 0:
45+
raise CustomValueError("Values can't be negative!", self.__class__)
46+
47+
self.x = x
48+
self.y = y
49+
50+
51+
SelfCoord = TypeVar('SelfCoord', bound=Coordinate)
52+
53+
54+
class Position(Coordinate):
55+
"""Positive set of an (x,y) offset relative to the top left corner of an area."""
56+
57+
58+
class Size(Coordinate):
59+
"""Positive set of an (x,y), (horizontal,vertical), size of an area."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .base import * # noqa: F401, F403
2+
from .enum import * # noqa: F401, F403
3+
from .file import * # noqa: F401, F403
4+
from .generic import * # noqa: F401, F403
5+
from .module import * # noqa: F401, F403

0 commit comments

Comments
 (0)