Skip to content

Commit

Permalink
修改CI
Browse files Browse the repository at this point in the history
  • Loading branch information
northgreen committed Jul 2, 2024
1 parent 4f6cc20 commit 6d7b77b
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 14 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/test_linux.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: test_linux
on:
workflow_dispatch:
pull_request:
push:

jobs:
test_linux:
strategy:
fail-fast: false
matrix:
python-version: [ "3.9", "3.10", "3.11","3.12" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: "dev"

- name: install python
uses: actions/setup-python@v4.7.1
with:
python-version: ${{ matrix.python-version }}

- name: install depends
run: |
python -m pip install --upgrade pip
pip install -r ./ictye-live-dm/requirements.txt
pip install ./ictye-live-dm/
pip install pytest pytest-cov pytest-asyncio pytest-aiohttp PyQt5
- name: test
run: |
pytest ./ictye-live-dm --junitxml=junit/test-results-${{ matrix.python-version }}.xml --cov --cov-report=html
- name: upload_results
uses: actions/upload-artifact@v3
with:
name: pytest-results-${{ matrix.python-version }}
path: |
junit/test-results-${{ matrix.python-version }}.xml
htmlcov/*
# Use always() to always run this step to publish test results when there are test failures
if: ${{ always() }}


2 changes: 1 addition & 1 deletion .run/gen GUI.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="gen GUI" type="ShConfigurationType" activateToolWindowBeforeRun="false">
<configuration default="false" name="Gen GUI" type="ShConfigurationType" activateToolWindowBeforeRun="false">
<option name="SCRIPT_TEXT" value="pyuic5 .\main.ui -o ..\GUI\Ui_MainWindow.py" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
Expand Down
76 changes: 63 additions & 13 deletions ictye-live-dm/src/ictye_live_dm/depends/config_registrar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from typing import TypeVar, Generic, Union

T = TypeVar('T')
from typing import Union


def __get_type_default__(type_: type):
Expand All @@ -21,12 +19,15 @@ def __get_type_default__(type_: type):
raise ValueError(f"Unsupported type: {type_},may be you can use ConfigTree to build a tree")


class ConfigKey(Generic[T]):
class ConfigKey:
"""
A config key that can be registered to the ConfigRegistrar.
"""

def __init__(self, default: T = None, optional: bool = False, option: list[T] = None, value: T = None):
def __init__(self, default: Union[str, bool, int, float] = None,
optional: bool = False,
option: list[Union[str, bool, int, float]] = None,
value: Union[str, bool, int, float] = None):
self.__default = __get_type_default__(type(value)) if default is None else default
self.__optional = optional
self.__option = option if option else [True, False] if isinstance(default, bool) else None
Expand Down Expand Up @@ -74,6 +75,34 @@ def __repr__(self):
return (f"ConfigKey(dfault={self.__default}, is optional={self.__optional}, options={self.__option}, "
f"value={self.__value})")

def __int__(self):
value = self.get()
if isinstance(value, int):
return value
else:
raise TypeError(f"Cannot convert {value} to int")

def __float__(self):
value = self.get()
if isinstance(value, float):
return value
else:
raise TypeError(f"Cannot convert {value} to float")

def __bool__(self):
value = self.get()
if isinstance(value, bool):
return value
else:
raise TypeError(f"Cannot convert {value} to bool")

def __str__(self):
value = self.get()
if isinstance(value, str):
return value
else:
raise TypeError(f"Cannot convert {value} to str")

def merge(self, other):
if self.__default is None:
self.__default = other.get_default()
Expand All @@ -98,7 +127,8 @@ def __init__(self,
build_dict: dict = None, # 字典結構的子節點
build_list: list = None, # 列表結構的子節點
build_with_default: bool = False, # 是否使用默認值構造子節點
allow=None,
allow: list = None,
tree_lock=False,
*args: any,
**kwargs: any):
"""
Expand All @@ -108,8 +138,9 @@ def __init__(self,
:param args: 列表結構的子節點
:param kwargs: 字典結構的子節點
"""
if allow is None:
allow = [any]

self.__allow = allow
self.__tree_lock = tree_lock
self.__value: ConfigKey = value
self.__content: dict[str, Union[ConfigKey, ConfigTree]] = {}
self.__is_list: bool = is_list
Expand All @@ -120,7 +151,7 @@ def __init__(self,
else:
self.__build_dict(kwargs)

if not build_dict is None or not build_list is None:
if build_dict is not None or build_list is not None:
if self.__is_list:
self.__build_list([*args, *build_list], default=build_with_default)
else:
Expand All @@ -130,6 +161,7 @@ def __build_list(self, value, default=False):
if not self.__is_list:
raise TypeError("This is not a list")
for i in value:

if default:
if isinstance(i, ConfigKey):
self.__list_content.append(i)
Expand Down Expand Up @@ -202,10 +234,18 @@ def get_value(self) -> ConfigKey:
def read_value(self) -> Union[str, int, float, bool]:
return self.__value.get()

def __setitem__(self, key, value):
def __setitem__(self, key: Union[str, int],
value: Union[ConfigKey, "ConfigTree"]):
self.set(key, value)

def set(self, key: T, value: T):
def set(self, key: Union[str, int],
value: Union[ConfigKey, "ConfigTree"]):
"""
設置值
@param key: 鍵名
@param value: 值
@return: None
"""
if self.__is_list:
self.__list_content[int(key)] = value
else:
Expand All @@ -217,6 +257,9 @@ def __iter__(self):
else:
return iter(self.__content)

def __str__(self):
return str(self.__value)

def __repr__(self):
return (f"ConfigTree(value= {self.__value}, is_list= {self.__is_list},"
f"content= {self.__content if not self.__is_list else self.__list_content})")
Expand Down Expand Up @@ -251,9 +294,16 @@ def is_dict(self) -> bool:
def is_list(self) -> bool:
return self.__is_list

def merage(self) -> None:
def to_dict(self) -> dict:
# TODO
...
if self.__is_list:
raise TypeError("Cannot convert list to dict")
else:
return self.__content

def merage(self, other: "ConfigTree") -> "ConfigTree":
pass

def __add__(self, other):
if isinstance(other, ConfigTree):
if self.is_list() and other.is_list():
Expand Down

0 comments on commit 6d7b77b

Please sign in to comment.