update readme

This commit is contained in:
shenjack 2023-07-11 14:24:33 +08:00
parent 47184633de
commit 55e167d0c1
3 changed files with 30 additions and 6 deletions

View File

@ -31,9 +31,10 @@ pip install lib-not-dr
```python
import subprocess
from lib_not_dr.nuitka import CompilerHelper
from pathlib import Path
from lib_not_dr.nuitka.compile import CompilerHelper
compiler = CompilerHelper("main.py")
compiler = CompilerHelper(src_file = Path("main.py"))
print(compiler)
subprocess.run(compiler.gen_subprocess_cmd())
@ -45,9 +46,10 @@ subprocess.run(compiler.gen_subprocess_cmd())
```python
import sys
import subprocess
from lib_not_dr.nuitka import CompilerHelper
from pathlib import Path
from lib_not_dr.nuitka.compile import CompilerHelper
compiler = CompilerHelper("main.py", run_after_build=True)
compiler = CompilerHelper(src_file = Path("main.py"), run_after_build=True)
print(compiler)

View File

@ -1,7 +1,13 @@
class CallBackDescriptor:
def __set_name__(self, owner, name):
def __init__(self, name):
self.callback_name = name
def __set__(self, instance, value):
if
assert getattr(instance, self.callback_name) is None, f"Attribute '{self.callback_name}' has been set."
instance.__dict__[self.callback_name] = value
def __get__(self, instance, owner):
if instance is None:
return self
else:
return instance.__dict__[self.callback_name]

View File

@ -6,6 +6,9 @@
import re
from typing import Callable, List, Optional, Union
from .descriptor import CallBackDescriptor
try:
from typing import Self
except ImportError:
@ -26,6 +29,15 @@ EMPTY_WORDS = re.compile(r"\s", re.I)
def check_once(cls, name) -> None:
"""
Check whether the attribute has been set.
if so, it will raise exception `AttributeError`.
检查属性是否已经被设置
如果已经被设置将会抛出 `AttributeError` 异常
:param cls: class object
:param name: attribute name
:return: None
"""
if hasattr(cls, name):
if getattr(cls, name) is not None:
raise AttributeError(f"Attribute '{name}' has been set.")
@ -65,6 +77,10 @@ class Flag:
class Literal:
_tip = CallBackDescriptor("_tip")
_func = CallBackDescriptor("_func")
_err_callback = CallBackDescriptor("_err_callback")
def __init__(self, name: str):
self.name: str = name
self.sub: List[Self] = []