From eabcc82d0ee9702e8d7657ff89564c8a93e8026f Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Mon, 20 Nov 2023 20:34:33 +0800 Subject: [PATCH] add new work flow1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 算了,不需要 init sub modules 我的问题,没处理好依赖 some fix to make ruff happy remove ruff format --- .github/workflows/dr_rs.yml | 12 +-- .github/workflows/nuitka.yml | 17 +-- .github/workflows/release.yml | 113 ++++++++++++++++++++ Difficult_Rocket/api/types/__init__.py | 10 +- Difficult_Rocket/client/guis/format/html.py | 14 +-- Difficult_Rocket/command/line.py | 6 +- Difficult_Rocket/gui/widget/theme/button.py | 3 +- Difficult_Rocket/utils/translate.py | 2 +- mods/dr_game/types.py | 3 +- pyproject.toml | 12 ++- 10 files changed, 154 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/dr_rs.yml b/.github/workflows/dr_rs.yml index c6192ed..4b7c8d7 100644 --- a/.github/workflows/dr_rs.yml +++ b/.github/workflows/dr_rs.yml @@ -25,7 +25,7 @@ jobs: fail-fast: false matrix: os: [macos-latest, ubuntu-latest, windows-latest] - python-version: ["3.8", "3.10"] # 3.11 still not support by nuitka + python-version: ["3.8"] # 3.11 is now supported!, but just run 3.8 runs-on: ${{ matrix.os }} @@ -35,10 +35,10 @@ jobs: uses: actions/checkout@v4 # check out submodule - - name: init submodule - run: | - git submodule init - git submodule update + # - name: init submodule + # run: | + # git submodule init + # git submodule update # 缓存 Rust 构建 - name: Cache rust @@ -70,12 +70,12 @@ jobs: cache: 'pip' cache-dependency-path: | **/requirement-dev.txt - .github/workflows/requirement.txt # 安装依赖 - name: Install env run: | pip install -r requirement-dev.txt + pip install git+https://github.com/shenjackyuanjie/lib-not-dr.git # 提取 DR 版本和其他信息 - name: Display Difficult-Rocket info diff --git a/.github/workflows/nuitka.yml b/.github/workflows/nuitka.yml index 34d69aa..351ba04 100644 --- a/.github/workflows/nuitka.yml +++ b/.github/workflows/nuitka.yml @@ -39,10 +39,11 @@ jobs: uses: actions/checkout@v4 # 初始化子模块 - - name: Init submodules - run: | - git submodule init - git submodule update + # 暂时不需要 因为直接用 git install + # - name: Init submodules + # run: | + # git submodule init + # git submodule update # 安装 Python - name: Setup Python ${{ matrix.python-version }} @@ -53,12 +54,12 @@ jobs: cache: 'pip' cache-dependency-path: | **/requirement-dev.txt - .github/workflows/requirement.txt - # 安装 pyglet - - name: Install pyglet + # 安装特殊依赖 + - name: Install git denpendencies run: | pip install git+https://github.com/shenjackyuanjie/pyglet.git + pip install git+https://github.com/shenjackyuanjie/lib-not-dr.git # 安装依赖 - name: Install env @@ -71,7 +72,7 @@ jobs: # 只在 windows 的 python 3.8 上检查 减少无用报错 run: | pip install ruff - ruff check . --exit-zero --format github + ruff check . --exit-zero # 提取 DR 版本和其他信息 - name: Display Difficult-Rocket info diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..209293a --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,113 @@ +# 名称 +name: Build DR release + +# 运行条件 +on: + # 触发条件 + workflow_dispatch: + +# 主任务 +jobs: + build-release: + # 全都要! + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + python-version: ["3.8", "3.9", "3.10", "3.11"] + # 老子全都要 ! + + runs-on: ${{ matrix.os }} + + steps: + # Check-out repository + - name: Check out + uses: actions/checkout@v4 + + # 初始化子模块 + # - name: Init submodules + # run: | + # git submodule init + # git submodule update + + # 缓存 Rust 构建 + - name: Cache rust + uses: Swatinem/rust-cache@v2 + with: + workspaces: mods/dr_game/Difficult_Rocket_rs + key: dr_release_v1 + + # 安装 Python + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} # 为了支持 win7 我还是得用 3.8 + architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified + cache: 'pip' + cache-dependency-path: | + **/requirement-dev.txt + + # 安装特殊依赖 + - name: Install git denpendencies + run: | + pip install git+https://github.com/shenjackyuanjie/pyglet.git + pip install git+https://github.com/shenjackyuanjie/lib-not-dr.git + + # 安装依赖 + - name: Install env + run: | + pip install -r requirement-dev.txt + + # 提取 DR 版本和其他信息 + - name: Display Difficult-Rocket info + id: DR_info + shell: pwsh + run: | + $infos = python .github/workflows/get_info.py -github + Write-Output $infos >> $env:GITHUB_ENV + python .github/workflows/get_info.py + + # 使用新的 nuitka_build.py + - name: Build by nuitka + shell: pwsh + run: | + python nuitka_build.py --github + # 集成的构建脚本 好耶! + + # 编译 dr_rs + - name: Build dr_rs + shell: pwsh + run: | + Set-Location mods/dr_game/Difficult_Rocket_rs/src + python setup.py build + python post_build.py + python setup.py clean + cd .. + Remove-Item -Recurse -Force src + + # 获取短 sha + - name: Get short commit sha + id: get_short_sha + shell: pwsh + run: | + $short_sha = Write-Output $env:GITHUB_SHA + $short_sha = $short_sha.substring(1,7) + Write-Output $short_sha + Write-Output "short_sha=$short_sha" >> $env:GITHUB_ENV + + # Uploads artifact + - name: Upload Artifact + uses: actions/upload-artifact@v3 + with: + name: Difficult-Rocket_v${{env.DR_version}}-${{runner.os}}${{matrix.python-version}}.zip + path: | + build/github/DR.dist + + + # Uploads artifact + - name: Upload Artifact + uses: actions/upload-artifact@v3 + with: + name: DR_rs${{env.DR_version}}-${{runner.os}}${{matrix.python-version}}-Build.${{github.run_number}}+${{env.short_sha}} + path: | + mods/dr_game diff --git a/Difficult_Rocket/api/types/__init__.py b/Difficult_Rocket/api/types/__init__.py index 8f9955d..dc5f2fb 100644 --- a/Difficult_Rocket/api/types/__init__.py +++ b/Difficult_Rocket/api/types/__init__.py @@ -7,11 +7,11 @@ from typing import Dict, Union from dataclasses import dataclass -from libs.lib_not_dr.types.options import (Options, - OptionsError, - OptionNameNotDefined, - OptionNotFound, - get_type_hints_) +from lib_not_dr.types.options import (Options, + OptionsError, + OptionNameNotDefined, + OptionNotFound, + get_type_hints_) from libs.MCDR.version import (Version, VersionRequirement, VersionParsingError) diff --git a/Difficult_Rocket/client/guis/format/html.py b/Difficult_Rocket/client/guis/format/html.py index 80f9159..b3d5cbf 100644 --- a/Difficult_Rocket/client/guis/format/html.py +++ b/Difficult_Rocket/client/guis/format/html.py @@ -66,7 +66,7 @@ class SingleTextStyle: @tag.setter def tag(self, value: list): - assert type(value) == list, 'SingleTextStyle.tag must be list' + assert isinstance(value, list), 'SingleTextStyle.tag must be list' for tag in value: if tag not in self._tag: self._tag.append(tag) @@ -82,7 +82,7 @@ class SingleTextStyle: :param other: 叠加的字体样式 :return: 叠加后的字体样式 """ - assert type(other) == SingleTextStyle, f'SingleTextStyle + other\n other must be the same type, not a {type(other)}' + assert isinstance(other, SingleTextStyle), f'SingleTextStyle + other\n other must be the same type, not a {type(other)}' return SingleTextStyle( font_name=other.font_name or self.font_name, font_size=other.font_size or self.font_size, @@ -102,7 +102,7 @@ class SingleTextStyle: :param other: 叠加的字体样式 :return: 叠加后的字体样式 """ - assert type(other) == SingleTextStyle, f'SingleTextStyle += other\n other must be the same type, not a {type(other)}' + assert isinstance(other, SingleTextStyle), f'SingleTextStyle += other\n other must be the same type, not a {type(other)}' self.font_name = other.font_name or self.font_name self.font_size = other.font_size or self.font_size self.bold = other.bold or self.bold @@ -125,7 +125,7 @@ class SingleTextStyle: :param other: 叠加的字体样式 :return: 是否相同 """ - assert type(other) == SingleTextStyle + assert isinstance(other, SingleTextStyle) return other.tag in self.tag def same_font(self, other: 'SingleTextStyle') -> bool: @@ -134,7 +134,7 @@ class SingleTextStyle: :param other: 叠加的字体样式 :return: 是否相同 """ - assert type(other) == SingleTextStyle + assert isinstance(other, SingleTextStyle) return (self.font_name == other.font_name and self.font_size == other.font_size and self.color == other.color and @@ -146,7 +146,7 @@ class SingleTextStyle: :param other: 叠加的字体样式 :return: 是否相同 """ - assert type(other) == SingleTextStyle + assert isinstance(other, SingleTextStyle) return self.bold == other.bold def same_italic(self, other: 'SingleTextStyle') -> bool: @@ -155,7 +155,7 @@ class SingleTextStyle: :param other: 叠加的字体样式 :return: 是否相同 """ - assert type(other) == SingleTextStyle + assert isinstance(other, SingleTextStyle) return self.italic == other.italic """ diff --git a/Difficult_Rocket/command/line.py b/Difficult_Rocket/command/line.py index a536c8c..9124316 100644 --- a/Difficult_Rocket/command/line.py +++ b/Difficult_Rocket/command/line.py @@ -125,7 +125,7 @@ class CommandLine(widgets.WidgetBase): @text.setter def text(self, value): - assert type(value) is str, 'CommandLine\'s text must be string!' + assert isinstance(value, str), 'CommandLine\'s text must be string!' self._text = value self._line.text = value @@ -143,7 +143,7 @@ class CommandLine(widgets.WidgetBase): 0 ~ (self.length-1) -> 切换视角到对应的行数 实际上还有一个限制 """ - assert type(value) is int, 'Command View must be integer' + assert isinstance(value, int), 'Command View must be integer' assert -self.length < value < self.length, f'Command View must be bigger than {-self.length} and smaller than {self.length}' if value == -1: # flush command list self._label.insert(0, self._label[-1]) @@ -168,7 +168,7 @@ class CommandLine(widgets.WidgetBase): @editing.setter def editing(self, value): - assert type(value) is bool, 'Command editing must be bool!' + assert isinstance(value, bool), 'Command editing must be bool!' self._editing = value self._line.visible = value self._outline.visible = value diff --git a/Difficult_Rocket/gui/widget/theme/button.py b/Difficult_Rocket/gui/widget/theme/button.py index 43450b9..fa8fe3a 100644 --- a/Difficult_Rocket/gui/widget/theme/button.py +++ b/Difficult_Rocket/gui/widget/theme/button.py @@ -4,9 +4,8 @@ # All rights reserved # ------------------------------- -from typing import Optional, Tuple +from typing import Tuple -from pyglet.shapes import Rectangle from pyglet.graphics import Batch, Group from Difficult_Rocket.gui.widget.theme import BaseTheme, FontTheme diff --git a/Difficult_Rocket/utils/translate.py b/Difficult_Rocket/utils/translate.py index a09315e..f2fd288 100644 --- a/Difficult_Rocket/utils/translate.py +++ b/Difficult_Rocket/utils/translate.py @@ -37,7 +37,7 @@ class TranslateConfig: def set(self, item: str, value: Union[bool, "Tr", "Translates"]) -> 'TranslateConfig': assert getattr(self, item, None) is not None, f'Config {item} is not in TranslateConfig' - assert type(value) is bool + assert isinstance(value, bool) setattr(self, item, value) return self diff --git a/mods/dr_game/types.py b/mods/dr_game/types.py index 99f59ce..0e0a900 100644 --- a/mods/dr_game/types.py +++ b/mods/dr_game/types.py @@ -5,8 +5,7 @@ # ------------------------------- import math -from typing import Dict, Union, Optional -from dataclasses import dataclass +from typing import Dict, Union # pyglet from pyglet.image import load, AbstractImage diff --git a/pyproject.toml b/pyproject.toml index a40f987..f69b532 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,11 +40,15 @@ build = [ target-version = "py38" line-length = 150 -src = ["Difficult_Rocket", "libs/lib_not_dr", "libs/utils"] +src = ["Difficult_Rocket", "libs/utils"] +exclude = ['libs/pyglet', + 'libs/pyperclip', + 'libs/lib_not_dr', + 'libs/MCDR/serializer.py', + 'libs/utils/logger-old.py' # 旧版日志, 忽略他就好 +] -exclude = ['libs/pyglet', 'libs/pyperclip', 'libs/MCDR/serializer.py'] - -[nuitka] +[tool.lndl.nuitka] lto = "yes" main = "DR.py"