wexample-wex-core 6.0.1__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.
- wexample-wex-core-6.0.1/PKG-INFO +17 -0
- wexample-wex-core-6.0.1/README.md +4 -0
- wexample-wex-core-6.0.1/setup.cfg +4 -0
- wexample-wex-core-6.0.1/setup.py +23 -0
- wexample-wex-core-6.0.1/wexample_wex_core/__init__.py +0 -0
- wexample-wex-core-6.0.1/wexample_wex_core/const/__init__.py +0 -0
- wexample-wex-core-6.0.1/wexample_wex_core/const/globals.py +2 -0
- wexample-wex-core-6.0.1/wexample_wex_core/const/types.py +7 -0
- wexample-wex-core-6.0.1/wexample_wex_core/helpers/__init__.py +0 -0
- wexample-wex-core-6.0.1/wexample_wex_core/helpers/click_helper.py +118 -0
- wexample-wex-core-6.0.1/wexample_wex_core/utils/__init__.py +0 -0
- wexample-wex-core-6.0.1/wexample_wex_core/utils/abstract_kernel_child.py +14 -0
- wexample-wex-core-6.0.1/wexample_wex_core/utils/kernel.py +32 -0
- wexample-wex-core-6.0.1/wexample_wex_core/utils/workdir.py +25 -0
- wexample-wex-core-6.0.1/wexample_wex_core.egg-info/PKG-INFO +17 -0
- wexample-wex-core-6.0.1/wexample_wex_core.egg-info/SOURCES.txt +17 -0
- wexample-wex-core-6.0.1/wexample_wex_core.egg-info/dependency_links.txt +1 -0
- wexample-wex-core-6.0.1/wexample_wex_core.egg-info/requires.txt +2 -0
- wexample-wex-core-6.0.1/wexample_wex_core.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: wexample-wex-core
|
|
3
|
+
Version: 6.0.1
|
|
4
|
+
Summary: Wex core
|
|
5
|
+
Home-page: https://github.com/wexample/wexample-wex-core
|
|
6
|
+
Author: weeger
|
|
7
|
+
Author-email: contact@wexample.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# Wex core toolkit
|
|
15
|
+
|
|
16
|
+
To use as python package.
|
|
17
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name='wexample-wex-core',
|
|
5
|
+
version=open('version.txt').read().strip(),
|
|
6
|
+
author='weeger',
|
|
7
|
+
author_email='contact@wexample.com',
|
|
8
|
+
description='Wex core',
|
|
9
|
+
long_description=open('README.md').read(),
|
|
10
|
+
long_description_content_type='text/markdown',
|
|
11
|
+
url='https://github.com/wexample/wexample-wex-core',
|
|
12
|
+
packages=find_packages(),
|
|
13
|
+
classifiers=[
|
|
14
|
+
'Programming Language :: Python :: 3',
|
|
15
|
+
'License :: OSI Approved :: MIT License',
|
|
16
|
+
'Operating System :: OS Independent',
|
|
17
|
+
],
|
|
18
|
+
install_requires=[
|
|
19
|
+
'click',
|
|
20
|
+
'pydantic',
|
|
21
|
+
],
|
|
22
|
+
python_requires='>=3.6',
|
|
23
|
+
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
from typing import Any, Dict, List
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
from click.core import Command
|
|
5
|
+
from click.types import BoolParamType
|
|
6
|
+
from wexample_helpers.helpers.args_helper import args_convert_dict_to_snake_dict
|
|
7
|
+
from wexample_helpers.helpers.string_helper import string_to_kebab_case
|
|
8
|
+
|
|
9
|
+
from wexample_wex_core.const.types import (
|
|
10
|
+
CoreCommandArgsDict,
|
|
11
|
+
CoreCommandArgsList,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def click_args_convert_dict_to_long_names_dict(
|
|
16
|
+
function: Command, args: CoreCommandArgsDict
|
|
17
|
+
) -> Dict[str, Any]:
|
|
18
|
+
short_names = {}
|
|
19
|
+
|
|
20
|
+
for param in function.params:
|
|
21
|
+
for opt in param.opts:
|
|
22
|
+
# This is a short name
|
|
23
|
+
if opt.startswith("-") and opt[1:2] != "-":
|
|
24
|
+
if param.name:
|
|
25
|
+
short_names[opt[1:]] = string_to_kebab_case(param.name)
|
|
26
|
+
|
|
27
|
+
# Transform short named args to long named args.
|
|
28
|
+
args_long = {}
|
|
29
|
+
for name in args:
|
|
30
|
+
if name in short_names:
|
|
31
|
+
args_long[short_names[name]] = args[name]
|
|
32
|
+
else:
|
|
33
|
+
args_long[name] = args[name]
|
|
34
|
+
|
|
35
|
+
return args_long
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def click_args_convert_to_dict(function: Command, arg_list: List[str]) -> Dict[str, Any]:
|
|
39
|
+
args_dict: Dict[str, str | bool] = {}
|
|
40
|
+
|
|
41
|
+
param_dict = {
|
|
42
|
+
opt.lstrip("-"): param
|
|
43
|
+
for param in function.params
|
|
44
|
+
if isinstance(param, click.Option)
|
|
45
|
+
for opt in param.opts
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
i = 0
|
|
49
|
+
while i < len(arg_list):
|
|
50
|
+
arg = arg_list[i]
|
|
51
|
+
|
|
52
|
+
if isinstance(arg, str):
|
|
53
|
+
stripped_arg = arg.lstrip("-")
|
|
54
|
+
|
|
55
|
+
# Manage parameters defined in function
|
|
56
|
+
if stripped_arg in param_dict:
|
|
57
|
+
param = param_dict[stripped_arg]
|
|
58
|
+
if isinstance(param.type, BoolParamType) or param.is_flag:
|
|
59
|
+
args_dict[stripped_arg] = True
|
|
60
|
+
i += 1
|
|
61
|
+
else:
|
|
62
|
+
i += 1
|
|
63
|
+
value = arg_list[i]
|
|
64
|
+
args_dict[stripped_arg] = value
|
|
65
|
+
i += 1
|
|
66
|
+
# Manage unknown parameters
|
|
67
|
+
else:
|
|
68
|
+
key = arg.lstrip("-")
|
|
69
|
+
|
|
70
|
+
if len(arg_list) > i + 1 and arg_list[i + 1][0:1] != "-":
|
|
71
|
+
args_dict[key] = arg_list[i + 1]
|
|
72
|
+
i += 1
|
|
73
|
+
else:
|
|
74
|
+
args_dict[key] = True
|
|
75
|
+
|
|
76
|
+
i += 1
|
|
77
|
+
else:
|
|
78
|
+
i += 1
|
|
79
|
+
|
|
80
|
+
return args_dict
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def click_args_convert_dict_to_args(
|
|
84
|
+
function: Command, args: CoreCommandArgsDict
|
|
85
|
+
) -> CoreCommandArgsList:
|
|
86
|
+
"""
|
|
87
|
+
Convert args {"my-arg": "value"} to list ["--my_arg", "value"].
|
|
88
|
+
Any key in `args` that is not found in `function.params` is added to the
|
|
89
|
+
argument list as a key-value pair.
|
|
90
|
+
"""
|
|
91
|
+
arg_list = []
|
|
92
|
+
args_long = click_args_convert_dict_to_long_names_dict(function=function, args=args)
|
|
93
|
+
args_long = args_convert_dict_to_snake_dict(input_dict=args_long)
|
|
94
|
+
|
|
95
|
+
for param in function.params:
|
|
96
|
+
if param.name in args_long:
|
|
97
|
+
if isinstance(param, click.Option):
|
|
98
|
+
param_name_kebab = string_to_kebab_case(param.name)
|
|
99
|
+
|
|
100
|
+
if param.is_flag:
|
|
101
|
+
if args_long[param.name]:
|
|
102
|
+
arg_list.append(f"--{param_name_kebab}")
|
|
103
|
+
# Flag passed to False is just removed
|
|
104
|
+
elif args_long[param.name] is not None:
|
|
105
|
+
arg_list.append(f"--{param_name_kebab}")
|
|
106
|
+
value = args_long[param.name]
|
|
107
|
+
if not isinstance(args_long[param.name], bool):
|
|
108
|
+
value = str(value)
|
|
109
|
+
arg_list.append(value)
|
|
110
|
+
# Append any remaining arguments as key-value pairs
|
|
111
|
+
for key, value in args_long.items():
|
|
112
|
+
if key not in [param.name for param in function.params] and value is not None:
|
|
113
|
+
arg_list.append(f"--{key}")
|
|
114
|
+
if not isinstance(value, bool):
|
|
115
|
+
# Convert to str to allow joining array.
|
|
116
|
+
arg_list.append(str(value))
|
|
117
|
+
|
|
118
|
+
return arg_list
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from wexample_wex_core.utils.kernel import Kernel
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class AbsractKernelChild(BaseModel):
|
|
10
|
+
kernel: "Kernel"
|
|
11
|
+
|
|
12
|
+
def __init__(self, kernel: "Kernel") -> None:
|
|
13
|
+
super().__init__()
|
|
14
|
+
self.kernel = kernel
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
from typing import Dict
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
from wexample_prompt.io_manager import IOManager
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Kernel(BaseModel):
|
|
11
|
+
def __init__(self, entrypoint_path: str) -> None:
|
|
12
|
+
super().__init__()
|
|
13
|
+
self._sys_argv: list[str] = sys.argv.copy()
|
|
14
|
+
|
|
15
|
+
root_path = os.path.dirname(os.path.realpath(entrypoint_path)) + os.sep
|
|
16
|
+
|
|
17
|
+
self._path: Dict[str, str] = {
|
|
18
|
+
"root": root_path,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
self.io = IOManager()
|
|
22
|
+
|
|
23
|
+
def call(self) -> None:
|
|
24
|
+
"""
|
|
25
|
+
Main entrypoint from bash call.
|
|
26
|
+
May never be called by an internal script.
|
|
27
|
+
:return:
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
# No arg found except process id
|
|
31
|
+
if not len(self._sys_argv) > 2:
|
|
32
|
+
return
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from wexample_filestate.const.enums import DiskItemType
|
|
4
|
+
from wexample_filestate.const.types import StateItemConfig
|
|
5
|
+
from wexample_filestate.file_state_manager import FileStateManager
|
|
6
|
+
from wexample_wex_core.const.globals import WORKDIR_SPECIAL_DIR
|
|
7
|
+
from wexample_filestate.const.types_state_items import TargetFileOrDirectory
|
|
8
|
+
from wexample_helpers.const.types import FileStringOrPath
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Workdir(FileStateManager):
|
|
12
|
+
def __init__(self, config: Optional[StateItemConfig], **data):
|
|
13
|
+
if "children" not in config:
|
|
14
|
+
config["children"] = []
|
|
15
|
+
|
|
16
|
+
config["children"].append({
|
|
17
|
+
"name": WORKDIR_SPECIAL_DIR,
|
|
18
|
+
"type": DiskItemType.DIRECTORY,
|
|
19
|
+
"should_exist": True
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
super().__init__(config=config, **data)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
Workdir.model_rebuild()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: wexample-wex-core
|
|
3
|
+
Version: 6.0.1
|
|
4
|
+
Summary: Wex core
|
|
5
|
+
Home-page: https://github.com/wexample/wexample-wex-core
|
|
6
|
+
Author: weeger
|
|
7
|
+
Author-email: contact@wexample.com
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# Wex core toolkit
|
|
15
|
+
|
|
16
|
+
To use as python package.
|
|
17
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
setup.py
|
|
3
|
+
wexample_wex_core/__init__.py
|
|
4
|
+
wexample_wex_core.egg-info/PKG-INFO
|
|
5
|
+
wexample_wex_core.egg-info/SOURCES.txt
|
|
6
|
+
wexample_wex_core.egg-info/dependency_links.txt
|
|
7
|
+
wexample_wex_core.egg-info/requires.txt
|
|
8
|
+
wexample_wex_core.egg-info/top_level.txt
|
|
9
|
+
wexample_wex_core/const/__init__.py
|
|
10
|
+
wexample_wex_core/const/globals.py
|
|
11
|
+
wexample_wex_core/const/types.py
|
|
12
|
+
wexample_wex_core/helpers/__init__.py
|
|
13
|
+
wexample_wex_core/helpers/click_helper.py
|
|
14
|
+
wexample_wex_core/utils/__init__.py
|
|
15
|
+
wexample_wex_core/utils/abstract_kernel_child.py
|
|
16
|
+
wexample_wex_core/utils/kernel.py
|
|
17
|
+
wexample_wex_core/utils/workdir.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
wexample_wex_core
|