diff --git a/.build/nuitka.cmd b/.build/nuitka.sh similarity index 88% rename from .build/nuitka.cmd rename to .build/nuitka.sh index 4df5bf9..be6408d 100755 --- a/.build/nuitka.cmd +++ b/.build/nuitka.sh @@ -1 +1 @@ -python3 -m nuitka run.py --mode=onefile --output-dir=./dist --no-deployment-flag=self-execution --output-filename=ddns --remove-output --include-module=dns.dnspod --include-module=dns.alidns --include-module=dns.dnspod_com --include-module=dns.dnscom --include-module=dns.cloudflare --include-module=dns.he --include-module=dns.huaweidns --include-module=dns.callback --product-name=DDNS --file-description="DDNS Client 自动更新域名解析到本机IP" --company-name="New Future" --copyright="https://ddns.newfuture.cc" --windows-icon-from-ico="favicon.ico" --assume-yes-for-downloads --lto=yes --nofollow-import-to=unittest,pydoc --onefile-tempdir-spec="{CACHE_DIR}/{PRODUCT}/{VERSION}" \ No newline at end of file +python3 -m nuitka run.py --mode=onefile --output-dir=./dist --no-deployment-flag=self-execution --output-filename=ddns --remove-output --include-module=dns.dnspod --include-module=dns.alidns --include-module=dns.dnspod_com --include-module=dns.dnscom --include-module=dns.cloudflare --include-module=dns.he --include-module=dns.huaweidns --include-module=dns.callback --product-name=DDNS --file-description="DDNS Client 自动更新域名解析到本机IP" --company-name="New Future" --copyright="https://ddns.newfuture.cc" --windows-icon-from-ico="favicon.ico" --assume-yes-for-downloads --lto=yes --nofollow-import-to=unittest,pydoc --onefile-tempdir-spec="{CACHE_DIR}/{PRODUCT}/{VERSION}" --linux-icon=doc/img/ddns.svg \ No newline at end of file diff --git a/.build/remove_python2.py b/.build/remove_python2.py index 0c1bdda..acebb33 100644 --- a/.build/remove_python2.py +++ b/.build/remove_python2.py @@ -27,11 +27,52 @@ def dedent_imports_with_blank(import_block, try_block, except_block): return ('\n' * try_lines) + imports + ('\n' * except_lines) +def extract_pure_version(version_str): + """ + 提取前4组数字并用点拼接,如 v1.2.3.beta4.5 -> 1.2.3.4 + """ + import re + nums = re.findall(r'\d+', version_str) + return '.'.join(nums[:4]) if nums else "0.0.0" + + +def update_nuitka_version(pyfile): + """ + 读取 __version__ 并替换 nuitka-project 版本号 + """ + with open(pyfile, 'r', encoding='utf-8') as f: + content = f.read() + + # 提取 __version__ 变量 + version_match = re.search(r'__version__\s*=\s*[\'"]([^\'"]+)[\'"]', content) + if not version_match: + print(f'No __version__ found in {pyfile}') + return False + + version_str = version_match.group(1) + pure_version = extract_pure_version(version_str) + + # 替换 nuitka-project 行 + new_content, n = re.subn( + r'(# nuitka-project: --product-version=)[^\n]*', + r'\g<1>' + pure_version, + content + ) + if n > 0: + with open(pyfile, 'w', encoding='utf-8') as f: + f.write(new_content) + print(f'update nuitka-project version: {pure_version} in {pyfile}') + return True + return False + + def main(): """ - 遍历所有py文件并替换兼容导入 + 遍历所有py文件并替换兼容导入,同时更新nuitka版本号 """ changed_files = 0 + # 先处理 run.py 的 nuitka-project 版本号 + update_nuitka_version(os.path.join(ROOT, "run.py")) for dirpath, _, filenames in os.walk(ROOT): for fname in filenames: if fname.endswith('.py'): diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 26b192a..e645ab9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -238,7 +238,7 @@ jobs: && dnf repolist \ && dnf install -y gcc strace patchelf ccache gdb make python3-devel python3-zstandard python3-ordered-set python3 -m pip install nuitka - cd /DDNS && python3 .build/remove_python2.py && .build/nuitka.cmd + cd /DDNS && python3 .build/remove_python2.py && .build/nuitka.sh - run: ./dist/ddns || test -e config.json - run: ./dist/ddns -h diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d357b98..867dd21 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -203,7 +203,7 @@ jobs: && dnf repolist \ && dnf install -y gcc strace patchelf ccache gdb make python3-devel python3-zstandard python3-ordered-set python3 -m pip install nuitka - cd /DDNS && python3 .build/remove_python2.py && .build/nuitka.cmd + cd /DDNS && python3 .build/remove_python2.py && .build/nuitka.sh - run: ./dist/ddns || test -e config.json - run: ./dist/ddns -h diff --git a/run.py b/run.py index 94bda2c..72f284c 100755 --- a/run.py +++ b/run.py @@ -6,10 +6,7 @@ DDNS @modified: rufengsuixing """ -# nuitka-project-if: os.getenv("BUILD_VERSION") is not None: -# nuitka-project: --product-version=${BUILD_VERSION} -# nuitka-project-else: -# nuitka-project: --product-version=0.0.0 +# nuitka-project: --product-version=0.0.0 from os import path, environ, name as os_name from tempfile import gettempdir