Compare commits

..

6 Commits

10 changed files with 23 additions and 522 deletions

View File

@ -6,7 +6,7 @@ A python lib came from [Difficult Rocket](https://github.com/shenjackyuanjie/Dif
## Information/信息
- Version / 版本: 0.3.14
- Version / 版本: 0.3.18
- Author / 作者: shenjackyuanjie <3695888@qq.com>
[shenjackyuanjie](https://github.com/shenjackyuanjie)
@ -17,89 +17,6 @@ A python lib came from [Difficult Rocket](https://github.com/shenjackyuanjie/Dif
[MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/)
## 安装/Install
## 剩余文档已经迁移到 [dr.shenjack.top](https://dr.shenjack.top/main/lib-not-dr/)
```bash title="install.sh"
pip install lib-not-dr
pip install lib-not-dr[nuitka]
# install with nuitka support
# 安装支持 nuitka 的版本
```
## 使用/Usage
### Logger
> WIP
> 等待 0.4.0
```python title="logger.py"
from lib_not_dr import loggers
logger = loggers.get_logger("test")
logger.fine('Hello World!')
logger.debug('Hello World!')
logger.trace('Hello tracing!')
logger.info('Hello World!') # info!
logger.warn('warnnnnnnn')
logger.error('Hello World!')
logger.fatal('good bye world')
# tag
logger.info('this message if from tag', tag='test')
logger.debug('this debug log if from admin', tag='admin')
# end
logger.debug('and this message ends with none', end=' ')
logger.trace('so this message will be in the same line', tag='same line!')
```
### Nuitka pyproject paser
> `pyproject.toml` 内的配置
>
> Config in `pyproject.toml`
前往 [example/nuitka](/example/nuitka) 查看更多例子
```toml title="pyproject.toml"
[tool.lndl.nuitka.cli]
main = "main.py"
# --main=main.py
standalone = true
onefile = false
[tool.lndl.nuitka]
script = "xxx.py"
```
> 通过 `lndl_nuitka` 命令行工具使用
>
> Use with `lndl_nuitka` command line tool
> 建议使用 `pip install lib-not-dr[nuitka]` 安装 lib-not-dr
```bash
lndl_nuitka .
lndl_nuitka . -- --onefile
# add --onefile to nuitka
lndl_nuitka . -y
# run without confirmation
lndl_nuitka . -n
# do not run
```
> 通过 `lib_not_dr.nuitka.reader` 模块使用
>
> Use with `lib_not_dr.nuitka.reader`
```python
from tomli import loads
from lib_not_dr.nuitka.reader import main, run_nuitka
pyproject_toml = loads(open("pyproject.toml", "r").read())
nuitka_config = pyproject_toml["tool"]["lndl"]["nuitka"]
nuitka_config["product_version"] = "0.1.0"
command = main(nuitka_config)
run_nuitka(command)
```
## The rest of the documentation have been moved to [dr.shenjack.top](https://dr.shenjack.top/main/lib-not-dr/)

View File

@ -1,95 +0,0 @@
# lndl 0.3
## 0.3.14
- lndl-nuitka
- 言出法随(
- 为 arg_parse.py 添加了一些类型注释相关的内容
- 好好好, 这就更新
## 0.3.13
- lndl-nuitka
- 大概是最后一次 0.3 的更新了
- 修复了带有 `__spilt__` 的时候参数错误
- 应该是使用 `arg_value` 判断类型
- 但实际上用了 `value`
- 把 `is True` 改成了双层判断
- `isinstance(value, bool)`
- `if value:`
## 0.3.12
- `Options`
- 又回来维护了哈
- 添加了 `_check_filled` 预定义选项
- 如果为 `True`
- 会在 `Options` 初始化时检查是否有未填写的选项
- 如果有, 则会抛出 `OptionNotFilled`
- 添加 `OptionNotFilled` 异常
- 用于在 `Options` 初始化时检查是否有未填写的选项
## 0.3.11
- 修复了 `Logger` 任意等级消息 `flush` 默认为 `True`
- 现在为 `None`
## 0.3.10
- 修复了 `LogMessage` 在传入非字符串时会因为 `str.join` 只支持 `str` 类型报错
## 0.3.9
- 改进了 `lndl-nuitka` 在没有找到 toml 库的时候的报错
- 这下看的懂了吧 ?
## 0.3.8
- 为 `logger` 添加了 `default_tag` 属性
- 详情请查看 `0.4` 文档
## 0.3.7
- lndl-nuitka 现在不会再输出那一堆 debug 信息了
### CompilerHelper
- 修复了如果未定义 `icon_path` 时 会报错的问题
- 这大概是最后一次修复了
- 0.4 会删除这一部分
## 0.3.6
- logger 的 `info` 更白了
## 0.3.5
- 向后移植了一些 `0.4` 的 logger 改动
- 其实就是懒得发 0.4, 先测试一下再说
## 0.3.2/3/4
仅用于测试新的 `pdm publish` hook
## 0.3.1
将 Python 包的 `license` 改为 `MPL-2.0`
## 0.3.0
> logger 继续后延
### lndl-nuitka
- [x] 修改配置路径
- 从 `[tool.lndl.nuitka]` 变为 `[tool.lndl.nuitka.cli]`
- [x] 添加新配置
- 添加 `[tool.lndl.nuitka.script]`
- 用于项目动态修改 nuitka 脚本中的信息
- 例如 `file-version` `product-version`
- 重构了一部分解析逻辑
- 现在配置路径位于 `[tool.lndl.nuitka.cli]`
- 可以添加脚本用于动态解析依赖
- `[tool.lndl.nuitka]`
- `script = "script.py"`

View File

@ -1,45 +0,0 @@
# lndl 0.4.0 (draft)
## Logger
- [x] 完成配置解析
- [x] 支持读取配置之后自动应用
- [ ] 达到可用级别
- `Outstream`
- `FileCacheOutputStream`
- 现在如果输入的文件名包含 `{time}`
- 会自动替换为 `time.strftime("%Y-%m-%d_%H-%M-%S")`
- 修复了一些之前没有发现的问题
- `config`
- 添加了 `get_logger_from_old`
- 用于从现有 logger 中获取一个新的 logger
- 现在 `info` 级别的默认颜色更白了 (255, 255, 255)
- `Logger`
- 添加了 `default_tag` 属性 (已经在 `0.3.8` 中添加)
- 用于设置默认的 tag
- 默认为 `None` (无默认 tag)
- 可以通过 `logger.tag = "tag"` 来设置
- 或者 `logger.set_tag("tag")` 来设置
- 可以链式调用
- 类似
- `self.logger = config.get_logger("root").set_tag("tag")`
- 也可以通过 `logger.tag = None` 来取消默认 tag
- 或者 `logger.clear_tag()` 来清除默认 tag
- 添加了 `get_config` 函数 (已经在 `0.3.0` 中添加)
- 用于获取全局配置
- 我也不确定有啥用捏
- 添加了 `read_config` 函数 (已经在 `0.3.0` 中添加)
- 用于向指定 `ConfigStorage`/全局 `ConfigStorage` 实例中添加配置
- 添加了 `get_logger` 函数 (已经在 `0.3.0` 中添加)
- 用于从指定 `ConfigStorage`/全局 `ConfigStorage` 实例中获取指定名称的 `Logger` 实例
- 添加了 `clone_logger` 函数 (已经在 `0.3.0` 中添加)
- 用于克隆一个新的配置相同的 `Logger` 实例
- 修复了 `Logger` 任意等级消息 `flush` 默认为 `True` (已经在 `0.3.11` 中修复)
- 现在为 `None`
- 将 `logger` 模块重命名为 `loggers`
## Nuitka Compiler Helper
- [ ] 移除 CompilerHelper 和他的附属部分

View File

@ -1,184 +0,0 @@
# lndl 老版本的更新日志
## 0.2.3
### lndl-nuitka
- 现在如果没有找到 toml 解析器
- 提示安装库 的信息里不再带有 `tomllib`
- 标准库也想装 ? 🤣
## 0.2.2
### Logger
- `MainFormatter`
- `_trace_format`
- 通过不需要获取绝对路径时直接使用获取到的路径减少用时
- `LogMessage`
- 不再继承 `Options`
- `Options` 的初始化太慢了
- 终于是开始扣时间了
- `ConfigStorage`
- 完善了功能 (虽然还是 WIP)
## 0.2.1
> logger 继续后延
### Fix
- `Logger`
- `MainFormatter`
- 修复了会导致 `ColorFormatter` 崩溃的问题
## 0.2.0
> 内容和 0.2.0-rc.10 相同
## 0.2.0-rc.10
### lndl-nuitka
- 将 `lndl-nuitka` 中的 `subprocess.run` 方法修改为
- Linux / MacOS: `subprocess.run(shell=False)`
- Windows: `subprocess.run(shell=True)`
## 0.2.0-rc.9
### lndl-nuitka
- 将运行方法修改为 `subprocess.run(shell=False)`
## 0.2.0-rc.4
### lndl-nuitka
- 在 `lndl-nuitka` 中使用新添加的 `subprocess_to_bash` 函数展示命令
- 保证展示的命令可以直接运行
> 真的就是在刷版本号啊
## 0.2.0-rc.3
### lndl-nuitka
- 在 `arg_parser` 中添加了函数 `subprocess_to_bash`
- 用于将 `arg_parser` 中的参数转换为 `bash` 命令
- 理论上可以直接运行
## 0.2.0-rc.1/2
### lndl-nuitka
- 修复了一些细节问题 (反正我懒得统计具体内容了)
- 现在不会在没有给定附加参数的时候报 `invalid args:`
- 似乎没有别的细节了?
## 0.2.0-beta.2
### lndl-nuitka
- 可以使用 `--` 单独添加参数了
- 例如 `lndl-nuitka -- --onefile`
- 会将 `--onefile` 添加到 `nuitka` 的参数中
## 0.2.0-beta.0/1
### 重构
- 重构了文件目录结构
- 保证 `setuptools` 可以正常工作
### lndl-nuitka
- 添加了脚本 `lndl-nuitka`
- 用于解析 `pyproject.toml` 中的 `tool.lndl.nuitka` 部分
## 0.2.0-alpha0
### Logger
- 添加了 Logger (虽说 0.1.8 就有了)
- 目前入口点位于 `lib_not_dr.logger.logger.Logger`
## 0.1.8
- 为 `types.Options` 添加了 `_check_option` 选项
- 为 `True` 时 会检查参数是否合法 (在类属性中已经定义了)
### Logger
- WIP (wait for 0.2.0)
## 0.1.7
- 修复了 `CompilerHelper` 中的问题
- 重复添加 `--output-dir` 参数
- 参数喜加 2
- `--onefile`
- `--onefile-tempdir-spec`
## 0.1.6
- 优化了 `CompilerHelper` 的一些周围实现
- 参数喜加一
- `--report`
## 0.1.5
- 修复了 `types.Options` 中的 `as_markdown` 实现细节
- 现在不会长度溢出了
## 0.1.4
- 更改了 `types.Options` 中的 `as_markdown` 实现方式
- 原来的实现会导致 如果终端长度 > 所需长度 时, 循环一直进行
- 同时现在分配长度是均分
## 0.1.3
- 修改了 `README.md` 内的版本号
## 0.1.2
- 改进了 `types.Options`
- 现在 `as_markdown` 如果没有指定最长长度 会自动适配输出所用终端的宽度
- 同时如果指定最大长度, 也会更灵活的适配
- 补全了一些文档
## 0.1.1
- 为 `CompilerHelper` 添加了 `remove_output` 的选项
- 用于删除编译后的过程文件
## 0.1.0
- 添加了一些文档
- `CompilerHelper`
- 添加了 `run_after_build` 参数
- 用于在编译完成后执行程序
- 添加了 `compat_nuitka_version` 参数
- 用于验证 nuitka 版本是否兼容
## 0.0.4
添加了项目的 url
## 0.0.3
继续添加了一些文档
## 0.0.2
添加了一些文档
## 0.0.1
- 添加了
- `nuitka.compile`
- `CompilerHelper`
- `types.options`
- `Options`
- `types.version`
- `Version`

View File

@ -1,7 +0,0 @@
# lndl 更新日志
## [0.4](/docs/change_logs/0-4.md)
## [0.3](/docs/change_logs/0-3.md)
## [old](/docs/change_logs/old.md)

View File

@ -1,88 +0,0 @@
# Command parser
> By shenjackyuanjie And MSDNicrosoft and Harvey Huskey
## Usage
```python
from typing import Callable, Self, Optional, List
class Literal:
def __init__(self, name: str):
self.name = name
self.sub = []
self._tip = ''
def __call__(self, *nodes) -> Self:
self.sub += nodes
return self
def run(self, func: Callable[[List[str]], None]) -> Self:
return self
def tip(self, tip: str) -> Self:
return self
def arg(self, parse_func: Callable[[str], Optional[type]]) -> Self:
return self
def error(self, callback: Callable[[str], None]) -> Self:
return self
builder = Literal('test1')(
Literal('a')
.run(lambda x: print(x)),
Literal('b')
.tip('this is b')
.run(lambda x: print(x))(
Literal('c')
.run(lambda x: print(x)),
Literal('d')
.run(lambda x: print(x)),
),
)
```
build
- test
- main
- arg:text
- go
- arg:int
- run
- command: 主节点
- literal: 字面量节点
## 设计思路
```rust
pub enum ArgumentType {
String(String),
Int(i128),
Bool(bool),
Float(f64),
}
pub type CallBackFunc = Fn(Vec<(String, ArgumentType)>) -> bool;
pub enum CallBack {
Fn(CallBackFunc),
Message(String),
}
pub trait Command {
fn new(nodes: Vec<Command>) -> Self;
// fn parse(&self, input: String) -> Result<Command, Error>;
fn literal(&self, name: String, then: Vec<Command>) -> &self;
fn argument(&self, name: String, shortcut: List<String>, optional: Option<bool>) -> &self;
fn flag(&self, name: String, shortcut: List<String>, ) -> &self;
fn error(&self, ret: CallBack) -> &self;
fn run(&self, ret: CallBack) -> &self;
fn tip(&self, tip: String) -> &self;
fn to_doc(&self) -> String;
fn exec(&self) -> Option;
}
```

View File

@ -9,7 +9,7 @@ from typing import TYPE_CHECKING
if TYPE_CHECKING:
from lib_not_dr import loggers, nuitka, types, command
_version_ = "0.3.14"
_version_ = "0.3.18"
# fmt: off
__all__ = [

View File

@ -62,10 +62,10 @@ TOML_READERS = (
# try tomllib first
"toml", # slow pure python toml reader
"rtoml", # rust based toml reader
"tomlkit", # pure python toml reader
"tomli", # pure python toml reader
"pytomlpp", # cpp based toml reader
"qtoml", # pure python toml reader, but faster than toml
"tomlkit", # pure python toml reader with style
)

View File

@ -183,8 +183,9 @@ def gen_subprocess_args(
# 处理混杂的情况
for item in value:
cmd_list += parse_value(name, item)
continue
warn(f"invalid config {name}:{value}")
continue
else:
warn(f"invalid config {name}:{value} {type(value)}")
return cmd_list

View File

@ -112,10 +112,6 @@ class Options:
setattr(self, option, value)
if self._check_filled:
miss_list.remove(option)
if self._check_filled and miss_list:
raise OptionNotFilled(
f"option: {miss_list} is not filled in {self.name}"
)
run_load_file = True
if hasattr(self, "init"):
run_load_file = self.init(**kwargs) # 默认 False/None
@ -125,6 +121,10 @@ class Options:
self.load_file()
except Exception:
traceback.print_exc()
if self._check_filled and miss_list:
raise OptionNotFilled(
f"option: {miss_list} is not filled in {self.name}"
)
self.flush_option()
def __str__(self):
@ -140,12 +140,12 @@ class Options:
if TYPE_CHECKING:
_options: Dict[str, Union[Callable, object]] = {}
def init(self, **kwargs) -> bool:
def init(self, **kwargs) -> bool: # type: ignore
"""如果子类定义了这个函数,则会在 __init__ 之后调用这个函数
返回值为 True 则不会调用 load_file 函数
"""
def load_file(self) -> bool:
def load_file(self) -> bool: # type: ignore
"""如果子类定义了这个函数,则会在 __init__ 和 init 之后再调用这个函数
请注意这个函数请尽量使用 try 包裹住可能出现错误的部分
@ -159,8 +159,9 @@ class Options:
"""
values = {}
for ann in self.__annotations__: # 获取类型注释
values[ann] = getattr(self, ann, None)
if values[ann] is None:
try:
values[ann] = getattr(self, ann)
except AttributeError:
values[ann] = self.__annotations__[ann]
if not hasattr(self, "_options"):
@ -238,7 +239,7 @@ class Options:
max_len_value = max(max_len_value, len(str(value)))
max_len_value_t = max(max_len_value_t, len(str(value_t)))
option_list.append([key, value, value_t])
return [option_list, max_len_key, max_len_value, max_len_value_t] # noqa
return [option_list, max_len_key, max_len_value, max_len_value_t] # type: ignore
def as_markdown(self, longest: Optional[int] = None) -> str:
"""
@ -296,14 +297,15 @@ class Options:
# 所以可以直接修改 string
for v in value[0]:
if len(str(v[0])) > option_len:
v[0] = f"{str(v[0])[:value_len - 3]}..."
v[0] = f"{str(v[0])[:value_len - 3]}..." # type: ignore
if len(str(v[1])) > value_len:
v[1] = f"{str(v[1])[:value_len - 3]}..."
v[1] = f"{str(v[1])[:value_len - 3]}..." # type: ignore
if len(str(v[2])) > value_type_len:
v[2] = f"{str(v[2])[:value_len - 3]}.."
v[2] = f"{str(v[2])[:value_len - 3]}.." # type: ignore
cache.write(
f"| Option{' ' * (option_len - 3)}| Value{' ' * (value_len - 2)}| Value Type{' ' * (value_type_len - 7)}|\n"
f"| Option{' ' * (option_len - 3)}| Value{' ' * (value_len - 2)}"
f"| Value Type{' ' * (value_type_len - 7)}|\n"
)
cache.write(
f'|:{"-" * (option_len + 3)}|:{"-" * (value_len + 3)}|:{"-" * (value_type_len + 3)}|\n'