This commit is contained in:
shenjack 2023-07-08 11:25:26 +08:00
parent fcff7f5392
commit a71e51ed9c
5 changed files with 51 additions and 5 deletions

View File

@ -6,7 +6,7 @@ A python lib came from [Difficult Rocket](https://github.com/shenjackyuanjie/Dif
## Information/信息
- Version/版本: 0.0.4
- Version/版本: 0.1.0
### Author/作者
@ -26,6 +26,9 @@ pip install lib-not-dr
### Nuitka Compiler Helper
> simple example
> 简单示例
```python
import subprocess
from lib_not_dr.nuitka import CompilerHelper
@ -35,3 +38,26 @@ compiler = CompilerHelper("main.py")
print(compiler)
subprocess.run(compiler.gen_subprocess_cmd())
```
> more complex example
> 复杂示例
```python
import sys
import subprocess
from lib_not_dr.nuitka import CompilerHelper
compiler = CompilerHelper("main.py", run_after_build=True)
print(compiler)
while (do := input("compile? [y/n]").lower()) not in ["y", "n", "yes", "no"]:
# 获取用户输入是否编译
# get user confirmation to compile or not
do = do[0]
```

View File

@ -1,5 +1,14 @@
# Change log / 更新日志
## 0.1.0
- 添加了一些文档
- `CompilerHelper`
- 添加了 `run_after_build` 参数
- 用于在编译完成后执行程序
- 添加了 `compat_nuitka_version` 参数
- 用于验证 nuitka 版本是否兼容
## 0.0.4
添加了项目的 url

View File

@ -4,5 +4,5 @@
# All rights reserved
# -------------------------------
__version__ = '0.0.4'
__version__ = '0.1.0'

View File

@ -6,11 +6,12 @@
# 用于使用 nuitka 构建 DR
import platform
import warnings
import traceback
from pathlib import Path
from typing import List, Tuple, Optional
from lib_not_dr.types import Options, Version
from lib_not_dr.types import Options, Version, VersionRequirement
def _add_cmd(cmd: List[str], string: Optional[str]) -> List[str]:
@ -31,8 +32,10 @@ class CompilerHelper(Options):
src_file: Path
python_cmd: str = 'python'
compat_nuitka_version: VersionRequirement = VersionRequirement("~1.7.1") # STATIC VERSION
# 以下为 nuitka 的参数
# nuitka options below
use_lto: bool = False # --lto=yes (no is faster)
use_clang: bool = True # --clang
use_msvc: bool = True # --msvc=latest
@ -47,6 +50,7 @@ class CompilerHelper(Options):
xml_path: Path = Path('build/compile_data.xml')
download_confirm: bool = True # --assume-yes-for-download
run_after_build: bool = False # --run
company_name: Optional[str] = ''
product_name: Optional[str] = ''
@ -68,6 +72,12 @@ class CompilerHelper(Options):
disable_plugin: List[str] = [] # --disable-plugin=xxx,xxx
def init(self, **kwargs) -> None:
if (compat_version := kwargs.get('compat_nuitka_version')) is not None:
if not self.compat_nuitka_version.accept(compat_version):
warnings.warn(
f"Nuitka version may not compat with {compat_version}\n"
"requirement: {self.compat_nuitka_version}"
)
# 非 windows 平台不使用 msvc
if platform.system() != 'Windows':
self.use_msvc = False
@ -126,6 +136,7 @@ class CompilerHelper(Options):
_add_cmd(cmd_list, '--show-progress' if self.show_progress else None)
_add_cmd(cmd_list, '--show-memory' if self.show_memory else None)
_add_cmd(cmd_list, '--assume-yes-for-download' if self.download_confirm else None)
_add_cmd(cmd_list, '--run' if self.run_after_build else None)
_add_cmd(cmd_list, '--enable-console' if self.enable_console else '--disable-console')
_add_cmd(cmd_list, f'--xml={self.xml_path.absolute()}' if self.save_xml else None)
@ -147,5 +158,5 @@ class CompilerHelper(Options):
if self.include_packages:
cmd_list += [f"--include-package={package}" for package in self.include_packages]
cmd_list.append(f"{self.src_file}")
cmd_list.append(f"--main={self.src_file}")
return cmd_list

View File

@ -1,5 +1,5 @@
[project]
version = "0.0.4"
version = "0.1.0"
name = "lib-not-dr"
description = "A python lib created from Difficult Rocket development"