diff --git a/DR.py b/DR.py index eabe5d0..9c5addc 100644 --- a/DR.py +++ b/DR.py @@ -53,14 +53,6 @@ def main() -> int: from Difficult_Rocket.exception import TestError from Difficult_Rocket import crash from Difficult_Rocket import DR_option - try: - from libs.pyglet_rs import get_version_str, patch_vector - print('pyglet_rs available:', get_version_str()) - print('trying to patch pyglet_rs') - patch_vector() - except ImportError: - print('pyglet_rs import error') - traceback.print_exc() try: from libs import pyglet # 导入pyglet pyglet.resource.path = ['/textures/'] diff --git a/Difficult_Rocket/utils/options.py b/Difficult_Rocket/utils/options.py index 2b651ab..24678a6 100644 --- a/Difficult_Rocket/utils/options.py +++ b/Difficult_Rocket/utils/options.py @@ -4,7 +4,6 @@ # All rights reserved # ------------------------------- -import warnings import traceback from io import StringIO from dataclasses import dataclass @@ -138,22 +137,13 @@ class Options: raise OptionNotFound(f'Option {option} is not found in {self.name}') from None return values - def str_option(self, shrink_to_long: Optional[int] = None) -> Dict[str, Union[str, Any]]: + def str_option(self) -> Dict[str, Union[str, Any]]: """ - 获取配置类的所有配置 并将所有非 BuiltIn 类型的值转换为 str + 获取配置类的所有配置 并将所有非 BuiltInType 的值转换为 str :return: """ raw_option = self.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 + return to_str_value_(raw_option) def format(self, text: str) -> str: """ @@ -174,15 +164,12 @@ class Options: self.cached_options = self.option() return self.cached_options - def option_with_len(self, longest: Optional[int] = None) -> Tuple[List[Tuple[str, Union[Any, Type], Type]], int, int, int]: + def option_with_len(self) -> Tuple[List[Tuple[str, Union[Any, Type], Type]], int, int, int]: """ 返回一个可以用于打印的 option 列表 :return: """ - if longest is None: - options = self.flush_option() - else: - options = self.str_option(longest) + options = self.flush_option() max_len_key = 1 max_len_value = 1 max_len_value_t = 1 @@ -195,12 +182,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, longest: Optional[int] = None) -> str: + def as_markdown(self) -> str: """ 返回一个 markdown 格式的 option 字符串 :return: markdown 格式的 option 字符串 """ - value = self.option_with_len(longest) + value = self.option_with_len() cache = StringIO() option_len = max(value[1], len('Option')) value_len = max(value[2], len('Value')) diff --git a/configs/lang/en-us.toml b/configs/lang/en-us.toml index 2076d18..0dc59a2 100644 --- a/configs/lang/en-us.toml +++ b/configs/lang/en-us.toml @@ -7,7 +7,6 @@ env.version.python = "Python version: {}" env.version.DR = "Difficult_Rocket version: {}" env.version.DR_rs = "Difficult_Rocket_rs version: {}" env.version.pyglet = "pyglet version: {}" -env.version.pyglet_rs = "pyglet_rs version: {}" version.now_on = "Difficult Rocket is running on Python Vision" version.need3p = "Difficult Rocket depends on Python vision 3.0+" version.best38p = "Difficult Rocket is writen in Python {write_py_v}, and now is running on Python {py_v} may cause BUG" diff --git a/configs/lang/zh-CN.toml b/configs/lang/zh-CN.toml index c9d93d3..99ebe75 100644 --- a/configs/lang/zh-CN.toml +++ b/configs/lang/zh-CN.toml @@ -7,7 +7,6 @@ env.version.python = "Python 版本: {}" env.version.DR = "Difficult_Rocket 版本: {}" env.version.DR_rs = "Difficult_Rocket_rs 版本: {}" env.version.pyglet = "pyglet 版本: {}" -env.version.pyglet_rs = "pyglet_rs 版本: {}" version.now_on = "困难火箭的运行 Python 环境为" version.need3p = "困难火箭需要 Python3.0+ 的环境" version.best38p = "困难火箭是在 Python {write_py_v} 的环境下编写的,目前正在运行在Python {py_v}的环境下,可能产生BUG" diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 0d9e668..8cdfc78 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -17,7 +17,6 @@ - [nuitka performents test](./nuitka/20221121_nuitka_performs.md) - [nuitka options](./nuitka/20230116_nuitka_options.md) - [nuitka 1.3.7 compile options](./nuitka/nuitka_options_137.md) - - [nuitka 1.6.1 compile options](./nuitka/nuitka_options_161.md) - [计划特性](./plan_features/README.md) - [格式](./plan_features/格式.md) diff --git a/docs/src/nuitka/nuitka_options_161.md b/docs/src/nuitka/nuitka_options_161.md deleted file mode 100644 index 328f080..0000000 --- a/docs/src/nuitka/nuitka_options_161.md +++ /dev/null @@ -1,629 +0,0 @@ -# nuitka 1.6.1 --help - -``` text -Usage: __main__.py [--module] [--run] [options] main_module.py - -Options: - --help show this help message and exit - --version Show version information and important details for bug - reports, then exit. Defaults to off. - --module Create an extension module executable instead of a - program. Defaults to off. - --standalone Enable standalone mode for output. This allows you to - transfer the created binary to other machines without - it using an existing Python installation. This also - means it will become big. It implies these option: "-- - follow-imports" and "--python-flag=no_site". Defaults - to off. - --onefile On top of standalone mode, enable onefile mode. This - means not a folder, but a compressed executable is - created and used. Defaults to off. - --python-debug Use debug version or not. Default uses what you are - using to run Nuitka, most likely a non-debug version. - --python-flag=FLAG Python flags to use. Default is what you are using to - run Nuitka, this enforces a specific mode. These are - options that also exist to standard Python executable. - Currently supported: "-S" (alias "no_site"), - "static_hashes" (do not use hash randomization), - "no_warnings" (do not give Python run time warnings), - "-O" (alias "no_asserts"), "no_docstrings" (do not use - doc strings), "-u" (alias "unbuffered") and "-m". - Default empty. - --python-for-scons=PATH - If using Python3.3 or Python3.4, provide the path of a - Python binary to use for Scons. Otherwise Nuitka can - use what you run Nuitka with or a Python installation - from Windows registry. On Windows Python 3.5 or higher - is needed. On non-Windows, Python 2.6 or 2.7 will do - as well. - - Control the inclusion of modules and packages in result: - --include-package=PACKAGE - Include a whole package. Give as a Python namespace, - e.g. "some_package.sub_package" and Nuitka will then - find it and include it and all the modules found below - that disk location in the binary or extension module - it creates, and make it available for import by the - code. To avoid unwanted sub packages, e.g. tests you - can e.g. do this "--nofollow-import-to=*.tests". - Default empty. - --include-module=MODULE - Include a single module. Give as a Python namespace, - e.g. "some_package.some_module" and Nuitka will then - find it and include it in the binary or extension - module it creates, and make it available for import by - the code. Default empty. - --include-plugin-directory=MODULE/PACKAGE - Include also the code found in that directory, - considering as if they are each given as a main file. - Overrides all other inclusion options. You ought to - prefer other inclusion options, that go by names, - rather than filenames, those find things through being - in "sys.path". This option is for very special use - cases only. Can be given multiple times. Default - empty. - --include-plugin-files=PATTERN - Include into files matching the PATTERN. Overrides all - other follow options. Can be given multiple times. - Default empty. - --prefer-source-code - For already compiled extension modules, where there is - both a source file and an extension module, normally - the extension module is used, but it should be better - to compile the module from available source code for - best performance. If not desired, there is --no- - prefer-source-code to disable warnings about it. - Default off. - - Control the following into imported modules: - --follow-imports Descend into all imported modules. Defaults to on in - standalone mode, otherwise off. - --follow-import-to=MODULE/PACKAGE - Follow to that module if used, or if a package, to the - whole package. Can be given multiple times. Default - empty. - --nofollow-import-to=MODULE/PACKAGE - Do not follow to that module name even if used, or if - a package name, to the whole package in any case, - overrides all other options. Can be given multiple - times. Default empty. - --nofollow-imports Do not descend into any imported modules at all, - overrides all other inclusion options and not usable - for standalone mode. Defaults to off. - --follow-stdlib Also descend into imported modules from standard - library. This will increase the compilation time by a - lot and is also not well tested at this time and - sometimes won't work. Defaults to off. - - Onefile options: - --onefile-tempdir-spec=ONEFILE_TEMPDIR_SPEC - Use this as a folder to unpack to in onefile mode. - Defaults to '%TEMP%/onefile_%PID%_%TIME%', i.e. user - temporary directory and being non-static it's removed. - Use e.g. a string like - '%CACHE_DIR%/%COMPANY%/%PRODUCT%/%VERSION%' which is a - good static cache path, this will then not be removed. - --onefile-child-grace-time=GRACE_TIME_MS - When stopping the child, e.g. due to CTRL-C or - shutdown, etc. the Python code gets a - "KeyboardInterrupt", that it may handle e.g. to flush - data. This is the amount of time in ms, before the - child it killed in the hard way. Unit is ms, and - default 5000. - --onefile-no-compression - When creating the onefile, disable compression of the - payload. This is mostly for debug purposes, or to save - time. Default is off. - - Data files: - --include-package-data=PACKAGE - Include data files for the given package name. DLLs - and extension modules are not data files and never - included like this. Can use patterns the filenames as - indicated below. Data files of packages are not - included by default, but package configuration can do - it. This will only include non-DLL, non-extension - modules, i.e. actual data files. After a ":" - optionally a filename pattern can be given as well, - selecting only matching files. Examples: "--include- - package-data=package_name" (all files) "--include- - package-data=package_name=*.txt" (only certain type) " - --include-package-data=package_name=some_filename.dat - (concrete file) Default empty. - --include-data-files=DESC - Include data files by filenames in the distribution. - There are many allowed forms. With '--include-data- - files=/path/to/file/*.txt=folder_name/some.txt' it - will copy a single file and complain if it's multiple. - With '--include-data- - files=/path/to/files/*.txt=folder_name/' it will put - all matching files into that folder. For recursive - copy there is a form with 3 values that '--include- - data-files=/path/to/scan=folder_name=**/*.txt' that - will preserve directory structure. Default empty. - --include-data-dir=DIRECTORY - Include data files from complete directory in the - distribution. This is recursive. Check '--include- - data-files' with patterns if you want non-recursive - inclusion. An example would be '--include-data- - dir=/path/some_dir=data/some_dir' for plain copy, of - the whole directory. All files are copied, if you want - to exclude files you need to remove them beforehand, - or use '--noinclude-data-files' option to remove them. - Default empty. - --noinclude-data-files=PATTERN - Do not include data files matching the filename - pattern given. This is against the target filename, - not source paths. So to ignore a file pattern from - package data for "package_name" should be matched as - "package_name/*.txt". Or for the whole directory - simply use "package_name". Default empty. - --list-package-data=LIST_PACKAGE_DATA - Output the data files found for a given package name. - Default not done. - - Metadata support: - --include-distribution-metadata=DISTRIBUTION - Include metadata information for the given - distribution name. Some packages check metadata for - presence, version, entry points, etc. and without this - option given, it only works when it's recognized at - compile time which is not always happening. This of - course only makes sense for packages that are included - in the compilation. Default empty. - - DLL files: - --noinclude-dlls=PATTERN - Do not include DLL files matching the filename pattern - given. This is against the target filename, not source - paths. So ignore a DLL "someDLL" contained in the - package "package_name" it should be matched as - "package_name/someDLL.*". Default empty. - --list-package-dlls=LIST_PACKAGE_DLLS - Output the DLLs found for a given package name. - Default not done. - - Control the warnings to be given by Nuitka: - --warn-implicit-exceptions - Enable warnings for implicit exceptions detected at - compile time. - --warn-unusual-code - Enable warnings for unusual code detected at compile - time. - --assume-yes-for-downloads - Allow Nuitka to download external code if necessary, - e.g. dependency walker, ccache, and even gcc on - Windows. To disable, redirect input from nul device, - e.g. "" is used. For compatibility reasons, the - "__file__" value will always have ".py" suffix - independent of what it really is. - --module-name-choice=MODE - Select what value "__name__" and "__package__" are - going to be. With "runtime" (default for module mode), - the created module uses the parent package to deduce - the value of "__package__", to be fully compatible. - The value "original" (default for other modes) allows - for more static optimization to happen, but is - incompatible for modules that normally can be loaded - into any package. - - Output choices: - --output-filename=FILENAME - Specify how the executable should be named. For - extension modules there is no choice, also not for - standalone mode and using it will be an error. This - may include path information that needs to exist - though. Defaults to '' on this platform. - .exe - --output-dir=DIRECTORY - Specify where intermediate and final output files - should be put. The DIRECTORY will be populated with - build folder, dist folder, binaries, etc. Defaults to - current directory. - --remove-output Removes the build directory after producing the module - or exe file. Defaults to off. - --no-pyi-file Do not create a ".pyi" file for extension modules - created by Nuitka. This is used to detect implicit - imports. Defaults to off. - - Debug features: - --debug Executing all self checks possible to find errors in - Nuitka, do not use for production. Defaults to off. - --unstripped Keep debug info in the resulting object file for - better debugger interaction. Defaults to off. - --profile Enable vmprof based profiling of time spent. Not - working currently. Defaults to off. - --internal-graph Create graph of optimization process internals, do not - use for whole programs, but only for small test cases. - Defaults to off. - --trace-execution Traced execution output, output the line of code - before executing it. Defaults to off. - --recompile-c-only This is not incremental compilation, but for Nuitka - development only. Takes existing files and simply - compile them as C again. Allows compiling edited C - files for quick debugging changes to the generated - source, e.g. to see if code is passed by, values - output, etc, Defaults to off. Depends on compiling - Python source to determine which files it should look - at. - --xml=XML_FILENAME Write the internal program structure, result of - optimization in XML form to given filename. - --generate-c-only Generate only C source code, and do not compile it to - binary or module. This is for debugging and code - coverage analysis that doesn't waste CPU. Defaults to - off. Do not think you can use this directly. - --experimental=FLAG - Use features declared as 'experimental'. May have no - effect if no experimental features are present in the - code. Uses secret tags (check source) per experimented - feature. - --low-memory Attempt to use less memory, by forking less C - compilation jobs and using options that use less - memory. For use on embedded machines. Use this in case - of out of memory problems. Defaults to off. - --create-environment-from-report=CREATE_ENVIRONMENT_FROM_REPORT - Create a new virtualenv in that non-existing path from - the report file given with e.g. '--report=compilation- - report.xml'. Default not done. - - Backend C compiler choice: - --clang Enforce the use of clang. On Windows this requires a - working Visual Studio version to piggy back on. - Defaults to off. - --mingw64 Enforce the use of MinGW64 on Windows. Defaults to off - unless MSYS2 with MinGW Python is used. - --msvc=MSVC_VERSION - Enforce the use of specific MSVC version on Windows. - Allowed values are e.g. "14.3" (MSVC 2022) and other - MSVC version numbers, specify "list" for a list of - installed compilers, or use "latest". Defaults to - latest MSVC being used if installed, otherwise MinGW64 - is used. - --jobs=N Specify the allowed number of parallel C compiler - jobs. Defaults to the system CPU count. - --lto=choice Use link time optimizations (MSVC, gcc, clang). - Allowed values are "yes", "no", and "auto" (when it's - known to work). Defaults to "auto". - --static-libpython=choice - Use static link library of Python. Allowed values are - "yes", "no", and "auto" (when it's known to work). - Defaults to "auto". - - Cache Control: - --disable-cache=DISABLED_CACHES - Disable selected caches, specify "all" for all cached. - Currently allowed values are: - "all","ccache","bytecode","dll-dependencies". can be - given multiple times or with comma separated values. - Default none. - --clean-cache=CLEAN_CACHES - Clean the given caches before executing, specify "all" - for all cached. Currently allowed values are: - "all","ccache","bytecode","dll-dependencies". can be - given multiple times or with comma separated values. - Default none. - --disable-bytecode-cache - Do not reuse dependency analysis results for modules, - esp. from standard library, that are included as - bytecode. Same as --disable-cache=bytecode. - --disable-ccache Do not attempt to use ccache (gcc, clang, etc.) or - clcache (MSVC, clangcl). Same as --disable- - cache=ccache. - --disable-dll-dependency-cache - Disable the dependency walker cache. Will result in - much longer times to create the distribution folder, - but might be used in case the cache is suspect to - cause errors. Same as --disable-cache=dll- - dependencies. - --force-dll-dependency-cache-update - For an update of the dependency walker cache. Will - result in much longer times to create the distribution - folder, but might be used in case the cache is suspect - to cause errors or known to need an update. - - PGO compilation choices: - --pgo Enables C level profile guided optimization (PGO), by - executing a dedicated build first for a profiling run, - and then using the result to feedback into the C - compilation. Note: This is experimental and not - working with standalone modes of Nuitka yet. Defaults - to off. - --pgo-args=PGO_ARGS - Arguments to be passed in case of profile guided - optimization. These are passed to the special built - executable during the PGO profiling run. Default - empty. - --pgo-executable=PGO_EXECUTABLE - Command to execute when collecting profile - information. Use this only, if you need to launch it - through a script that prepares it to run. Default use - created program. - - Tracing features: - --report=REPORT_FILENAME - Report module, data files, compilation, plugin, etc. - details in an XML output file. This is also super - useful for issue reporting. These reports can e.g. be - used to re-create the environment easily using it with - '--create-environment-from-report', but contain a lot - of information. Default is off. - --report-diffable Report data in diffable form, i.e. no timing or memory - usage values that vary from run to run. Default is - off. - --report-user-provided=KEY_VALUE - Report data from you. This can be given multiple times - and be anything in 'key=value' form, where key should - be an identifier, e.g. use '--report-user- - provided=pipenv-lock-hash=64a5e4' to track some input - values. Default is empty. - --report-template=REPORT_DESC - Report via template. Provide template and output - filename "template.rst.j2:output.rst". For built-in - templates, check the User Manual for what these are. - Can be given multiple times. Default is empty. - --quiet Disable all information outputs, but show warnings. - Defaults to off. - --show-scons Run the C building backend Scons with verbose - information, showing the executed commands, detected - compilers. Defaults to off. - --no-progressbar Disable progress bars. Defaults to off. - --show-progress Obsolete: Provide progress information and statistics. - Disables normal progress bar. Defaults to off. - --show-memory Provide memory information and statistics. Defaults to - off. - --show-modules Provide information for included modules and DLLs - Obsolete: You should use '--report' file instead. - Defaults to off. - --show-modules-output=PATH - Where to output '--show-modules', should be a - filename. Default is standard output. - --verbose Output details of actions taken, esp. in - optimizations. Can become a lot. Defaults to off. - --verbose-output=PATH - Where to output from '--verbose', should be a - filename. Default is standard output. - - General OS controls: - --disable-console When compiling for Windows or macOS, disable the - console window and create a GUI application. Defaults - to off. - --enable-console When compiling for Windows or macOS, enable the - console window and create a console application. This - disables hints from certain modules, e.g. "PySide" - that suggest to disable it. Defaults to true. - --force-stdout-spec=FORCE_STDOUT_SPEC - Force standard output of the program to go to this - location. Useful for programs with disabled console - and programs using the Windows Services Plugin of - Nuitka commercial. Defaults to not active, use e.g. - '%PROGRAM%.out.txt', i.e. file near your program, - check User Manual for full list of available values. - --force-stderr-spec=FORCE_STDERR_SPEC - Force standard error of the program to go to this - location. Useful for programs with disabled console - and programs using the Windows Services Plugin of - Nuitka commercial. Defaults to not active, use e.g. - '%PROGRAM%.err.txt', i.e. file near your program, - check User Manual for full list of available values. - - Windows specific controls: - --windows-icon-from-ico=ICON_PATH - Add executable icon. Can be given multiple times for - different resolutions or files with multiple icons - inside. In the later case, you may also suffix with - # where n is an integer index starting from 1, - specifying a specific icon to be included, and all - others to be ignored. - --windows-icon-from-exe=ICON_EXE_PATH - Copy executable icons from this existing executable - (Windows only). - --onefile-windows-splash-screen-image=SPLASH_SCREEN_IMAGE - When compiling for Windows and onefile, show this - while loading the application. Defaults to off. - --windows-uac-admin - Request Windows User Control, to grant admin rights on - execution. (Windows only). Defaults to off. - --windows-uac-uiaccess - Request Windows User Control, to enforce running from - a few folders only, remote desktop access. (Windows - only). Defaults to off. - - macOS specific controls: - --macos-target-arch=MACOS_TARGET_ARCH - What architectures is this to supposed to run on. - Default and limit is what the running Python allows - for. Default is "native" which is the architecture the - Python is run with. - --macos-create-app-bundle - When compiling for macOS, create a bundle rather than - a plain binary application. Currently experimental and - incomplete. Currently this is the only way to unlock - disabling of console.Defaults to off. - --macos-app-icon=ICON_PATH - Add icon for the application bundle to use. Can be - given only one time. Defaults to Python icon if - available. - --macos-signed-app-name=MACOS_SIGNED_APP_NAME - Name of the application to use for macOS signing. - Follow "com.YourCompany.AppName" naming results for - best results, as these have to be globally unique, and - will potentially grant protected API accesses. - --macos-app-name=MACOS_APP_NAME - Name of the product to use in macOS bundle - information. Defaults to base filename of the binary. - --macos-app-mode=MODE - Mode of application for the application bundle. When - launching a Window, and appearing in Docker is - desired, default value "gui" is a good fit. Without a - Window ever, the application is a "background" - application. For UI elements that get to display - later, "ui-element" is in-between. The application - will not appear in dock, but get full access to - desktop when it does open a Window later. - --macos-sign-identity=MACOS_APP_VERSION - When signing on macOS, by default an ad-hoc identify - will be used, but with this option your get to specify - another identity to use. The signing of code is now - mandatory on macOS and cannot be disabled. Default - "ad-hoc" if not given. - --macos-sign-notarization - When signing for notarization, using a proper TeamID - identity from Apple, use the required runtime signing - option, such that it can be accepted. - --macos-app-version=MACOS_APP_VERSION - Product version to use in macOS bundle information. - Defaults to "1.0" if not given. - --macos-app-protected-resource=RESOURCE_DESC - Request an entitlement for access to a macOS protected - resources, e.g. - "NSMicrophoneUsageDescription:Microphone access for - recording audio." requests access to the microphone - and provides an informative text for the user, why - that is needed. Before the colon, is an OS identifier - for an access right, then the informative text. Legal - values can be found on https://developer.apple.com/doc - umentation/bundleresources/information_property_list/p - rotected_resources and the option can be specified - multiple times. Default empty. - - Linux specific controls: - --linux-icon=ICON_PATH - Add executable icon for onefile binary to use. Can be - given only one time. Defaults to Python icon if - available. - - Binary Version Information: - --company-name=COMPANY_NAME - Name of the company to use in version information. - Defaults to unused. - --product-name=PRODUCT_NAME - Name of the product to use in version information. - Defaults to base filename of the binary. - --file-version=FILE_VERSION - File version to use in version information. Must be a - sequence of up to 4 numbers, e.g. 1.0 or 1.0.0.0, no - more digits are allowed, no strings are allowed. - Defaults to unused. - --product-version=PRODUCT_VERSION - Product version to use in version information. Same - rules as for file version. Defaults to unused. - --file-description=FILE_DESCRIPTION - Description of the file used in version information. - Windows only at this time. Defaults to binary - filename. - --copyright=COPYRIGHT_TEXT - Copyright used in version information. Windows only at - this time. Defaults to not present. - --trademarks=TRADEMARK_TEXT - Copyright used in version information. Windows only at - this time. Defaults to not present. - - Plugin control: - --enable-plugin=PLUGIN_NAME - Enabled plugins. Must be plug-in names. Use '--plugin- - list' to query the full list and exit. Default empty. - --disable-plugin=PLUGIN_NAME - Disabled plugins. Must be plug-in names. Use '-- - plugin-list' to query the full list and exit. Most - standard plugins are not a good idea to disable. - Default empty. - --plugin-no-detection - Plugins can detect if they might be used, and the you - can disable the warning via "--disable-plugin=plugin- - that-warned", or you can use this option to disable - the mechanism entirely, which also speeds up - compilation slightly of course as this detection code - is run in vain once you are certain of which plugins - to use. Defaults to off. - --plugin-list Show list of all available plugins and exit. Defaults - to off. - --user-plugin=PATH The file name of user plugin. Can be given multiple - times. Default empty. - --show-source-changes - Show source changes to original Python file content - before compilation. Mostly intended for developing - plugins. Default False. - - Plugin options of 'anti-bloat': - --show-anti-bloat-changes - Annotate what changes are by the plugin done. - --noinclude-setuptools-mode=NOINCLUDE_SETUPTOOLS_MODE - What to do if a 'setuptools' or import is encountered. - This package can be big with dependencies, and should - definitely be avoided. Also handles 'setuptools_scm'. - --noinclude-pytest-mode=NOINCLUDE_PYTEST_MODE - What to do if a 'pytest' import is encountered. This - package can be big with dependencies, and should - definitely be avoided. Also handles 'nose' imports. - --noinclude-unittest-mode=NOINCLUDE_UNITTEST_MODE - What to do if a unittest import is encountered. This - package can be big with dependencies, and should - definitely be avoided. - --noinclude-IPython-mode=NOINCLUDE_IPYTHON_MODE - What to do if a IPython import is encountered. This - package can be big with dependencies, and should - definitely be avoided. - --noinclude-dask-mode=NOINCLUDE_DASK_MODE - What to do if a 'dask' import is encountered. This - package can be big with dependencies, and should - definitely be avoided. - --noinclude-numba-mode=NOINCLUDE_NUMBA_MODE - What to do if a 'numba' import is encountered. This - package can be big with dependencies, and is currently - not working for standalone. This package is big with - dependencies, and should definitely be avoided. - --noinclude-default-mode=NOINCLUDE_DEFAULT_MODE - This actually provides the default "warning" value for - above options, and can be used to turn all of these - on. - --noinclude-custom-mode=CUSTOM_CHOICES - What to do if a specific import is encountered. Format - is module name, which can and should be a top level - package and then one choice, "error", "warning", - "nofollow", e.g. PyQt5:error. -``` \ No newline at end of file diff --git a/libs/pyglet_rs/README.md b/libs/pyglet_rs/README.md deleted file mode 100644 index 9a9496a..0000000 --- a/libs/pyglet_rs/README.md +++ /dev/null @@ -1,64 +0,0 @@ -# pyglet_rs - -This is a folder about pyglet_rs. - -## What is pyglet_rs? - -pyglet_rs is a python library that patches pyglet to use rust to make it faster! - -## Notice - -**This Folder may be move to an individual repo. here is just a temp location** - -## requirements -- `python 3.8+` -- `pyglet 2.0+` -- `rustc 1.68.1+` -- no more - -## status -- still writing - -## usage - -```python -import pyglet_rs -pyglet_rs.patch_sprite() - -import pyglet -... -``` - -## how to build - -```powershell -cd src -./build.ps1 -``` - -## roadmap - -- [ ] `pyglet.sprite.Sprite` patch - -- [ ] `pyglet.math.Vec2` patch (doing) - - [ ] main Calculate protocol - - [ ] other protocols -- [ ] `pyglet.math.Vec3` patch (doing) - - [ ] main Calculate protocol - - [ ] other protocols -- [ ] `pyglet.math.Vec4` patch (doing) - - [ ] main Calculate protocol - - [ ] other protocols -- [ ] `pyglet.math.Mat3(tuple)` patch (doing) - - [ ] main Calculate protocol - - [ ] other protocols -- [ ] `pyglet.math.Mat4(tuple)` patch (doing) - - [ ] main Calculate protocol - - [ ] other protocols - -## Thanks - -Great thanks to Github Copilot! -It helps me a lot in Vector and Matrix calculation and protocol implementation. -(there are A LOT of code generated by copilot) -(even this sentence is generated by copilot) \ No newline at end of file diff --git a/libs/pyglet_rs/__init__.py b/libs/pyglet_rs/__init__.py deleted file mode 100644 index 4913087..0000000 --- a/libs/pyglet_rs/__init__.py +++ /dev/null @@ -1,112 +0,0 @@ -# ------------------------------- -# Difficult Rocket -# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com -# All rights reserved -# ------------------------------- - -""" -from .lib import (get_version_str) - -from .lib import (Sprite_rs, - Vector2_rs, Vector3_rs, Vector4_rs, - Matrix3_rs, Matrix4_rs) -""" -from .lib import * - -from typing import TYPE_CHECKING, Union - -# noinspection PyUnresolvedReferences -__version__ = get_version_str() -__all__ = ['patch_sprite', 'patch_vector', 'patch_matrix', 'patch_all', - 'Sprite_rs', - 'Vector2_rs', 'Vector3_rs', 'Vector4_rs', - 'Matrix3_rs', 'Matrix4_rs'] - -if TYPE_CHECKING: - from pyglet.event import EventDispatcher - - Number = Union[int, float] - - - def get_version_str() -> str: ... - - - class Sprite_rs(EventDispatcher): ... - - - class Vector2_rs: - def __init__(self, x: Number, y: Number): ... - def __add__(self, other: "Vector2_rs") -> "Vector2_rs": ... - def __sub__(self, other: "Vector2_rs") -> "Vector2_rs": ... - def __mul__(self, other: "Vector2_rs") -> "Vector2_rs": ... - def __truediv__(self, other: "Vector2_rs") -> "Vector2_rs": ... - def __floordiv__(self, other: "Vector2_rs") -> "Vector2_rs": ... - def __repr__(self) -> str: ... - @property - def x(self) -> float: ... - @property - def y(self) -> float: ... - - - class Vector3_rs: - def __init__(self, x: Number, y: Number, z: Number): ... - def __add__(self, other: "Vector3_rs") -> "Vector3_rs": ... - def __sub__(self, other: "Vector3_rs") -> "Vector3_rs": ... - def __mul__(self, other: "Vector3_rs") -> "Vector3_rs": ... - def __truediv__(self, other: "Vector3_rs") -> "Vector3_rs": ... - def __floordiv__(self, other: "Vector3_rs") -> "Vector3_rs": ... - def __repr__(self) -> str: ... - @property - def x(self) -> float: ... - @property - def y(self) -> float: ... - @property - def z(self) -> float: ... - - - class Vector4_rs: - def __init__(self, x: Number, y: Number, z: Number, w: Number): ... - def __add__(self, other: "Vector4_rs") -> "Vector4_rs": ... - def __sub__(self, other: "Vector4_rs") -> "Vector4_rs": ... - def __mul__(self, other: "Vector4_rs") -> "Vector4_rs": ... - def __truediv__(self, other: "Vector4_rs") -> "Vector4_rs": ... - def __floordiv__(self, other: "Vector4_rs") -> "Vector4_rs": ... - def __repr__(self) -> str: ... - @property - def x(self) -> float: ... - @property - def y(self) -> float: ... - @property - def z(self) -> float: ... - @property - def w(self) -> float: ... - - - class Matrix3_rs: ... - - - class Matrix4_rs: ... - - -def patch_sprite(): - from pyglet import sprite - sprite.Sprite = Sprite_rs - - -def patch_vector(): - from pyglet import math - math.Vector2 = Vector2_rs - math.Vector3 = Vector3_rs - math.Vector4 = Vector4_rs - - -def patch_matrix(): - from pyglet import math - math.Matrix3 = Matrix3_rs - math.Matrix4 = Matrix4_rs - - -def patch_all(): - patch_sprite() - patch_vector() - patch_matrix() diff --git a/libs/pyglet_rs/src/Cargo.lock b/libs/pyglet_rs/src/Cargo.lock deleted file mode 100644 index 34a267f..0000000 --- a/libs/pyglet_rs/src/Cargo.lock +++ /dev/null @@ -1,325 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "ctor" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" -dependencies = [ - "quote", - "syn 1.0.109", -] - -[[package]] -name = "ghost" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e77ac7b51b8e6313251737fcef4b1c01a2ea102bde68415b62c0ee9268fec357" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.5", -] - -[[package]] -name = "indoc" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" - -[[package]] -name = "inventory" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "498ae1c9c329c7972b917506239b557a60386839192f1cf0ca034f345b65db99" -dependencies = [ - "ctor", - "ghost", -] - -[[package]] -name = "libc" -version = "0.2.140" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" - -[[package]] -name = "lock_api" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" -dependencies = [ - "autocfg", - "scopeguard", -] - -[[package]] -name = "memoffset" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" -dependencies = [ - "autocfg", -] - -[[package]] -name = "once_cell" -version = "1.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-sys", -] - -[[package]] -name = "proc-macro2" -version = "1.0.53" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba466839c78239c09faf015484e5cc04860f88242cff4d03eb038f04b4699b73" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "pyglet_rs" -version = "0.1.0" -dependencies = [ - "pyo3", -] - -[[package]] -name = "pyo3" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06a3d8e8a46ab2738109347433cb7b96dffda2e4a218b03ef27090238886b147" -dependencies = [ - "cfg-if", - "indoc", - "inventory", - "libc", - "memoffset", - "parking_lot", - "pyo3-build-config", - "pyo3-ffi", - "pyo3-macros", - "unindent", -] - -[[package]] -name = "pyo3-build-config" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75439f995d07ddfad42b192dfcf3bc66a7ecfd8b4a1f5f6f046aa5c2c5d7677d" -dependencies = [ - "once_cell", - "target-lexicon", -] - -[[package]] -name = "pyo3-ffi" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "839526a5c07a17ff44823679b68add4a58004de00512a95b6c1c98a6dcac0ee5" -dependencies = [ - "libc", - "pyo3-build-config", -] - -[[package]] -name = "pyo3-macros" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd44cf207476c6a9760c4653559be4f206efafb924d3e4cbf2721475fc0d6cc5" -dependencies = [ - "proc-macro2", - "pyo3-macros-backend", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "pyo3-macros-backend" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1f43d8e30460f36350d18631ccf85ded64c059829208fe680904c65bcd0a4c" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "quote" -version = "1.0.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags", -] - -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "smallvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89c2d1c76a26822187a1fbb5964e3fff108bc208f02e820ab9dac1234f6b388a" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "target-lexicon" -version = "0.12.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae9980cab1db3fceee2f6c6f643d5d8de2997c58ee8d25fb0cc8a9e9e7348e5" - -[[package]] -name = "unicode-ident" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" - -[[package]] -name = "unindent" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1766d682d402817b5ac4490b3c3002d91dfa0d22812f341609f97b08757359c" - -[[package]] -name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" diff --git a/libs/pyglet_rs/src/Cargo.toml b/libs/pyglet_rs/src/Cargo.toml deleted file mode 100644 index 07dcb65..0000000 --- a/libs/pyglet_rs/src/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "pyglet_rs" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[lib] -name = 'pyglet_rs' -crate-type = ["cdylib"] - -[profile.release] -codegen-units = 1 - -[dependencies.pyo3] -version = "0.18.1" -features = ["extension-module", "multiple-pymethods"] diff --git a/libs/pyglet_rs/src/build.ps1 b/libs/pyglet_rs/src/build.ps1 deleted file mode 100644 index 4394df1..0000000 --- a/libs/pyglet_rs/src/build.ps1 +++ /dev/null @@ -1 +0,0 @@ -cargo fmt;python3.8 .\setup.py build; python .\post_build.py diff --git a/libs/pyglet_rs/src/post_build.py b/libs/pyglet_rs/src/post_build.py deleted file mode 100644 index ead64fd..0000000 --- a/libs/pyglet_rs/src/post_build.py +++ /dev/null @@ -1,41 +0,0 @@ -# ------------------------------- -# Difficult Rocket -# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com -# All rights reserved -# ------------------------------- -import os -import shutil -import warnings -import traceback - -package_path = 'pyglet_rs' -lib_path = '../lib' -build_path = 'build' - -if not os.path.exists(lib_path): - os.mkdir(lib_path) - -builds = os.listdir(build_path) -print(os.path.abspath('.')) - -try: - shutil.copy('src/__init__.py', os.path.join(lib_path, '__init__.py')) -except shutil.SameFileError: - traceback.print_exc() - -for build_dir in builds: - if not os.path.exists(os.path.join(build_path, build_dir, package_path)): - warnings.warn(f'package not found at {build_path}/{build_dir}') - continue - for file in os.listdir(os.path.join(build_path, build_dir, package_path)): - # file_name = os.path.join(lib_path, file.replace(package_path, f'{package_path}.{DR_runtime.DR_Rust_version}')) - file_name = os.path.join(lib_path, file) - shutil.rmtree(file_name, ignore_errors=True) - try: - shutil.copy(os.path.join(build_path, build_dir, package_path, file), file_name) - except (shutil.SameFileError, PermissionError): - # print(os.path.exists(os.path)) - print(os.listdir(lib_path)) - traceback.print_exc() - continue - print(os.path.abspath(file_name)) diff --git a/libs/pyglet_rs/src/setup.py b/libs/pyglet_rs/src/setup.py deleted file mode 100644 index ba38dd8..0000000 --- a/libs/pyglet_rs/src/setup.py +++ /dev/null @@ -1,39 +0,0 @@ -# ------------------------------- -# Difficult Rocket -# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com -# All rights reserved -# ------------------------------- -import os -import sys -import rtoml -import shutil -from setuptools import setup -from setuptools_rust import Binding, RustExtension - -sys.path.append('../../../') -sys.path.append(os.curdir) - -package_path = 'pyglet_rs' - -# 版本号从 cargo.toml 中读取 -with open(f'Cargo.toml', 'r') as f: - cargo_toml = rtoml.load(f) - version = cargo_toml['package']['version'] - -setup( - name='pyglet_rs', - version=version, - author='shenjackyuanjie', - author_email='3695888@qq.com', - rust_extensions=[RustExtension(target="pyglet_rs.pyglet_rs", - binding=Binding.PyO3)], - zip_safe=False, -) - -lib_path = '../lib' -build_path = 'build' - -if 'clean' in sys.argv: - shutil.rmtree(build_path, ignore_errors=True) - shutil.rmtree(f'{package_path}.egg-info', ignore_errors=True) - sys.exit(0) diff --git a/libs/pyglet_rs/src/src/__init__.py b/libs/pyglet_rs/src/src/__init__.py deleted file mode 100644 index 5387515..0000000 --- a/libs/pyglet_rs/src/src/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -# ------------------------------- -# Difficult Rocket -# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com -# All rights reserved -# ------------------------------- - -from typing import TYPE_CHECKING - -if not TYPE_CHECKING: - from .pyglet_rs import * diff --git a/libs/pyglet_rs/src/src/lib.rs b/libs/pyglet_rs/src/src/lib.rs deleted file mode 100644 index a64836c..0000000 --- a/libs/pyglet_rs/src/src/lib.rs +++ /dev/null @@ -1,30 +0,0 @@ -/* - * ------------------------------- - * Difficult Rocket - * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com - * All rights reserved - * ------------------------------- - */ - -mod math; -mod pymath; -mod sprite; - -use pyo3::prelude::*; - -#[pyfunction] -fn get_version_str() -> String { - return "0.1.0".to_string(); -} - -#[pymodule] -#[pyo3(name = "pyglet_rs")] -fn module_init(_py: Python<'_>, m: &PyModule) -> PyResult<()> { - m.add_function(wrap_pyfunction!(get_version_str, m)?)?; - m.add_class::()?; - // vector - m.add_class::()?; - m.add_class::()?; - m.add_class::()?; - Ok(()) -} diff --git a/libs/pyglet_rs/src/src/math.rs b/libs/pyglet_rs/src/src/math.rs deleted file mode 100644 index 09b6554..0000000 --- a/libs/pyglet_rs/src/src/math.rs +++ /dev/null @@ -1,395 +0,0 @@ -/* - * ------------------------------- - * Difficult Rocket - * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com - * All rights reserved - * ------------------------------- - */ - -pub mod vector { - use std::ops::{Add, Div, Mul, Sub}; - - #[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] - pub struct Vector2 { - pub x: f64, - pub y: f64, - } - - #[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] - pub struct Vector3 { - pub x: f64, - pub y: f64, - pub z: f64, - } - - #[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] - pub struct Vector4 { - pub x: f64, - pub y: f64, - pub z: f64, - pub w: f64, - } - - pub trait VectorTrait { - fn len(&self) -> i8; // use short int to save memory (even if its not going to save a lot) - fn floordiv(&self, other: &Self) -> Self; - fn abs(&self) -> f64; - fn neg(&self) -> Self; - fn dot(&self, other: &Self) -> f64; - fn round(&self, ndigits: Option) -> Self; - fn clamp(&self, min: f64, max: f64) -> Self; - fn distance(&self, other: &Self) -> f64; - fn normalize(&self) -> Self; - // from - fn from_same(len: f64) -> Self; - } - - impl Add for Vector2 { - type Output = Self; - - fn add(self, rhs: Self) -> Self::Output { - Self::new(self.x + rhs.x, self.y + rhs.y) - } - } - - impl Sub for Vector2 { - type Output = Self; - - fn sub(self, rhs: Self) -> Self::Output { - Self::new(self.x - rhs.x, self.y - rhs.y) - } - } - - impl Mul for Vector2 { - type Output = Self; - - fn mul(self, rhs: Self) -> Self::Output { - Self::new(self.x * rhs.x, self.y * rhs.y) - } - } - - impl Div for Vector2 { - type Output = Self; - - fn div(self, rhs: Self) -> Self::Output { - Self::new(self.x / rhs.x, self.y / rhs.y) - } - } - - impl Add for Vector3 { - type Output = Self; - - fn add(self, rhs: Self) -> Self::Output { - Self::new(self.x + rhs.x, self.y + rhs.y, self.z + rhs.z) - } - } - - impl Sub for Vector3 { - type Output = Self; - - fn sub(self, rhs: Self) -> Self::Output { - Self::new(self.x - rhs.x, self.y - rhs.y, self.z - rhs.z) - } - } - - impl Mul for Vector3 { - type Output = Self; - - fn mul(self, rhs: Self) -> Self::Output { - Self::new(self.x * rhs.x, self.y * rhs.y, self.z * rhs.z) - } - } - - impl Div for Vector3 { - type Output = Self; - - fn div(self, rhs: Self) -> Self::Output { - Self::new(self.x / rhs.x, self.y / rhs.y, self.z / rhs.z) - } - } - - impl Add for Vector4 { - type Output = Self; - - fn add(self, rhs: Self) -> Self::Output { - Self::new( - self.x + rhs.x, - self.y + rhs.y, - self.z + rhs.z, - self.w + rhs.w, - ) - } - } - - impl Sub for Vector4 { - type Output = Self; - - fn sub(self, rhs: Self) -> Self::Output { - Self::new( - self.x - rhs.x, - self.y - rhs.y, - self.z - rhs.z, - self.w - rhs.w, - ) - } - } - - impl Mul for Vector4 { - type Output = Self; - - fn mul(self, rhs: Self) -> Self::Output { - Self::new( - self.x * rhs.x, - self.y * rhs.y, - self.z * rhs.z, - self.w * rhs.w, - ) - } - } - - impl Div for Vector4 { - type Output = Self; - - fn div(self, rhs: Self) -> Self::Output { - Self::new( - self.x / rhs.x, - self.y / rhs.y, - self.z / rhs.z, - self.w / rhs.w, - ) - } - } - - impl VectorTrait for Vector2 { - fn len(&self) -> i8 { - return 2; - } - fn floordiv(&self, other: &Self) -> Self { - // 手动模拟python的//运算符 - Self::new((self.x / other.x).floor(), (self.y / other.y).floor()) - } - - fn abs(&self) -> f64 { - return (self.x.powi(2) + self.y.powi(2)).sqrt(); - } - - fn neg(&self) -> Self { - Self::new(-self.x, -self.y) - } - - fn dot(&self, other: &Self) -> f64 { - self.x * other.x + self.y * other.y - } - - fn round(&self, ndigits: Option) -> Self { - match ndigits { - Some(ndigits) => { - let ndigits = ndigits as i32; - Self::new( - self.x.round() * 10.0_f64.powi(ndigits), - self.y.round() * 10.0_f64.powi(ndigits), - ) - } - None => Self::new(self.x.round(), self.y.round()), - } - } - - fn clamp(&self, min: f64, max: f64) -> Self { - Self::new(self.x.clamp(min, max), self.y.clamp(min, max)) - } - - fn distance(&self, other: &Self) -> f64 { - (*self - *other).abs() - } - - fn normalize(&self) -> Self { - let d = self.abs(); - return if d != 0.0 { - Self::new(self.x / d, self.y / d) - } else { - self.clone() - }; - } - - fn from_same(len: f64) -> Self { - Self::new(len, len) - } - } - - impl VectorTrait for Vector3 { - fn len(&self) -> i8 { - return 3; - } - - fn floordiv(&self, other: &Self) -> Self { - // 手动模拟python的//运算符 - Self::new( - (self.x / other.x).floor(), - (self.y / other.y).floor(), - (self.z / other.z).floor(), - ) - } - - fn abs(&self) -> f64 { - return (self.x.powi(2) + self.y.powi(2) + self.z.powi(2)).sqrt(); - } - - fn neg(&self) -> Self { - Self::new(-self.x, -self.y, -self.z) - } - - fn dot(&self, other: &Self) -> f64 { - self.x * other.x + self.y * other.y + self.z * other.z - } - - fn round(&self, ndigits: Option) -> Self { - match ndigits { - Some(ndigits) => { - let ndigits = ndigits as i32; - Self::new( - self.x.round() * 10.0_f64.powi(ndigits), - self.y.round() * 10.0_f64.powi(ndigits), - self.z.round() * 10.0_f64.powi(ndigits), - ) - } - None => Self::new(self.x.round(), self.y.round(), self.z.round()), - } - } - - fn clamp(&self, min: f64, max: f64) -> Self { - Self::new( - self.x.clamp(min, max), - self.y.clamp(min, max), - self.z.clamp(min, max), - ) - } - - fn distance(&self, other: &Self) -> f64 { - (*self - *other).abs() - } - - fn normalize(&self) -> Self { - let d = self.abs(); - return if d != 0.0 { - Self::new(self.x / d, self.y / d, self.z / d) - } else { - self.clone() - }; - } - - fn from_same(len: f64) -> Self { - Self::new(len, len, len) - } - } - - impl VectorTrait for Vector4 { - fn len(&self) -> i8 { - return 4; - } - - fn floordiv(&self, other: &Self) -> Self { - // 手动模拟python的//运算符 - Self::new( - (self.x / other.x).floor(), - (self.y / other.y).floor(), - (self.z / other.z).floor(), - (self.w / other.w).floor(), - ) - } - - fn abs(&self) -> f64 { - return (self.x.powi(2) + self.y.powi(2) + self.z.powi(2) + self.w.powi(2)).sqrt(); - } - - fn neg(&self) -> Self { - Self::new(-self.x, -self.y, -self.z, -self.w) - } - - fn dot(&self, other: &Self) -> f64 { - self.x * other.x + self.y * other.y + self.z * other.z + self.w * other.w - } - - fn round(&self, ndigits: Option) -> Self { - match ndigits { - Some(ndigits) => { - let ndigits = ndigits as i32; - Self::new( - self.x.round() * 10.0_f64.powi(ndigits), - self.y.round() * 10.0_f64.powi(ndigits), - self.z.round() * 10.0_f64.powi(ndigits), - self.w.round() * 10.0_f64.powi(ndigits), - ) - } - None => Self::new( - self.x.round(), - self.y.round(), - self.z.round(), - self.w.round(), - ), - } - } - - fn clamp(&self, min: f64, max: f64) -> Self { - Self::new( - self.x.clamp(min, max), - self.y.clamp(min, max), - self.z.clamp(min, max), - self.w.clamp(min, max), - ) - } - - fn distance(&self, other: &Self) -> f64 { - (*self - *other).abs() - } - - fn normalize(&self) -> Self { - let d = self.abs(); - return if d != 0.0 { - Self::new(self.x / d, self.y / d, self.z / d, self.w / d) - } else { - self.clone() - }; - } - - fn from_same(len: f64) -> Self { - Self::new(len, len, len, len) - } - } - - impl Vector2 { - pub fn new(x: f64, y: f64) -> Self { - Self { x, y } - } - } - - impl Vector3 { - pub fn new(x: f64, y: f64, z: f64) -> Self { - Self { x, y, z } - } - } - - impl Vector4 { - pub fn new(x: f64, y: f64, z: f64, w: f64) -> Self { - Self { x, y, z, w } - } - } -} - -pub mod matrix { - use super::vector::{Vector3, Vector4}; - - #[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] - pub struct Matrix3 { - pub line1: Vector3, - pub line2: Vector3, - pub line3: Vector3, - } - - #[derive(Debug, Clone, Copy, PartialEq, PartialOrd)] - pub struct Matrix4 { - pub line1: Vector4, - pub line2: Vector4, - pub line3: Vector4, - pub line4: Vector4, - } -} diff --git a/libs/pyglet_rs/src/src/pymath.rs b/libs/pyglet_rs/src/src/pymath.rs deleted file mode 100644 index fcfd682..0000000 --- a/libs/pyglet_rs/src/src/pymath.rs +++ /dev/null @@ -1,354 +0,0 @@ -/* - * ------------------------------- - * Difficult Rocket - * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com - * All rights reserved - * ------------------------------- - */ - -pub mod python_class { - use pyo3::class::basic::CompareOp; - use pyo3::prelude::*; - use pyo3::types::PySlice; - - use crate::math::matrix::{Matrix3, Matrix4}; - use crate::math::vector::{Vector2, Vector3, Vector4, VectorTrait}; - - #[derive(Clone)] - #[pyclass(name = "Vector2_rs")] - pub struct PyVector2 { - pub data: Vector2, - } - - #[derive(Clone)] - #[pyclass(name = "Vector3_rs")] - pub struct PyVector3 { - pub data: Vector3, - } - - #[derive(Clone)] - #[pyclass(name = "Vector4_rs")] - pub struct PyVector4 { - pub data: Vector4, - } - - #[derive(Clone)] - #[pyclass(name = "Matrix3_rs")] - pub struct PyMatrix3 { - pub data: Matrix3, - } - - #[derive(Clone)] - #[pyclass(name = "Matrix4_rs")] - pub struct PyMatrix4 { - pub data: Matrix4, - } - - #[allow(unused)] - pub trait PyCalc { - fn __add__(&self, other: &Self) -> Self; - fn __sub__(&self, other: &Self) -> Self; - fn __mul__(&self, other: &Self) -> Self; - fn __truediv__(&self, other: &Self) -> Self; - fn __floordiv__(&self, other: &Self) -> Self; - fn __abs__(&self) -> f64; - fn __neg__(&self) -> Self; - fn __round__(&self, ndigits: Option) -> Self; - fn __radd__(&self, other: &PyAny) -> Self; - // fn rotate - } - - /// 这是一个用来自动给 impl xxx for xxx 的块去掉 trait 部分的宏 - /// 用于在为 pyclass 实现 - - #[pymethods] - impl PyVector2 { - #[new] - fn py_new(x: f64, y: f64) -> Self { - return Self { - data: Vector2::new(x, y), - }; - } - - fn __add__(&self, other: &Self) -> Self { - return Self { - data: self.data + other.data, - }; - } - - fn __radd__(&self, other: &PyAny) -> Self { - return if other.is_instance_of::().unwrap() { - Self { - data: self.data + other.extract::().unwrap().data, - } - } else { - // if other == 0 - if other.is_none() { - self.clone() - } else { - Self { - data: self.data + Vector2::from_same(other.extract::().unwrap()), - } - } - }; - } - - fn __sub__(&self, other: &Self) -> Self { - return Self { - data: self.data - other.data, - }; - } - - fn __mul__(&self, other: &Self) -> Self { - return Self { - data: self.data * other.data, - }; - } - - fn __truediv__(&self, other: &Self) -> Self { - return Self { - data: self.data / other.data, - }; - } - - fn __floordiv__(&self, other: &Self) -> Self { - return Self { - data: self.data.floordiv(&other.data), - }; - } - - fn __richcmp__(&self, other: &Self, op: CompareOp) -> PyResult { - match op { - CompareOp::Lt => Ok(self.data < other.data), - CompareOp::Le => Ok(self.data <= other.data), - CompareOp::Eq => Ok(self.data == other.data), - CompareOp::Ne => Ok(self.data != other.data), - CompareOp::Gt => Ok(self.data > other.data), - CompareOp::Ge => Ok(self.data >= other.data), - } - } - - fn __repr__(&self) -> String { - return format!("Vector2_rs({}, {})", self.data.x, self.data.y); - } - - // fn __getitem__(&self, item: &PyAny) -> PyResult<&PyAny> { - // if item.is_instance_of::().unwrap() { - // let item = item.extract::().unwrap(); - // let indices = item.indices().unwrap(); - // } - // } - - // getter and setter - - #[getter] - fn get_x(&self) -> f64 { - return self.data.x; - } - - #[getter] - fn get_y(&self) -> f64 { - return self.data.y; - } - - #[setter] - fn set_x(&mut self, x: f64) { - self.data.x = x; - } - - #[setter] - fn set_y(&mut self, y: f64) { - self.data.y = y; - } - } - - #[pymethods] - impl PyVector3 { - #[new] - fn py_new(x: f64, y: f64, z: f64) -> Self { - return Self { - data: Vector3::new(x, y, z), - }; - } - - fn __add__(&self, other: &Self) -> Self { - return Self { - data: self.data + other.data, - }; - } - - fn __sub__(&self, other: &Self) -> Self { - return Self { - data: self.data - other.data, - }; - } - - fn __mul__(&self, other: &Self) -> Self { - return Self { - data: self.data * other.data, - }; - } - - fn __truediv__(&self, other: &Self) -> Self { - return Self { - data: self.data / other.data, - }; - } - - fn __floordiv__(&self, other: &Self) -> Self { - return Self { - data: self.data.floordiv(&other.data), - }; - } - - fn __richcmp__(&self, other: &Self, op: CompareOp) -> PyResult { - match op { - CompareOp::Lt => Ok(self.data < other.data), - CompareOp::Le => Ok(self.data <= other.data), - CompareOp::Eq => Ok(self.data == other.data), - CompareOp::Ne => Ok(self.data != other.data), - CompareOp::Gt => Ok(self.data > other.data), - CompareOp::Ge => Ok(self.data >= other.data), - } - } - - fn __repr__(&self) -> String { - return format!( - "Vector3_rs({}, {}, {})", - self.data.x, self.data.y, self.data.z - ); - } - - // getter and setter - - #[getter] - fn get_x(&self) -> f64 { - return self.data.x; - } - - #[getter] - fn get_y(&self) -> f64 { - return self.data.y; - } - - #[getter] - fn get_z(&self) -> f64 { - return self.data.z; - } - - #[setter] - fn set_x(&mut self, x: f64) { - self.data.x = x; - } - - #[setter] - fn set_y(&mut self, y: f64) { - self.data.y = y; - } - - #[setter] - fn set_z(&mut self, z: f64) { - self.data.z = z; - } - } - - #[pymethods] - impl PyVector4 { - #[new] - fn py_new(x: f64, y: f64, z: f64, w: f64) -> Self { - return Self { - data: Vector4::new(x, y, z, w), - }; - } - - fn __add__(&self, other: &Self) -> Self { - return Self { - data: self.data + other.data, - }; - } - - fn __sub__(&self, other: &Self) -> Self { - return Self { - data: self.data - other.data, - }; - } - - fn __mul__(&self, other: &Self) -> Self { - return Self { - data: self.data * other.data, - }; - } - - fn __truediv__(&self, other: &Self) -> Self { - return Self { - data: self.data / other.data, - }; - } - - fn __floordiv__(&self, other: &Self) -> Self { - return Self { - data: self.data.floordiv(&other.data), - }; - } - - fn __richcmp__(&self, other: &Self, op: CompareOp) -> PyResult { - match op { - CompareOp::Lt => Ok(self.data < other.data), - CompareOp::Le => Ok(self.data <= other.data), - CompareOp::Eq => Ok(self.data == other.data), - CompareOp::Ne => Ok(self.data != other.data), - CompareOp::Gt => Ok(self.data > other.data), - CompareOp::Ge => Ok(self.data >= other.data), - } - } - - fn __repr__(&self) -> String { - return format!( - "Vector4_rs({}, {}, {}, {})", - self.data.x, self.data.y, self.data.z, self.data.w - ); - } - - // getter and setter - - #[getter] - fn get_x(&self) -> f64 { - return self.data.x; - } - - #[getter] - fn get_y(&self) -> f64 { - return self.data.y; - } - - #[getter] - fn get_z(&self) -> f64 { - return self.data.z; - } - - #[getter] - fn get_w(&self) -> f64 { - return self.data.w; - } - - #[setter] - fn set_x(&mut self, x: f64) { - self.data.x = x; - } - - #[setter] - fn set_y(&mut self, y: f64) { - self.data.y = y; - } - - #[setter] - fn set_z(&mut self, z: f64) { - self.data.z = z; - } - - #[setter] - fn set_w(&mut self, w: f64) { - self.data.w = w; - } - } -} diff --git a/libs/pyglet_rs/src/src/sprite.rs b/libs/pyglet_rs/src/src/sprite.rs deleted file mode 100644 index 4d877c4..0000000 --- a/libs/pyglet_rs/src/src/sprite.rs +++ /dev/null @@ -1,226 +0,0 @@ -/* - * ------------------------------- - * Difficult Rocket - * Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com - * All rights reserved - * ------------------------------- - */ - -use pyo3::intern; -use pyo3::prelude::*; -// use pyo3::types::PyDict; - -/// Instance of an on-screen image -/// See the module documentation for usage. -#[pyclass(name = "Sprite_rs", subclass)] -#[pyo3(text_signature = "(img, x=0.0, y=0.0, z=0.0, \ - blend_src=770, blend_dest=771, \ - batch=None, group=None, \ - subpixel=False, program=None)")] -pub struct Sprite { - // render - pub subpixel: bool, - pub batch: Py, - pub group: Option>, - pub user_group: Option>, - pub group_class: Py, - // view - pub x: f64, - pub y: f64, - pub z: f64, - pub scale: f64, - pub scale_x: f64, - pub scale_y: f64, - pub visible: bool, - pub vertex_list: Option>, - // frame - pub frame_index: u32, - pub next_dt: f64, - #[pyo3(get)] - pub program: Option>, - pub animation: Option>, - pub texture: Option>, - pub paused: bool, - // other - pub rotation: f64, - pub rgba: (u8, u8, u8, u8), -} - -#[pymethods] -impl Sprite { - /// python code: - /// 366: - /// if isinstance(img, image.Animation): - /// self._animation = img - /// self._texture = img.frames[0].image.get_texture() - /// self._next_dt = img.frames[0].duration - /// if self._next_dt: - /// clock.schedule_once(self._animate, self._next_dt) - /// else: - /// self._texture = img.get_texture() - /// 375: - /// if not program: - /// if isinstance(img, image.TextureArrayRegion): - /// self._program = get_default_array_shader() - /// else: - /// self._program = get_default_shader() - /// else: - /// self._program = program - /// 383: - /// self._batch = batch or graphics.get_default_batch() - /// self._user_group = group - /// self._group = self.group_class(self._texture, blend_src, blend_dest, self.program, group) - /// self._subpixel = subpixel - /// 387: - /// self._create_vertex_list() - #[new] - fn new( - py_: Python, - img: &PyAny, - x: f64, - y: f64, - z: f64, - blend_src: u32, // default 770 (GL_SRC_ALPHA) - blend_dest: u32, // default 771 (GL_ONE_MINUS_SRC_ALPHA) - batch_: &PyAny, - group: &PyAny, - subpixel: bool, - program_: &PyAny, - ) -> Self { - let texture; - let batch; - let mut next_dt = 0.0; - let mut animation = None; - let mut program = program_; - let sprite_group_class = PyModule::import(py_, "pyglet.sprite") - .unwrap() - .getattr("SpriteGroup") - .unwrap(); - // 366 - let animation_class = PyModule::import(py_, "pyglet.image.Animation") - .unwrap() - .getattr("Animation") - .unwrap(); - if img.is_instance(animation_class).unwrap() { - animation = Some(img.into()); - texture = img - .getattr(intern!(img.py(), "frames")) - .unwrap() - .get_item(0) - .unwrap() - .getattr(intern!(img.py(), "image")) - .unwrap() - .call_method0(intern!(img.py(), "get_texture")) - .unwrap(); - let _next_dt = img - .getattr(intern!(img.py(), "frames")) - .unwrap() - .get_item(0) - .unwrap() - .getattr(intern!(img.py(), "duration")); - next_dt = match _next_dt { - Ok(v) => v.extract().unwrap(), - Err(_) => 0.0, - } - // 372 - } else { - texture = img.call_method0(intern!(img.py(), "get_texture")).unwrap(); - } - // 375 - if !program.is_true().unwrap() { - let texture_array_region_class = - PyModule::import(py_, "pyglet.image.TextureArrayRegion") - .unwrap() - .getattr("TextureArrayRegion") - .unwrap(); - if img.is_instance(texture_array_region_class).unwrap() { - // self._program = get_default_array_shader() - let get_default_array_shader = PyModule::import(py_, "pyglet.sprite") - .unwrap() - .getattr("get_default_array_shader") - .unwrap(); - program = get_default_array_shader.call0().unwrap(); - } else { - // self._program = get_default_shader() - let get_default_shader = PyModule::import(py_, "pyglet.sprite") - .unwrap() - .getattr("get_default_shader") - .unwrap(); - program = get_default_shader.call0().unwrap(); - } - } - // 383 - if !batch_.is_none() { - batch = PyModule::import(py_, "pyglet.graphics") - .unwrap() - .getattr("get_default_batch") - .unwrap() - .call0() - .unwrap(); - } else { - batch = batch_; - } - // 385 - let group = sprite_group_class - .call1((texture, blend_src, blend_dest, program, group)) - .unwrap(); - - Sprite { - subpixel, - batch: batch.into(), - group: Some(group.into()), - user_group: Some(group.into()), - group_class: group.into(), - x, - y, - z, - scale: 1.0, - scale_x: 1.0, - scale_y: 1.0, - visible: true, - vertex_list: None, - frame_index: 0, - next_dt, - program: Some(program.into()), - animation: animation, - texture: Some(texture.into()), - paused: false, - rotation: 0.0, - rgba: (255, 255, 255, 255), - } - } - - // python code: - // 390: - // def _create_vertex_list(self): - // texture = self._texture - // self._vertex_list = self.program.vertex_list( - // 1, GL_POINTS, self._batch, self._group, - // position=('f', (self._x, self._y, self._z)), - // size=('f', (texture.width, texture.height, 1, 1)), - // color=('Bn', self._rgba), - // texture_uv=('f', texture.uv), - // rotation=('f', (self._rotation,))) - - // pub fn _create_vertex_list(&mut self) -> PyResult<()> { - // let texture = self.texture.as_ref()?; - // Python::with_gil(|py| -> PyResult<()> { - // let args = PyDict::new(py); - // args.set_item("position", (self.x, self.y, self.z))?; - // args.set_item( - // "size", - // ( - // texture.getattr(py, "width")?, - // texture.getattr(py, "height")?, - // 1, - // 1, - // ), - // )?; - // args.set_item("color", ("Bn", self.rgba))?; - // args.set_item("texture_uv", texture.getattr(py, "uv")?)?; - // args.set_item("rotation", (self.rotation,))?; - // Ok(()) - // })?; - // Ok(()) - // } -} diff --git a/libs/pyglet_rs/src/test/vector.py b/libs/pyglet_rs/src/test/vector.py deleted file mode 100644 index 58a749b..0000000 --- a/libs/pyglet_rs/src/test/vector.py +++ /dev/null @@ -1,71 +0,0 @@ -# ------------------------------- -# Difficult Rocket -# Copyright © 2020-2023 by shenjackyuanjie 3695888@qq.com -# All rights reserved -# ------------------------------- - -import random -import unittest - -from typing import Tuple - -from libs.pyglet_rs import Vector2_rs, Vector3_rs, Vector4_rs - - -# 用于自动在测试运行前后输出测试信息的装饰器 -def print_test_info(func): - def wrapper(*args, **kwargs): - print(f"{'=' * 20} {func.__name__} {'=' * 20}") - func(*args, **kwargs) - print(f"{'=' * 20} {func.__name__} {'=' * 20}") - - return wrapper - - -def gen_random_vector() -> Tuple[Vector2_rs, Vector3_rs, Vector4_rs]: - vec2 = Vector2_rs(random.randint(1, 100), random.randint(1, 100)) - vec3 = Vector3_rs(random.randint(1, 100), random.randint(1, 100), random.randint(1, 100)) - vec4 = Vector4_rs(random.randint(1, 100), random.randint(1, 100), random.randint(1, 100), random.randint(1, 100)) - return vec2, vec3, vec4 - - -class TestVector(unittest.TestCase): - - @print_test_info - def test1_create_print_vector(self): - vec2, vec3, vec4 = gen_random_vector() - - print(f"{vec2=}") - print(f"{vec3=}") - print(f"{vec4=}") - - @print_test_info - def test2_calculate_vector(self): - vec2, vec3, vec4 = gen_random_vector() - vec2_1, vec3_1, vec4_1 = gen_random_vector() - - print('test add') - self.assertEqual(vec2 + vec2_1, Vector2_rs(vec2.x + vec2_1.x, vec2.y + vec2_1.y)) - self.assertEqual(vec3 + vec3_1, Vector3_rs(vec3.x + vec3_1.x, vec3.y + vec3_1.y, vec3.z + vec3_1.z)) - self.assertEqual(vec4 + vec4_1, Vector4_rs(vec4.x + vec4_1.x, vec4.y + vec4_1.y, vec4.z + vec4_1.z, vec4.w + vec4_1.w)) - - print('test sub') - self.assertEqual(vec2 - vec2_1, Vector2_rs(vec2.x - vec2_1.x, vec2.y - vec2_1.y)) - self.assertEqual(vec3 - vec3_1, Vector3_rs(vec3.x - vec3_1.x, vec3.y - vec3_1.y, vec3.z - vec3_1.z)) - self.assertEqual(vec4 - vec4_1, Vector4_rs(vec4.x - vec4_1.x, vec4.y - vec4_1.y, vec4.z - vec4_1.z, vec4.w - vec4_1.w)) - - print('test mul') - self.assertEqual(vec2 * vec2_1, Vector2_rs(vec2.x * vec2_1.x, vec2.y * vec2_1.y)) - self.assertEqual(vec3 * vec3_1, Vector3_rs(vec3.x * vec3_1.x, vec3.y * vec3_1.y, vec3.z * vec3_1.z)) - self.assertEqual(vec4 * vec4_1, Vector4_rs(vec4.x * vec4_1.x, vec4.y * vec4_1.y, vec4.z * vec4_1.z, vec4.w * vec4_1.w)) - - print('test true_div') - self.assertEqual(vec2 / vec2_1, Vector2_rs(vec2.x / vec2_1.x, vec2.y / vec2_1.y)) - self.assertEqual(vec3 / vec3_1, Vector3_rs(vec3.x / vec3_1.x, vec3.y / vec3_1.y, vec3.z / vec3_1.z)) - self.assertEqual(vec4 / vec4_1, Vector4_rs(vec4.x / vec4_1.x, vec4.y / vec4_1.y, vec4.z / vec4_1.z, vec4.w / vec4_1.w)) - - print('test floor_div') - self.assertEqual(vec2 // vec2_1, Vector2_rs(vec2.x // vec2_1.x, vec2.y // vec2_1.y)) - self.assertEqual(vec3 // vec3_1, Vector3_rs(vec3.x // vec3_1.x, vec3.y // vec3_1.y, vec3.z // vec3_1.z)) - self.assertEqual(vec4 // vec4_1, Vector4_rs(vec4.x // vec4_1.x, vec4.y // vec4_1.y, vec4.z // vec4_1.z, vec4.w // vec4_1.w)) - diff --git a/libs/utils/nuitka.py b/libs/utils/nuitka.py index 1733cd3..8c77f3e 100644 --- a/libs/utils/nuitka.py +++ b/libs/utils/nuitka.py @@ -8,7 +8,7 @@ import platform import traceback from pathlib import Path -from typing import List, Tuple, Optional +from typing import List, Tuple from Difficult_Rocket.api.types import Options, Version @@ -28,7 +28,6 @@ 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 @@ -39,11 +38,8 @@ class CompilerHelper(Options): company_name: str = 'tool-shenjack-workshop' product_name: str = 'Difficult-Rocket' - 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 + file_version: Version icon_path: Path = Path('textures/icon.png') @@ -55,9 +51,6 @@ class CompilerHelper(Options): ('./configs', './configs')] include_packages: List[str] = ['Difficult_Rocket.api'] - enable_plugin: List[str] = [] # --enable-plugin=xxx,xxx - disable_plugin: List[str] = [] # --disable-plugin=xxx,xxx - def init(self, **kwargs) -> None: # 非 windows 平台不使用 msvc if platform.system() != 'Windows': @@ -80,8 +73,8 @@ class CompilerHelper(Options): def __str__(self): return self.as_markdown() - def as_markdown(self, longest: Optional[int] = None) -> str: - front = super().as_markdown(longest) + def as_markdown(self) -> str: + front = super().as_markdown() gen_cmd = self.gen_subprocess_cmd() return f"{front}\n\n```bash\n{' '.join(gen_cmd)}\n```" @@ -91,22 +84,14 @@ 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: @@ -128,10 +113,8 @@ 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"--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}") + cmd_list.append(f"--file-version={self.file_version}") if icon_cmd: cmd_list.append(icon_cmd) @@ -142,8 +125,5 @@ class CompilerHelper(Options): cmd_list.append(f"--follow-import-to={','.join(self.follow_import)}") cmd_list.append(f"--nofollow-import-to={','.join(self.no_follow_import)}") - cmd_list.append(f"--enable-plugin={','.join(self.enable_plugin)}") - cmd_list.append(f"--disable-plugin={','.join(self.disable_plugin)}") - cmd_list.append(f"{self.src_file}") return cmd_list diff --git a/nuitka_build.py b/nuitka_build.py index 6fdc980..b27137b 100644 --- a/nuitka_build.py +++ b/nuitka_build.py @@ -79,11 +79,9 @@ if __name__ == '__main__': if f'pyglet.{lib}.{name}' in compiler.no_follow_import: compiler.no_follow_import.remove(f'pyglet.{lib}.{name}') - print(compiler.as_markdown(longest=70)) + print(compiler.output_path) - if is_github: - from pprint import pprint - pprint(compiler.option()) + print(compiler) print(compiler.gen_subprocess_cmd())