Skip to content

Commit

Permalink
Add gui executable for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Shengjie Xu committed Oct 28, 2024
1 parent ce1ce27 commit e6897b0
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 17 deletions.
5 changes: 4 additions & 1 deletion .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/preppipe/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
# 一般用于在报错时追加部分没有翻译的错误提示
# (只有程序内部错误的处理可以用这种方式,如果用户操作有错的话还是应该用带翻译的提示)
Expand Down
50 changes: 38 additions & 12 deletions versionfile_gen.py
Original file line number Diff line number Diff line change
@@ -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(".")]
Expand All @@ -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:
Expand Down Expand Up @@ -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}')]
),
Expand All @@ -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
Expand All @@ -90,4 +109,11 @@ def generate_versionfile():
print(versionfile_print)

if __name__== "__main__":
generate_versionfile()
# versionfile_gen.py <versionfile> <executable_filename> [--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)

0 comments on commit e6897b0

Please sign in to comment.