add longest option for Options and nuitka build now default longest = 70

This commit is contained in:
shenjack 2023-06-16 00:02:08 +08:00
parent 1b858c5154
commit 289ec9b4ac
3 changed files with 43 additions and 14 deletions

View File

@ -4,6 +4,7 @@
# All rights reserved
# -------------------------------
import warnings
import traceback
from io import StringIO
from dataclasses import dataclass
@ -137,13 +138,22 @@ class Options:
raise OptionNotFound(f'Option {option} is not found in {self.name}') from None
return values
def str_option(self) -> Dict[str, Union[str, Any]]:
def str_option(self, shrink_to_long: Optional[int] = None) -> Dict[str, Union[str, Any]]:
"""
获取配置类的所有配置 并将所有非 BuiltInType 的值转换为 str
获取配置类的所有配置 并将所有非 BuiltIn 类型的值转换为 str
:return:
"""
raw_option = self.option()
return to_str_value_(raw_option)
str_option = to_str_value_(raw_option)
if shrink_to_long is None:
return str_option
if not isinstance(shrink_to_long, int) or shrink_to_long <= 0:
return str_option
for option, value in str_option.items():
if value is not None:
if len(str(value)) > shrink_to_long:
str_option[option] = str(value)[:shrink_to_long] + '...'
return str_option
def format(self, text: str) -> str:
"""
@ -164,12 +174,15 @@ class Options:
self.cached_options = self.option()
return self.cached_options
def option_with_len(self) -> Tuple[List[Tuple[str, Union[Any, Type], Type]], int, int, int]:
def option_with_len(self, longest: Optional[int] = None) -> Tuple[List[Tuple[str, Union[Any, Type], Type]], int, int, int]:
"""
返回一个可以用于打印的 option 列表
:return:
"""
options = self.flush_option()
if longest is None:
options = self.flush_option()
else:
options = self.str_option(longest)
max_len_key = 1
max_len_value = 1
max_len_value_t = 1
@ -182,12 +195,12 @@ class Options:
option_list.append((key, value, value_t))
return option_list, max_len_key, max_len_value, max_len_value_t
def as_markdown(self) -> str:
def as_markdown(self, longest: Optional[int] = None) -> str:
"""
返回一个 markdown 格式的 option 字符串
:return: markdown 格式的 option 字符串
"""
value = self.option_with_len()
value = self.option_with_len(longest)
cache = StringIO()
option_len = max(value[1], len('Option'))
value_len = max(value[2], len('Value'))

View File

@ -8,7 +8,7 @@
import platform
import traceback
from pathlib import Path
from typing import List, Tuple
from typing import List, Tuple, Optional
from Difficult_Rocket.api.types import Options, Version
@ -28,6 +28,7 @@ class CompilerHelper(Options):
use_mingw: bool = False # --mingw64
standalone: bool = True # --standalone
use_ccache: bool = True # not --disable-ccache
enable_console: bool = True # --enable-console / --disable-console
show_progress: bool = True # --show-progress
show_memory: bool = False # --show-memory
@ -38,8 +39,11 @@ class CompilerHelper(Options):
company_name: str = 'tool-shenjack-workshop'
product_name: str = 'Difficult-Rocket'
product_version: Version
file_version: Version
product_version: Version
file_description: str = 'Difficult Rocket' # --file-description
copy_right: str = 'Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com' # --copyright
icon_path: Path = Path('textures/icon.png')
@ -73,8 +77,8 @@ class CompilerHelper(Options):
def __str__(self):
return self.as_markdown()
def as_markdown(self) -> str:
front = super().as_markdown()
def as_markdown(self, longest: Optional[int] = None) -> str:
front = super().as_markdown(longest)
gen_cmd = self.gen_subprocess_cmd()
return f"{front}\n\n```bash\n{' '.join(gen_cmd)}\n```"
@ -84,14 +88,22 @@ class CompilerHelper(Options):
icon_cmd = ""
if platform.system() == 'Darwin':
icon_cmd = f"--macos-app-icon={self.icon_path.absolute()}"
cmd_list.append(f"--macos-app-version={self.product_version}")
elif platform.system() == 'Windows':
icon_cmd = f"--windows-icon-from-ico={self.icon_path.absolute()}"
elif platform.system() == 'Linux':
icon_cmd = f"--linux-icon={self.icon_path.absolute()}"
if self.use_lto:
cmd_list.append('--lto=yes')
else:
cmd_list.append('--lto=no')
if self.enable_console:
cmd_list.append('--enable-console')
else:
cmd_list.append('--disable-console')
if self.use_clang:
cmd_list.append('--clang')
if self.use_msvc:
@ -113,8 +125,10 @@ class CompilerHelper(Options):
cmd_list.append(f"--company-name={self.company_name}")
cmd_list.append(f"--product-name={self.product_name}")
cmd_list.append(f"--product-version={self.product_version}")
cmd_list.append(f"--file-version={self.file_version}")
cmd_list.append(f"--product-version={self.product_version}")
cmd_list.append(f"--file-description={self.file_description}")
cmd_list.append(f"--copyright={self.copy_right}")
if icon_cmd:
cmd_list.append(icon_cmd)

View File

@ -79,9 +79,11 @@ if __name__ == '__main__':
if f'pyglet.{lib}.{name}' in compiler.no_follow_import:
compiler.no_follow_import.remove(f'pyglet.{lib}.{name}')
print(compiler.output_path)
print(compiler.as_markdown(longest=70))
print(compiler)
if is_github:
from pprint import pprint
pprint(compiler.option())
print(compiler.gen_subprocess_cmd())