rc-toolkit 0.1.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.
@@ -0,0 +1,9 @@
1
+ Metadata-Version: 2.1
2
+ Name: rc-toolkit
3
+ Version: 0.1.0
4
+ License: MIT
5
+ Author-email: break-soul <57186766+break-soul@users.noreply.github.com>
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+
9
+ # rc-toolkit
@@ -0,0 +1 @@
1
+ # rc-toolkit
@@ -0,0 +1,21 @@
1
+ [project]
2
+ name = "rc-toolkit"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = [
6
+ { name = "break-soul", email = "57186766+break-soul@users.noreply.github.com" },
7
+ ]
8
+ dependencies = [
9
+ "rclog>=1.4.0",
10
+ ]
11
+ requires-python = ">=3.8"
12
+ readme = "README.md"
13
+
14
+ [project.license]
15
+ text = "MIT"
16
+
17
+ [build-system]
18
+ requires = [
19
+ "pdm-pep517>=1.0.0",
20
+ ]
21
+ build-backend = "pdm.pep517.api"
File without changes
@@ -0,0 +1,86 @@
1
+ """
2
+ This module contains functions to control the Python interpreter.
3
+ """
4
+
5
+ import os
6
+ import sys
7
+ import importlib.util
8
+
9
+ from typing import NoReturn, TYPE_CHECKING
10
+
11
+ from rclog import get_log
12
+
13
+ from .control import lazy_load
14
+
15
+ if TYPE_CHECKING:
16
+ from logging import Logger
17
+
18
+
19
+ class Env:
20
+ @staticmethod
21
+ def set_env(key: str, value: str) -> None:
22
+ os.environ[key] = value
23
+
24
+ @staticmethod
25
+ def get_env(key: str, default: Optional[str] = None) -> str:
26
+ return os.environ.get(key, default)
27
+
28
+ @staticmethod
29
+ @lazy_load
30
+ def is_debug() -> bool:
31
+ """
32
+ Check whether it == DEBUG mode
33
+
34
+ Returns:
35
+ bool: __debug__
36
+ """
37
+ return bool(Env.get_env("DEBUG", default=0))
38
+
39
+ @lazy_load
40
+ def log() -> "Logger":
41
+ return get_log("RCTK.base.pycontrol")
42
+
43
+
44
+ def get_pycache() -> str:
45
+ return sys.pycache_prefix()
46
+
47
+
48
+ def add_path(path: str) -> NoReturn:
49
+ sys.path.append(path)
50
+
51
+
52
+ def remove_path(path: str) -> NoReturn:
53
+ sys.path.remove(path)
54
+
55
+
56
+ class Compile:
57
+
58
+ @staticmethod
59
+ def compile_file(
60
+ file, cfile=None, dfile=None, doraise=False, optimize=1, quiet=0
61
+ ) -> None:
62
+ log.info("Compile {file}".format(file=file))
63
+ import py_compile
64
+
65
+ @staticmethod
66
+ def compile_dir(
67
+ path, cfile=None, dfile=None, doraise=False, optimize=1, quiet=0
68
+ ) -> None:
69
+ Compile.compile_file(file)
70
+
71
+
72
+ def set_global(key: str, value: object) -> NoReturn:
73
+ import builtins
74
+
75
+ log().warning("Hooking builtin {} as {}".format(key, str(value)))
76
+ builtins.__dict__[key] = value
77
+
78
+
79
+ def is_module(name, path: str) -> bool: ...
80
+
81
+
82
+ def get_module(path: str) -> object: ...
83
+
84
+
85
+ def exit_py() -> NoReturn:
86
+ sys.exit()
@@ -0,0 +1,172 @@
1
+ """
2
+ Store the enums used in the package.
3
+ """
4
+
5
+ from enum import Enum
6
+ from typing import overload, Tuple
7
+
8
+ from ..system.base import System, Arch
9
+
10
+
11
+ def mode_func(*args, **kw): ...
12
+
13
+
14
+ class _MISSING_TYPE:
15
+ pass
16
+
17
+
18
+ class Release(Enum):
19
+ ALPHA = "a"
20
+ BETA = "b"
21
+ RELEASE = "r"
22
+ DEBUG = "d"
23
+
24
+ @classmethod
25
+ def from_str(cls, rel_str: str) -> "Release":
26
+ if rel_str == "a":
27
+ return cls.ALPHA
28
+ if rel_str == "b":
29
+ return cls.BETA
30
+ if rel_str == "r":
31
+ return cls.RELEASE
32
+ if rel_str == "d":
33
+ return cls.DEBUG
34
+ raise ValueError("Invalid release string")
35
+
36
+
37
+ MISSING = _MISSING_TYPE()
38
+
39
+
40
+ class Version:
41
+ def __init__(self, ver_1: int, ver_2: int, ver_3: int, build: int = 0):
42
+ self.ver: Tuple[int, int, int] = (ver_1, ver_2, ver_3)
43
+ self.build: int = build
44
+
45
+ @classmethod
46
+ def from_str(cls, ver_str: str) -> "Version":
47
+ return cls(*cls.dump_ver(ver_str))
48
+
49
+ def set_build(self, build: int) -> None:
50
+ self.build = build
51
+
52
+ def get_build(self) -> int:
53
+ return self.build
54
+
55
+ def set_ver(self, ver: Tuple[int, int, int]) -> None:
56
+ self.ver = ver
57
+
58
+ def get_ver(self) -> Tuple[int, int, int]:
59
+ return self.ver
60
+
61
+ def update(self, ver_path: int = 3) -> None:
62
+ if ver_path < 1 or ver_path > 3:
63
+ raise ValueError("ver_path must be between 1 and 3")
64
+ ver_list = list(self.ver)
65
+ ver_list[ver_path - 1] += 1
66
+ self.ver = tuple(ver_list)
67
+
68
+ if self.build != 0:
69
+ self.build += 1
70
+
71
+ @overload
72
+ def dump_ver(ver_str: str) -> Tuple[int, int, int]: ...
73
+ @overload
74
+ def dump_ver(ver_str: str) -> Tuple[int, int, int, int]: ...
75
+ @staticmethod
76
+ def dump_ver(ver_str: str):
77
+ def _str_ver(ver_str: str) -> Tuple[int, int, int]:
78
+ return tuple(map(int, ver_str.split(".")))
79
+
80
+ ver_list = ver_str.split("_")
81
+ ver = _str_ver(ver_list[0])
82
+ if len(ver_list) > 1:
83
+ if ver_list[1].startswith("b"):
84
+ build = int(ver_list[1][1:])
85
+ return ver + (build,)
86
+ return ver
87
+
88
+ def __str__(self) -> str:
89
+ rt = f"v{self.ver[0]}.{self.ver[1]}.{self.ver[2]}"
90
+ if self.build == 0:
91
+ return rt
92
+ return rt + f"_b{self.build}"
93
+
94
+ def __repr__(self) -> str:
95
+ return self.__str__()
96
+
97
+ # region
98
+ def __eq__(self, other: "Version") -> bool:
99
+ return self.ver == other.ver and self.build == other.build
100
+
101
+ def __ne__(self, other: "Version") -> bool:
102
+ return not self.__eq__(other)
103
+
104
+ def __lt__(self, other: "Version") -> bool:
105
+ return self.ver < other.ver or (
106
+ self.ver == other.ver and self.build < other.build
107
+ )
108
+
109
+ def __le__(self, other: "Version") -> bool:
110
+ return self.ver < other.ver or (
111
+ self.ver == other.ver and self.build <= other.build
112
+ )
113
+
114
+ def __gt__(self, other: "Version") -> bool:
115
+ return self.ver > other.ver or (
116
+ self.ver == other.ver and self.build > other.build
117
+ )
118
+
119
+ def __ge__(self, other: "Version") -> bool:
120
+ return self.ver > other.ver or (
121
+ self.ver == other.ver and self.build >= other.build
122
+ )
123
+
124
+ # endregion
125
+
126
+
127
+ class Meta:
128
+ def __init__(
129
+ self,
130
+ name: str,
131
+ ver: Version = Version(0, 0, 0),
132
+ release: Release = Release.RELEASE,
133
+ platform: System = System.get_os(),
134
+ arch: Arch = Arch.get_arch(),
135
+ ):
136
+ self.name: str = name
137
+ self.ver: Version = ver
138
+ self.release: Release = release
139
+ self.platform: System = platform
140
+ self.arch: Arch = arch
141
+
142
+ def __str__(self) -> str:
143
+ rt = f"{self.name}"
144
+ if self.ver != Version(0, 0, 0):
145
+ rt += f"-{str(self.ver)}"
146
+ if self.release and self.release != MISSING:
147
+ rt += f"-r{self.release.value}"
148
+ if self.platform != System.Other and self.platform != MISSING:
149
+ rt += f"-p{self.platform.value}"
150
+ if self.arch != Arch.Other and self.arch != MISSING:
151
+ rt += f"-a_{self.arch.value}"
152
+ return rt
153
+
154
+ def __repr__(self):
155
+ return self.__str__()
156
+
157
+ @classmethod
158
+ def dump(cls, mate_str) -> str:
159
+ split = mate_str.split("-")
160
+ lt = list([split[0], MISSING, MISSING, MISSING, MISSING])
161
+ for_map = {
162
+ "v": [1, Version.from_str],
163
+ "r": [2, Release.from_str],
164
+ "p": [3, System.get_os],
165
+ "a": [4, Arch.get_arch],
166
+ }
167
+
168
+ for s in split[1:]:
169
+ if s[0] in for_map:
170
+ lt[for_map[s[0]][0]] = for_map[s[0]][1](s[1:])
171
+
172
+ return cls(*lt)
@@ -0,0 +1,23 @@
1
+
2
+
3
+ def lazy_load(func, *args, **kwargs):
4
+
5
+ class LazyLoad:
6
+ def __init__(self, func, *args, **kwargs):
7
+ self.func = func
8
+ self.result = None
9
+ self.has_run = False
10
+ self.args = args
11
+ self.kwargs = kwargs
12
+
13
+ def __call__(self):
14
+ if not self.has_run:
15
+ self.result = self.func(*self.args, **self.kwargs)
16
+ self.has_run = True
17
+ return self.result
18
+
19
+ def __getattr__(self, name):
20
+ obj = self.__call__()
21
+ return getattr(obj, name)
22
+
23
+ return LazyLoad(func, *args, **kwargs)
File without changes
@@ -0,0 +1,32 @@
1
+ """
2
+ File IO module
3
+ """
4
+
5
+ from os import path, makedirs
6
+ from pathlib import Path
7
+ from typing import NoReturn
8
+
9
+
10
+ def get_dir() -> tuple: ...
11
+
12
+
13
+ def mkdir(file_path: str) -> NoReturn:
14
+ """
15
+ make log file dirs
16
+
17
+ Args:
18
+ file_path (str): file path
19
+ """
20
+
21
+ dir_path = Path(file_path).parent
22
+ if not path.isdir(dir_path):
23
+ try:
24
+ makedirs(dir_path)
25
+ except Exception: # pylint: disable=broad-exception-caught
26
+ raise
27
+
28
+
29
+ def try_open(): ...
30
+
31
+
32
+ def try_read(): ...
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+
2
+
File without changes
@@ -0,0 +1,54 @@
1
+ import platform
2
+ from enum import Enum
3
+ from functools import lru_cache
4
+
5
+
6
+ class System(Enum):
7
+ Other = "other"
8
+ AIX = "aix"
9
+ Linux = "linux"
10
+ Win32 = "win32"
11
+ Cygwin = "cygwin"
12
+ macOS = "darwin"
13
+ FreeBSD = "freebsd"
14
+
15
+ @classmethod
16
+ @lru_cache(1)
17
+ def get_os(cls, os_str: str = platform.system()) -> "System":
18
+ if os_str == "win32":
19
+ return cls.Win32
20
+ if os_str == "linux":
21
+ return cls.Linux
22
+ if os_str == "darwin":
23
+ return cls.macOS
24
+ if os_str == "aix":
25
+ return cls.AIX
26
+ if os_str == "cygwin":
27
+ return cls.Cygwin
28
+ if os_str.startswith("freebsd"):
29
+ return cls.FreeBSD
30
+ return cls.Other
31
+
32
+
33
+ class Arch(Enum):
34
+ x86 = "i386"
35
+ x64 = "amd64"
36
+ ARM = "arm"
37
+ ARM64 = "arm64"
38
+ Other = "other"
39
+
40
+ @classmethod
41
+ @lru_cache(1)
42
+ def get_arch(cls, arch_str: str = platform.machine()) -> "Arch":
43
+ arch_str = arch_str.lower().replace("_", "")
44
+ if arch_str == "amd64":
45
+ return cls.x64
46
+ if arch_str == "i386":
47
+ return cls.x86
48
+ if arch_str == "arm":
49
+ return cls.ARM
50
+ if arch_str == "arm64":
51
+ return cls.ARM64
52
+ return cls.Other
53
+
54
+ env_os = System.get_os()