From e6897b0def78db123513cc23a2c3a333aff46c27 Mon Sep 17 00:00:00 2001 From: Shengjie Xu Date: Mon, 28 Oct 2024 00:12:08 -0400 Subject: [PATCH] Add gui executable for CI --- .github/actions/build/action.yml | 5 +++- .github/workflows/ci.yml | 13 ++++++--- setup.cfg | 6 ++++ src/preppipe/language.py | 6 ++++ versionfile_gen.py | 50 ++++++++++++++++++++++++-------- 5 files changed, 63 insertions(+), 17 deletions(-) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index cc8f02d..4048a09 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -26,8 +26,11 @@ runs: - name: build run: python3 -X utf8 -m build shell: bash + - name: fetch wheel filename + run: echo WHEEL_FILE=`echo dist/*.whl` >> $GITHUB_ENV + shell: bash - name: install - run: pip install dist/*.whl + run: pip install "${WHEEL_FILE}[gui]" shell: bash - name: build assets run: python3 -X utf8 ./build_assets.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6a0373..33a4286 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,12 +27,16 @@ jobs: run: echo "${{ steps.vars.outputs.version_tag }}" - name: install pyinstaller run: pip install pyinstaller - - name: create versionfile - run: python3 ./versionfile_gen.py + - name: create versionfiles + run: | + python3 ./versionfile_gen.py versionfile_cli.txt preppipe_cli.exe --cli + python3 ./versionfile_gen.py versionfile_gui.txt preppipe.exe - name: run pyinstaller run: | - pyinstaller --icon=preppipe.ico --version-file=versionfile.txt -n preppipe_cli -D preppipe_cli.py - cd dist/preppipe_cli && 7z.exe a -t7z -mx=9 ../preppipe_cli-windows-x64.7z * + pyinstaller --icon=preppipe.ico --version-file=versionfile_cli.txt -n preppipe_cli -D preppipe_cli.py + pyinstaller --icon=preppipe.ico --version-file=versionfile_gui.txt -n preppipe -D preppipe_gui_entry.py + cd dist/preppipe_cli && 7z.exe a -t7z -mx=9 ../preppipe_cli-windows-x64.7z * && cd ../.. + cd dist/preppipe && 7z.exe a -t7z -mx=9 ../preppipe-windows-x64.7z * && cd ../.. - uses: "marvinpinto/action-automatic-releases@latest" with: repo_token: "${{ secrets.GITHUB_TOKEN }}" @@ -41,6 +45,7 @@ jobs: title: "${{ steps.vars.outputs.version_tag }} 最新版本 (Latest build) - ${{ env.BRANCH_NAME }}" files: | dist/preppipe_cli-windows-x64.7z + dist/preppipe-windows-x64.7z dist/*.whl dist/builtin-assets.zip - name: Repository Dispatch diff --git a/setup.cfg b/setup.cfg index 31c1bda..2aad15b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,6 +42,12 @@ install_requires = graphviz antlr4-python3-runtime >= 4.10, < 4.11.0 +# GUI extra dependencies here +# https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#configuring-setup-using-setup-cfg-files +[options.extras_require] +gui = + tkinterdnd2 + [options.packages.find] where = src diff --git a/src/preppipe/language.py b/src/preppipe/language.py index 396ffb9..3650d8b 100644 --- a/src/preppipe/language.py +++ b/src/preppipe/language.py @@ -198,6 +198,12 @@ def get(self) -> str: self.cached_str = self.candidates["en"][0] return self.cached_str + def lookup_candidate(self, lang : str) -> str | None: + if l := self.candidates.get(lang): + if len(l) > 0: + return l[0] + return None + def get_with_msg(self, msg : str): # 一般用于在报错时追加部分没有翻译的错误提示 # (只有程序内部错误的处理可以用这种方式,如果用户操作有错的话还是应该用带翻译的提示) diff --git a/versionfile_gen.py b/versionfile_gen.py index 2fc1ea5..8e43194 100644 --- a/versionfile_gen.py +++ b/versionfile_gen.py @@ -1,9 +1,12 @@ #!/usr/bin/env python3 +import sys +import argparse import datetime import preppipe +import preppipe.language -def generate_versionfile(): +def generate_versionfile(versionfile_filename: str, executable_filename : str, is_cli_only : bool = True): # The version string must be a 4-number string separated by dots, so we need a conversion here versionstr = preppipe.__version__.replace("post", ".") version_number_list = [int(s) for s in versionstr.split(".")] @@ -12,6 +15,22 @@ def generate_versionfile(): version_number_tuple = tuple(version_number_list) versionstr = ".".join([str(s) for s in version_number_tuple]) year = datetime.datetime.now().year + + internalname = "PrepPipe CLI" + file_description_dict = { + "en" : "PrepPipe Compiler Command Line Interface", + "zh_cn": "语涵编译器命令行", + "zh_hk": "語涵編譯器命令行" + } + if not is_cli_only: + internalname = "PrepPipe" + keys = list(file_description_dict.keys()) + for key in keys: + result = preppipe.language.Translatable.tr_program_name.lookup_candidate(key) + if result is None: + raise RuntimeError(f"Cannot find the program name for language {key}") + file_description_dict[key] = result + versionfile_content = f"""# UTF-8 # # For more details about fixed file info 'ffi' see: @@ -44,33 +63,33 @@ def generate_versionfile(): StringTable( u'040904B0', [StringStruct(u'CompanyName', u'PrepPipe Project'), - StringStruct(u'FileDescription', u'PrepPipe Compiler Command Line Interface'), + StringStruct(u'FileDescription', u'{file_description_dict["en"]}'), StringStruct(u'FileVersion', u'{versionstr}'), - StringStruct(u'InternalName', u'PrepPipe CLI'), + StringStruct(u'InternalName', u'{internalname}'), StringStruct(u'LegalCopyright', u'Copyright (c) {year} PrepPipe Contributors.'), - StringStruct(u'OriginalFilename', u'preppipe_cli.exe'), + StringStruct(u'OriginalFilename', u'{executable_filename}'), StringStruct(u'ProductName', u'PrepPipe Compiler'), StringStruct(u'ProductVersion', u'{versionstr}')] ), StringTable( u'080404B0', [StringStruct(u'CompanyName', u'语涵计划'), - StringStruct(u'FileDescription', u'语涵编译器命令行'), + StringStruct(u'FileDescription', u'{file_description_dict["zh_cn"]}'), StringStruct(u'FileVersion', u'{versionstr}'), - StringStruct(u'InternalName', u'PrepPipe CLI'), + StringStruct(u'InternalName', u'{internalname}'), StringStruct(u'LegalCopyright', u'Copyright (c) {year} 语涵计划贡献者'), - StringStruct(u'OriginalFilename', u'preppipe_cli.exe'), + StringStruct(u'OriginalFilename', u'{executable_filename}'), StringStruct(u'ProductName', u'语涵编译器'), StringStruct(u'ProductVersion', u'{versionstr}')] ), StringTable( u'040404B0', [StringStruct(u'CompanyName', u'語涵計劃'), - StringStruct(u'FileDescription', u'語涵編譯器命令行'), + StringStruct(u'FileDescription', u'{file_description_dict["zh_hk"]}'), StringStruct(u'FileVersion', u'{versionstr}'), - StringStruct(u'InternalName', u'PrepPipe CLI'), + StringStruct(u'InternalName', u'{internalname}'), StringStruct(u'LegalCopyright', u'Copyright (c) {year} 語涵計劃貢獻者'), - StringStruct(u'OriginalFilename', u'preppipe_cli.exe'), + StringStruct(u'OriginalFilename', u'{executable_filename}'), StringStruct(u'ProductName', u'語涵編譯器'), StringStruct(u'ProductVersion', u'{versionstr}')] ), @@ -79,7 +98,7 @@ def generate_versionfile(): ] ) """ - with open("versionfile.txt", "w", encoding="utf-8") as f: + with open(versionfile_filename, "w", encoding="utf-8") as f: f.write(versionfile_content) # print the content for debugging @@ -90,4 +109,11 @@ def generate_versionfile(): print(versionfile_print) if __name__== "__main__": - generate_versionfile() + # versionfile_gen.py [--cli] + parser = argparse.ArgumentParser(description='Generate version file for Windows executable') + parser.add_argument('versionfile', type=str, help='Output version file', default="versionfile.txt") + parser.add_argument('executable_filename', type=str, help='Executable filename', default="preppipe.exe") + parser.add_argument('--cli', action='store_true', help='CLI only') + args = parser.parse_args() + is_cli_only = args.cli + generate_versionfile(args.versionfile, args.executable_filename, is_cli_only)