add longest option for Options and nuitka build now default longest = 70
This commit is contained in:
parent
1b858c5154
commit
289ec9b4ac
@ -4,6 +4,7 @@
|
|||||||
# All rights reserved
|
# All rights reserved
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
|
||||||
|
import warnings
|
||||||
import traceback
|
import traceback
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
@ -137,13 +138,22 @@ class Options:
|
|||||||
raise OptionNotFound(f'Option {option} is not found in {self.name}') from None
|
raise OptionNotFound(f'Option {option} is not found in {self.name}') from None
|
||||||
return values
|
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:
|
:return:
|
||||||
"""
|
"""
|
||||||
raw_option = self.option()
|
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:
|
def format(self, text: str) -> str:
|
||||||
"""
|
"""
|
||||||
@ -164,12 +174,15 @@ class Options:
|
|||||||
self.cached_options = self.option()
|
self.cached_options = self.option()
|
||||||
return self.cached_options
|
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 列表
|
返回一个可以用于打印的 option 列表
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
if longest is None:
|
||||||
options = self.flush_option()
|
options = self.flush_option()
|
||||||
|
else:
|
||||||
|
options = self.str_option(longest)
|
||||||
max_len_key = 1
|
max_len_key = 1
|
||||||
max_len_value = 1
|
max_len_value = 1
|
||||||
max_len_value_t = 1
|
max_len_value_t = 1
|
||||||
@ -182,12 +195,12 @@ class Options:
|
|||||||
option_list.append((key, value, value_t))
|
option_list.append((key, value, value_t))
|
||||||
return option_list, max_len_key, max_len_value, max_len_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 字符串
|
返回一个 markdown 格式的 option 字符串
|
||||||
:return: markdown 格式的 option 字符串
|
:return: markdown 格式的 option 字符串
|
||||||
"""
|
"""
|
||||||
value = self.option_with_len()
|
value = self.option_with_len(longest)
|
||||||
cache = StringIO()
|
cache = StringIO()
|
||||||
option_len = max(value[1], len('Option'))
|
option_len = max(value[1], len('Option'))
|
||||||
value_len = max(value[2], len('Value'))
|
value_len = max(value[2], len('Value'))
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
import platform
|
import platform
|
||||||
import traceback
|
import traceback
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple, Optional
|
||||||
|
|
||||||
from Difficult_Rocket.api.types import Options, Version
|
from Difficult_Rocket.api.types import Options, Version
|
||||||
|
|
||||||
@ -28,6 +28,7 @@ class CompilerHelper(Options):
|
|||||||
use_mingw: bool = False # --mingw64
|
use_mingw: bool = False # --mingw64
|
||||||
standalone: bool = True # --standalone
|
standalone: bool = True # --standalone
|
||||||
use_ccache: bool = True # not --disable-ccache
|
use_ccache: bool = True # not --disable-ccache
|
||||||
|
enable_console: bool = True # --enable-console / --disable-console
|
||||||
|
|
||||||
show_progress: bool = True # --show-progress
|
show_progress: bool = True # --show-progress
|
||||||
show_memory: bool = False # --show-memory
|
show_memory: bool = False # --show-memory
|
||||||
@ -38,8 +39,11 @@ class CompilerHelper(Options):
|
|||||||
|
|
||||||
company_name: str = 'tool-shenjack-workshop'
|
company_name: str = 'tool-shenjack-workshop'
|
||||||
product_name: str = 'Difficult-Rocket'
|
product_name: str = 'Difficult-Rocket'
|
||||||
product_version: Version
|
|
||||||
file_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')
|
icon_path: Path = Path('textures/icon.png')
|
||||||
|
|
||||||
@ -73,8 +77,8 @@ class CompilerHelper(Options):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.as_markdown()
|
return self.as_markdown()
|
||||||
|
|
||||||
def as_markdown(self) -> str:
|
def as_markdown(self, longest: Optional[int] = None) -> str:
|
||||||
front = super().as_markdown()
|
front = super().as_markdown(longest)
|
||||||
gen_cmd = self.gen_subprocess_cmd()
|
gen_cmd = self.gen_subprocess_cmd()
|
||||||
return f"{front}\n\n```bash\n{' '.join(gen_cmd)}\n```"
|
return f"{front}\n\n```bash\n{' '.join(gen_cmd)}\n```"
|
||||||
|
|
||||||
@ -84,14 +88,22 @@ class CompilerHelper(Options):
|
|||||||
icon_cmd = ""
|
icon_cmd = ""
|
||||||
if platform.system() == 'Darwin':
|
if platform.system() == 'Darwin':
|
||||||
icon_cmd = f"--macos-app-icon={self.icon_path.absolute()}"
|
icon_cmd = f"--macos-app-icon={self.icon_path.absolute()}"
|
||||||
|
cmd_list.append(f"--macos-app-version={self.product_version}")
|
||||||
elif platform.system() == 'Windows':
|
elif platform.system() == 'Windows':
|
||||||
icon_cmd = f"--windows-icon-from-ico={self.icon_path.absolute()}"
|
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:
|
if self.use_lto:
|
||||||
cmd_list.append('--lto=yes')
|
cmd_list.append('--lto=yes')
|
||||||
else:
|
else:
|
||||||
cmd_list.append('--lto=no')
|
cmd_list.append('--lto=no')
|
||||||
|
|
||||||
|
if self.enable_console:
|
||||||
|
cmd_list.append('--enable-console')
|
||||||
|
else:
|
||||||
|
cmd_list.append('--disable-console')
|
||||||
|
|
||||||
if self.use_clang:
|
if self.use_clang:
|
||||||
cmd_list.append('--clang')
|
cmd_list.append('--clang')
|
||||||
if self.use_msvc:
|
if self.use_msvc:
|
||||||
@ -113,8 +125,10 @@ class CompilerHelper(Options):
|
|||||||
|
|
||||||
cmd_list.append(f"--company-name={self.company_name}")
|
cmd_list.append(f"--company-name={self.company_name}")
|
||||||
cmd_list.append(f"--product-name={self.product_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"--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:
|
if icon_cmd:
|
||||||
cmd_list.append(icon_cmd)
|
cmd_list.append(icon_cmd)
|
||||||
|
@ -79,9 +79,11 @@ if __name__ == '__main__':
|
|||||||
if f'pyglet.{lib}.{name}' in compiler.no_follow_import:
|
if f'pyglet.{lib}.{name}' in compiler.no_follow_import:
|
||||||
compiler.no_follow_import.remove(f'pyglet.{lib}.{name}')
|
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())
|
print(compiler.gen_subprocess_cmd())
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user