lib-not-dr/README.md

118 lines
2.5 KiB
Markdown
Raw Normal View History

2023-06-10 00:23:46 +08:00
# lib-not-dr
2023-06-24 21:01:09 +08:00
A python lib came from [Difficult Rocket](https://github.com/shenjackyuanjie/Difficult-Rocket) development
一个在 [Difficult Rocket](https://github.com/shenjackyuanjie/Difficult-Rocket) 开发中 分离出来的 python 库
## Information/信息
2023-11-25 16:21:01 +08:00
- Version / 版本: 0.2.0-beta.3
2023-11-18 23:42:10 +08:00
- Author / 作者: shenjackyuanjie <3695888@qq.com>
2023-06-24 21:01:09 +08:00
> [shenjackyuanjie](https://github.com/shenjackyuanjie)
> [更新日志|Change Log](docs/change_log.md)
2023-06-24 21:01:09 +08:00
### License/许可证
[MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/)
## 安装/Install
```bash title="install.sh"
2023-06-24 21:01:09 +08:00
pip install lib-not-dr
```
## 使用/Usage
### Logger
> WIP
> 等待 0.2.0
```python title="logger.py"
from lib_not_dr.logger.logger import Logger
logger = Logger.get_logger_by_name("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
> WIP
> 等待 0.2.0
```toml title="pyproject.toml"
[tool.lndl.nuitka]
main = "main.py"
# --main=main.py
2023-11-25 16:21:01 +08:00
standalone = true
onefile = false
```
2023-11-25 16:21:01 +08:00
```bash
lndl-nuitka .
lndl-nuitka . -- --onefile
# add --onefile to nuitka
```
2023-06-24 21:01:09 +08:00
### Nuitka Compiler Helper
2023-07-08 11:25:26 +08:00
> simple example
> 简单示例
```python title="simple_nuitka.py"
2023-06-24 21:01:09 +08:00
import subprocess
2023-07-11 14:24:33 +08:00
from pathlib import Path
from lib_not_dr.nuitka.compile import CompilerHelper
2023-06-24 21:01:09 +08:00
2023-07-11 14:24:33 +08:00
compiler = CompilerHelper(src_file = Path("main.py"))
2023-06-24 21:01:09 +08:00
print(compiler)
subprocess.run(compiler.gen_subprocess_cmd())
```
2023-07-08 11:25:26 +08:00
> more complex example
> 复杂示例
```python title="complex_nuitka.py"
2023-07-08 11:25:26 +08:00
import sys
import subprocess
2023-07-11 14:24:33 +08:00
from pathlib import Path
from lib_not_dr.nuitka.compile import CompilerHelper
2023-07-08 11:25:26 +08:00
2023-07-11 14:24:33 +08:00
compiler = CompilerHelper(src_file = Path("main.py"), run_after_build=True)
2023-07-08 11:25:26 +08:00
print(compiler)
2023-07-08 11:32:58 +08:00
if '-y' in sys.argv or '--yes' in sys.argv:
do_run = True
elif '-n' in sys.argv or '--no' in sys.argv:
do_run = False
else: # do_run is None
while (do_run := input("compile? [y/n]").lower()) not in ["y", "n", "yes", "no"]:
2023-07-11 00:15:29 +08:00
pass
2023-07-08 11:32:58 +08:00
# 获取用户输入是否编译
# get user confirmation to compile or not
do_run = True if do_run[0] == "y" else False
if do_run:
subprocess.run(compiler.gen_subprocess_cmd())
2023-07-08 11:25:26 +08:00
```