update readme
This commit is contained in:
parent
47184633de
commit
55e167d0c1
10
README.md
10
README.md
@ -31,9 +31,10 @@ pip install lib-not-dr
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
import subprocess
|
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)
|
print(compiler)
|
||||||
subprocess.run(compiler.gen_subprocess_cmd())
|
subprocess.run(compiler.gen_subprocess_cmd())
|
||||||
@ -45,9 +46,10 @@ subprocess.run(compiler.gen_subprocess_cmd())
|
|||||||
```python
|
```python
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
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)
|
print(compiler)
|
||||||
|
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
class CallBackDescriptor:
|
class CallBackDescriptor:
|
||||||
def __set_name__(self, owner, name):
|
def __init__(self, name):
|
||||||
self.callback_name = name
|
self.callback_name = name
|
||||||
|
|
||||||
def __set__(self, instance, value):
|
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]
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
from typing import Callable, List, Optional, Union
|
from typing import Callable, List, Optional, Union
|
||||||
|
|
||||||
|
from .descriptor import CallBackDescriptor
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from typing import Self
|
from typing import Self
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -26,6 +29,15 @@ EMPTY_WORDS = re.compile(r"\s", re.I)
|
|||||||
|
|
||||||
|
|
||||||
def check_once(cls, name) -> None:
|
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 hasattr(cls, name):
|
||||||
if getattr(cls, name) is not None:
|
if getattr(cls, name) is not None:
|
||||||
raise AttributeError(f"Attribute '{name}' has been set.")
|
raise AttributeError(f"Attribute '{name}' has been set.")
|
||||||
@ -65,6 +77,10 @@ class Flag:
|
|||||||
|
|
||||||
|
|
||||||
class Literal:
|
class Literal:
|
||||||
|
_tip = CallBackDescriptor("_tip")
|
||||||
|
_func = CallBackDescriptor("_func")
|
||||||
|
_err_callback = CallBackDescriptor("_err_callback")
|
||||||
|
|
||||||
def __init__(self, name: str):
|
def __init__(self, name: str):
|
||||||
self.name: str = name
|
self.name: str = name
|
||||||
self.sub: List[Self] = []
|
self.sub: List[Self] = []
|
||||||
|
Loading…
Reference in New Issue
Block a user