From 0ce43f5992651c26fceb2c19da3837cea569de95 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Sun, 31 Dec 2023 02:32:40 +0800 Subject: [PATCH] update dependency and fix issue with tomli --- .github/workflows/get_info.py | 4 ++-- .gitignore | 1 + Difficult_Rocket/__init__.py | 8 ++++---- Difficult_Rocket/client/__init__.py | 4 ++-- Difficult_Rocket/runtime.py | 6 +++--- Difficult_Rocket/utils/tools.py | 9 +++++---- README.md | 3 ++- config/main.toml | 1 + docs/README-en.md | 7 ++----- gen_require.py | 2 +- libs/pyglet | 2 +- libs/utils/parse_toml.py | 2 +- mods/dr_game/__init__.py | 2 +- 13 files changed, 26 insertions(+), 25 deletions(-) diff --git a/.github/workflows/get_info.py b/.github/workflows/get_info.py index a5f88db..8f8b171 100644 --- a/.github/workflows/get_info.py +++ b/.github/workflows/get_info.py @@ -6,7 +6,7 @@ import os import sys -import rtoml +import tomlkit import io @@ -35,7 +35,7 @@ if sys.argv == [__file__]: # 没有输入参数,直接输出默认信息并 config_file = tools.load_file("./config/main.toml") config_file["window"]["width"] = 1024 config_file["window"]["height"] = 768 - rtoml.dump(config_file, open("./config/main.toml", "w")) + tomlkit.dump(config_file, open("./config/main.toml", "w")) elif os.path.abspath(os.curdir) in sys.path and "-github" in sys.argv: print(f"DR_version={DR_status.DR_version}") diff --git a/.gitignore b/.gitignore index 57dc8eb..462c7a3 100644 --- a/.gitignore +++ b/.gitignore @@ -85,6 +85,7 @@ coverage.xml *.pot # Environments +env* .env .venv env/ diff --git a/Difficult_Rocket/__init__.py b/Difficult_Rocket/__init__.py index 1cd3baa..b7f9233 100644 --- a/Difficult_Rocket/__init__.py +++ b/Difficult_Rocket/__init__.py @@ -79,7 +79,7 @@ DR_status = _DRStatus() def load_logger(): log_config_path = Path("./config/lndl-logger.toml") - import rtoml + import tomli warn_config = False if not log_config_path.is_file(): @@ -91,11 +91,11 @@ def load_logger(): except (FileNotFoundError, OSError, PermissionError): print("\033[31mFailed to write default log config file\033[0m") warn_config = True - logger_config = rtoml.loads(log_config.default_config) + logger_config = tomli.loads(log_config.default_config) else: # 读取配置文件 - with open(log_config_path, encoding="utf-8") as f: - logger_config = rtoml.load(f) + with open(log_config_path, 'rb') as f: + logger_config = tomli.load(f) # 输入 lndl 进行配置 from lib_not_dr.loggers.config import read_config, get_logger diff --git a/Difficult_Rocket/client/__init__.py b/Difficult_Rocket/client/__init__.py index ac81550..399ff39 100644 --- a/Difficult_Rocket/client/__init__.py +++ b/Difficult_Rocket/client/__init__.py @@ -16,7 +16,7 @@ from decimal import Decimal from typing import Callable, Dict, List, TYPE_CHECKING, Type # third function -import rtoml +import tomlkit import pyglet # from pyglet import gl @@ -330,7 +330,7 @@ class ClientWindow(Window): config_file["window"]["width"] = self.width config_file["window"]["height"] = self.height config_file["runtime"]["language"] = DR_runtime.language - rtoml.dump(config_file, open("./config/main.toml", "w")) + tomlkit.dump(config_file, open("./config/main.toml", "w")) self.logger.info(tr().client.config.save.done()) """ diff --git a/Difficult_Rocket/runtime.py b/Difficult_Rocket/runtime.py index 9eb2d12..a3267bc 100644 --- a/Difficult_Rocket/runtime.py +++ b/Difficult_Rocket/runtime.py @@ -37,10 +37,10 @@ class _DRRuntime(Options): def load_file(self) -> bool: with contextlib.suppress(FileNotFoundError): - with open("./config/main.toml", "r", encoding="utf-8") as f: - import rtoml + with open("./config/main.toml", "rb") as f: + import tomli - config_file = rtoml.load(f) + config_file = tomli.load(f) self.language = config_file["runtime"]["language"] self.mod_path = config_file["game"]["mods"]["path"] self.main_config = config_file diff --git a/Difficult_Rocket/utils/tools.py b/Difficult_Rocket/utils/tools.py index 04558a3..6c600ca 100644 --- a/Difficult_Rocket/utils/tools.py +++ b/Difficult_Rocket/utils/tools.py @@ -16,7 +16,8 @@ import sys import time import math import json -import rtoml +import tomli +import tomlkit import configparser from pathlib import Path @@ -62,8 +63,8 @@ def load_file( if stack: get_file = get_file[stack] elif f_type == "toml": - with open(file_name, mode="r", encoding=encoding) as file: - get_file = rtoml.load(file) + with open(file_name, mode="rb") as file: + get_file = tomli.load(file) if stack is not None: get_file = get_file[stack] elif f_type == "json": @@ -102,7 +103,7 @@ def save_dict_file(file_name: str, data: dict, encoding: str = "utf-8") -> bool: return False elif f_type == "toml": with open(file_name, mode="w", encoding=encoding) as file: - rtoml.dump(data, file) + tomlkit.dump(data, file) elif f_type == "json": with open(file_name, mode="w", encoding=encoding) as file: json.dump(data, file) diff --git a/README.md b/README.md index 3b5893b..153ce8c 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,8 @@ git clone git@github.com:shenjackyuanjie/Difficult-Rocket.git ### 2. 安装依赖 ```bash title="install.sh" -python -m pip install -r requirement.txt +python gen_require.py 0 +python -m pip install -r requirements.txt git submodule update --init --recursive cd libs python -m pip install ./lib_not_dr diff --git a/config/main.toml b/config/main.toml index 7af5df9..f1b9a61 100644 --- a/config/main.toml +++ b/config/main.toml @@ -21,5 +21,6 @@ background_color = [21, 22, 23, 0] width = 1024 height = 768 gui_scale = 1 + [game.mods] path = "mods" diff --git a/docs/README-en.md b/docs/README-en.md index 6be9940..94b5011 100644 --- a/docs/README-en.md +++ b/docs/README-en.md @@ -56,6 +56,7 @@ git clone git@github.com:shenjackyuanjie/Difficult-Rocket.git ### 2. Install requirements ```bash title="install.sh" +python gen_require.py 0 python -m pip install -r requirements.txt git submodule update --init --recursive cd libs @@ -84,14 +85,10 @@ python DR.py > python gen_require.py [-h] {0,1,2} > run / build / compile -- `pyglet` (pre-installed V2.0.8 path:`./libs/pyglet`) +- `pyglet` (pre-installed V2.x path:`./libs/pyglet`) - `xmltodict` (pre-installed V0.12.0 path:`./libs/xmltodict`) - `pyperclip` (pre-installed V1.8.2 path: `./libs/pyperclip`) -[requirement.txt](requirement.txt) -[requirement-build.txt](requirement-build.txt) -[requirement-dev.txt](requirement-dev.txt) - ## Credits - Open Source Projects diff --git a/gen_require.py b/gen_require.py index 1defc21..0360b27 100644 --- a/gen_require.py +++ b/gen_require.py @@ -34,7 +34,7 @@ dev = { "debug": [ "objprint >= 0.2.3", "viztracer >= 0.16.0; platform_python_implementation != \"PyPy\"", - "vizplugin >= 0.1.3; platform_python_implementation != \"PyPy\"" + "vizplugins >= 0.1.3; platform_python_implementation != \"PyPy\"" ] } # fmt: on diff --git a/libs/pyglet b/libs/pyglet index 6b586c7..c50c697 160000 --- a/libs/pyglet +++ b/libs/pyglet @@ -1 +1 @@ -Subproject commit 6b586c72a7c17aa7b140db3a0549897cc73f9959 +Subproject commit c50c697b40c31361f499d88e83a9a0980d8fb2c0 diff --git a/libs/utils/parse_toml.py b/libs/utils/parse_toml.py index 26f08c7..429fb35 100644 --- a/libs/utils/parse_toml.py +++ b/libs/utils/parse_toml.py @@ -2,7 +2,7 @@ import json import pprint import sys -import rtoml as toml +import tomlkit as toml with open(sys.argv[1], encoding="utf-8", mode="r") as f: if sys.argv[2] == "parse": diff --git a/mods/dr_game/__init__.py b/mods/dr_game/__init__.py index 3758b25..d1c4841 100644 --- a/mods/dr_game/__init__.py +++ b/mods/dr_game/__init__.py @@ -16,7 +16,7 @@ from Difficult_Rocket.api.types import Options, Version from lib_not_dr import loggers -DR_rust_version = Version("0.3.0") # DR_mod 的 Rust 编写部分的兼容版本 +DR_rust_version = Version("0.3.1") # DR_mod 的 Rust 编写部分的兼容版本 logger = loggers.config.get_logger_from_old("client.dr_game", "client")