pytron-kit 0.3.12__py3-none-macosx_11_0_universal2.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytron/__init__.py +112 -0
- pytron/application.py +562 -0
- pytron/apputils/__init__.py +0 -0
- pytron/apputils/chrome_ipc.py +203 -0
- pytron/apputils/codegen.py +261 -0
- pytron/apputils/config.py +303 -0
- pytron/apputils/deadmansswitch.py +47 -0
- pytron/apputils/extras.py +76 -0
- pytron/apputils/native.py +148 -0
- pytron/apputils/shell.py +73 -0
- pytron/apputils/windows.py +286 -0
- pytron/cli.py +384 -0
- pytron/commands/__init__.py +0 -0
- pytron/commands/android.py +28 -0
- pytron/commands/build.py +26 -0
- pytron/commands/doctor.py +221 -0
- pytron/commands/engine.py +23 -0
- pytron/commands/frontend.py +60 -0
- pytron/commands/harvest.py +112 -0
- pytron/commands/helpers.py +239 -0
- pytron/commands/info.py +50 -0
- pytron/commands/init.py +521 -0
- pytron/commands/install.py +294 -0
- pytron/commands/login.py +130 -0
- pytron/commands/package.py +228 -0
- pytron/commands/plugin.py +442 -0
- pytron/commands/run.py +312 -0
- pytron/commands/scan.py +210 -0
- pytron/commands/show.py +23 -0
- pytron/commands/uninstall.py +150 -0
- pytron/commands/utils.py +42 -0
- pytron/commands/workflow.py +95 -0
- pytron/console.py +133 -0
- pytron/core.py +18 -0
- pytron/dependencies/WebView2Loader.dll +0 -0
- pytron/dependencies/__init__.py +1 -0
- pytron/dependencies/pytron_native.so +0 -0
- pytron/engines/chrome/adapter.py +445 -0
- pytron/engines/chrome/engine.py +576 -0
- pytron/engines/chrome/forge.py +147 -0
- pytron/engines/chrome/shell/package.json +8 -0
- pytron/engines/chrome/shell/preload.js +12 -0
- pytron/engines/chrome/shell/shell.js +534 -0
- pytron/exceptions.py +36 -0
- pytron/inspector.py +201 -0
- pytron/inspector_ui.py +512 -0
- pytron/installer/Installation.nsi +236 -0
- pytron/installer/header.bmp +0 -0
- pytron/installer/pytron.ico +0 -0
- pytron/installer/sidebar.bmp +0 -0
- pytron/llms.md +98 -0
- pytron/manifests/README.md +29 -0
- pytron/manifests/windows-utf8.manifest +44 -0
- pytron/menu.py +128 -0
- pytron/nsis-setup.exe +0 -0
- pytron/pack/__init__.py +0 -0
- pytron/pack/assets.py +131 -0
- pytron/pack/compilers.py +289 -0
- pytron/pack/crystal.py +297 -0
- pytron/pack/graph.py +377 -0
- pytron/pack/inference.py +157 -0
- pytron/pack/installers.py +402 -0
- pytron/pack/introspect.py +357 -0
- pytron/pack/metadata.py +213 -0
- pytron/pack/modules.py +618 -0
- pytron/pack/nuitka.py +108 -0
- pytron/pack/pipeline.py +107 -0
- pytron/pack/pyinstaller.py +176 -0
- pytron/pack/rust_engine.py +273 -0
- pytron/pack/secure.py +309 -0
- pytron/pack/secure_loader/bin/pytron_rust_bootloader +0 -0
- pytron/pack/secure_loader/icon.ico +0 -0
- pytron/pack/utils.py +110 -0
- pytron/pack/virtual_root.py +124 -0
- pytron/platforms/__init__.py +0 -0
- pytron/platforms/android/__init__.py +3 -0
- pytron/platforms/android/android.py +103 -0
- pytron/platforms/android/builder.py +736 -0
- pytron/platforms/android/ops/build.py +79 -0
- pytron/platforms/android/ops/init.py +63 -0
- pytron/platforms/android/ops/run.py +79 -0
- pytron/platforms/android/ops/sync.py +770 -0
- pytron/platforms/android/ops/utils.py +8 -0
- pytron/platforms/android/shell/README.md +30 -0
- pytron/platforms/android/shell/app/build.gradle +64 -0
- pytron/platforms/android/shell/app/src/main/AndroidManifest.xml +29 -0
- pytron/platforms/android/shell/app/src/main/assets/python/main.py +86 -0
- pytron/platforms/android/shell/app/src/main/assets/python/python314.zip +0 -0
- pytron/platforms/android/shell/app/src/main/cpp/CMakeLists.txt +25 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/Python.h +155 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/abstract.h +915 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/audit.h +30 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/bltinmodule.h +14 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/boolobject.h +54 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/bytearrayobject.h +44 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/bytesobject.h +66 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/ceval.h +145 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/codecs.h +176 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/compile.h +22 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/complexobject.h +30 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/abstract.h +104 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/audit.h +8 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/bytearrayobject.h +38 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/bytesobject.h +42 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/cellobject.h +50 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/ceval.h +43 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/classobject.h +71 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/code.h +340 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/compile.h +50 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/complexobject.h +33 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/context.h +107 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/critical_section.h +154 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/descrobject.h +62 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/dictobject.h +105 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/fileobject.h +16 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/fileutils.h +16 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/floatobject.h +27 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/frameobject.h +35 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/funcobject.h +185 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/genobject.h +56 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/import.h +30 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/initconfig.h +334 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/listobject.h +53 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/lock.h +74 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/longintrepr.h +184 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/longobject.h +89 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/memoryobject.h +50 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/methodobject.h +66 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/modsupport.h +26 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/monitoring.h +269 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/object.h +493 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/objimpl.h +104 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/odictobject.h +43 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/picklebufobject.h +31 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pthread_stubs.h +105 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyatomic.h +614 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyatomic_gcc.h +615 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyatomic_msc.h +1197 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyatomic_std.h +1112 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyctype.h +39 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pydebug.h +38 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyerrors.h +132 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyfpe.h +15 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyframe.h +45 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pyhash.h +54 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pylifecycle.h +89 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pymem.h +84 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pystate.h +275 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pystats.h +194 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pythonrun.h +96 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pythread.h +43 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/pytime.h +27 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/setobject.h +71 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/traceback.h +13 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/tracemalloc.h +32 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/tupleobject.h +40 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/unicodeobject.h +773 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/warnings.h +20 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/cpython/weakrefobject.h +66 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/critical_section.h +16 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/datetime.h +267 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/descrobject.h +100 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/dictobject.h +108 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/dynamic_annotations.h +499 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/enumobject.h +17 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/errcode.h +45 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/exports.h +105 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/fileobject.h +41 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/fileutils.h +62 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/floatobject.h +54 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/frameobject.h +20 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/genericaliasobject.h +14 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/import.h +103 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/atomic.h +392 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/internal.h +969 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/prim.h +329 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/track.h +147 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc/types.h +721 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/mimalloc/mimalloc.h +565 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_abstract.h +61 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_asdl.h +112 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ast.h +945 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ast_state.h +271 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_atexit.h +31 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_audit.h +35 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_backoff.h +133 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_bitutils.h +186 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_blocks_output_buffer.h +321 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_brc.h +73 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_bytes_methods.h +82 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_bytesobject.h +149 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_c_array.h +39 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_call.h +206 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_capsule.h +17 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_cell.h +75 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ceval.h +390 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ceval_state.h +48 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_code.h +671 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_codecs.h +76 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_compile.h +230 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_complexobject.h +34 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_condvar.h +93 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_context.h +59 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_critical_section.h +237 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_crossinterp.h +406 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_crossinterp_data_registry.h +41 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_debug_offsets.h +379 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_descrobject.h +28 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_dict.h +410 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_dict_state.h +28 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_dtoa.h +40 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_emscripten_signal.h +30 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_emscripten_trampoline.h +70 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_exceptions.h +40 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_faulthandler.h +100 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_fileutils.h +320 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_fileutils_windows.h +98 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_floatobject.h +49 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_flowgraph.h +47 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_format.h +27 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_frame.h +61 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_freelist.h +111 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_freelist_state.h +70 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_function.h +53 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_gc.h +378 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_genobject.h +43 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_getopt.h +22 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_gil.h +66 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_global_objects.h +34 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_global_objects_fini_generated.h +1592 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_global_strings.h +854 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_hamt.h +113 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_hashtable.h +150 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_import.h +141 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_importdl.h +139 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_index_pool.h +36 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_initconfig.h +197 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_instruction_sequence.h +83 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_instruments.h +127 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interp.h +109 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interp_structs.h +977 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interpframe.h +401 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interpframe_structs.h +95 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_interpolation.h +26 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_intrinsics.h +51 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_jit.h +29 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_list.h +81 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_llist.h +106 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_lock.h +236 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_long.h +319 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_magic_number.h +305 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_memoryobject.h +20 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_mimalloc.h +69 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_modsupport.h +99 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_moduleobject.h +62 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_namespace.h +21 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object.h +1029 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object_alloc.h +71 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object_deferred.h +32 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object_stack.h +95 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_object_state.h +49 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_obmalloc.h +702 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_obmalloc_init.h +66 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_opcode_metadata.h +2117 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_opcode_utils.h +90 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_optimizer.h +318 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_parking_lot.h +97 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_parser.h +78 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pathconfig.h +26 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pyarena.h +68 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pyatomic_ft_wrappers.h +174 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pybuffer.h +21 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pyerrors.h +213 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pyhash.h +91 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pylifecycle.h +136 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pymath.h +205 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pymem.h +145 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pymem_init.h +103 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pystate.h +339 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pystats.h +21 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pythonrun.h +68 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_pythread.h +172 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_qsbr.h +172 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_range.h +21 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_runtime.h +63 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_runtime_init.h +239 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_runtime_init_generated.h +1589 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_runtime_structs.h +310 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_semaphore.h +67 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_setobject.h +41 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_signal.h +108 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_sliceobject.h +20 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_stackref.h +791 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_stats.h +97 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_strhex.h +39 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_structs.h +88 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_structseq.h +40 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_symtable.h +201 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_sysmodule.h +32 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_template.h +26 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_time.h +334 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_token.h +110 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_traceback.h +111 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_tracemalloc.h +164 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_tstate.h +88 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_tuple.h +75 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_typedefs.h +18 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_typeobject.h +155 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_typevarobject.h +28 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_ucnhash.h +36 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_unicodeobject.h +308 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_unicodeobject_generated.h +3132 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_unionobject.h +26 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_uniqueid.h +57 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_uop_ids.h +335 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_uop_metadata.h +1204 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_warnings.h +21 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/internal/pycore_weakref.h +133 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/intrcheck.h +23 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/iterobject.h +24 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/listobject.h +55 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/lock.h +16 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/longobject.h +178 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/marshal.h +31 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/memoryobject.h +34 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/methodobject.h +146 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/modsupport.h +146 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/moduleobject.h +122 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/monitoring.h +18 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/object.h +828 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/objimpl.h +211 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/opcode.h +43 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/opcode_ids.h +259 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/osdefs.h +57 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/osmodule.h +17 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/patchlevel.h +49 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/py_curses.h +117 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pyatomic.h +16 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pybuffer.h +145 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pycapsule.h +58 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pyconfig.h +2088 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pydtrace.h +59 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pyerrors.h +335 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pyexpat.h +62 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pyframe.h +26 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pyhash.h +59 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pylifecycle.h +80 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pymacconfig.h +91 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pymacro.h +243 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pymath.h +65 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pymem.h +110 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pyport.h +710 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pystate.h +132 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pystats.h +28 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pystrcmp.h +23 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pystrtod.h +37 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pythonrun.h +42 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pythread.h +131 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/pytypedefs.h +30 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/rangeobject.h +27 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/refcount.h +555 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/setobject.h +49 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/sliceobject.h +69 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/structmember.h +56 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/structseq.h +46 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/sysmodule.h +27 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/traceback.h +26 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/tupleobject.h +46 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/typeslots.h +96 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/unicodeobject.h +1029 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/warnings.h +45 -0
- pytron/platforms/android/shell/app/src/main/cpp/include/weakrefobject.h +46 -0
- pytron/platforms/android/shell/app/src/main/cpp/pytron_bridge.cpp +224 -0
- pytron/platforms/android/shell/app/src/main/java/com/pytron/shell/MainActivity.kt +208 -0
- pytron/platforms/android/shell/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- pytron/platforms/android/shell/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- pytron/platforms/android/shell/build.gradle +11 -0
- pytron/platforms/android/shell/gradle/wrapper/gradle-wrapper.jar +0 -0
- pytron/platforms/android/shell/gradle/wrapper/gradle-wrapper.properties +5 -0
- pytron/platforms/android/shell/gradle.properties +2 -0
- pytron/platforms/android/shell/gradlew.bat +85 -0
- pytron/platforms/android/shell/settings.gradle +16 -0
- pytron/platforms/darwin.py +82 -0
- pytron/platforms/darwin_ops/libs.py +31 -0
- pytron/platforms/darwin_ops/system.py +182 -0
- pytron/platforms/darwin_ops/utils.py +85 -0
- pytron/platforms/darwin_ops/webview.py +5 -0
- pytron/platforms/darwin_ops/window.py +102 -0
- pytron/platforms/interface.py +152 -0
- pytron/platforms/linux.py +82 -0
- pytron/platforms/linux_ops/libs.py +49 -0
- pytron/platforms/linux_ops/system.py +316 -0
- pytron/platforms/linux_ops/utils.py +19 -0
- pytron/platforms/linux_ops/webview.py +5 -0
- pytron/platforms/linux_ops/window.py +115 -0
- pytron/platforms/windows.py +136 -0
- pytron/platforms/windows_ops/__init__.py +0 -0
- pytron/platforms/windows_ops/constants.py +126 -0
- pytron/platforms/windows_ops/system.py +518 -0
- pytron/platforms/windows_ops/utils.py +3 -0
- pytron/platforms/windows_ops/webview.py +5 -0
- pytron/platforms/windows_ops/window.py +361 -0
- pytron/plugin.py +467 -0
- pytron/rcedit-x64.exe +0 -0
- pytron/router.py +146 -0
- pytron/serializer.py +240 -0
- pytron/shortcuts.py +279 -0
- pytron/state.py +76 -0
- pytron/tray.py +399 -0
- pytron/updater.py +181 -0
- pytron/utf8_hook.py +112 -0
- pytron/utils.py +44 -0
- pytron/webview.py +722 -0
- pytron_kit-0.3.12.dist-info/METADATA +131 -0
- pytron_kit-0.3.12.dist-info/RECORD +419 -0
- pytron_kit-0.3.12.dist-info/WHEEL +5 -0
- pytron_kit-0.3.12.dist-info/entry_points.txt +2 -0
- pytron_kit-0.3.12.dist-info/licenses/LICENSE +201 -0
- pytron_kit-0.3.12.dist-info/top_level.txt +1 -0
pytron/pack/graph.py
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
import ast
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import List, Dict, Set, Optional, Any
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class Edge:
|
|
11
|
+
source: str
|
|
12
|
+
target: str
|
|
13
|
+
type: str # "static", "dynamic", "side-effect"
|
|
14
|
+
confidence: float # 0.0 to 1.0
|
|
15
|
+
reason: str
|
|
16
|
+
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class Node:
|
|
21
|
+
name: str # fully qualified module name
|
|
22
|
+
path: Optional[Path] = None
|
|
23
|
+
type: str = "module" # "module", "package", "resource"
|
|
24
|
+
features: Set[str] = field(
|
|
25
|
+
default_factory=set
|
|
26
|
+
) # extracted signals (e.g. "has_getattr")
|
|
27
|
+
literals: Set[str] = field(
|
|
28
|
+
default_factory=set
|
|
29
|
+
) # interesting string literals found in source
|
|
30
|
+
|
|
31
|
+
def to_dict(self):
|
|
32
|
+
return {
|
|
33
|
+
"name": self.name,
|
|
34
|
+
"path": str(self.path) if self.path else None,
|
|
35
|
+
"type": self.type,
|
|
36
|
+
"features": list(self.features),
|
|
37
|
+
"literals": list(self.literals),
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class SideEffectGraph:
|
|
42
|
+
"""
|
|
43
|
+
A probabilistic dependency graph that models the uncertainty of Python imports.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
def __init__(self):
|
|
47
|
+
self.nodes: Dict[str, Node] = {}
|
|
48
|
+
self.edges: List[Edge] = []
|
|
49
|
+
self._uncertainty_zones: List[Dict] = [] # Places where dynamic magic happens
|
|
50
|
+
|
|
51
|
+
def add_node(self, name: str, path: Path = None) -> Node:
|
|
52
|
+
if name not in self.nodes:
|
|
53
|
+
self.nodes[name] = Node(name=name, path=path)
|
|
54
|
+
return self.nodes[name]
|
|
55
|
+
|
|
56
|
+
def add_edge(
|
|
57
|
+
self,
|
|
58
|
+
source: str,
|
|
59
|
+
target: str,
|
|
60
|
+
type: str,
|
|
61
|
+
confidence: float = 1.0,
|
|
62
|
+
reason: str = "",
|
|
63
|
+
):
|
|
64
|
+
# Avoid duplicates
|
|
65
|
+
for e in self.edges:
|
|
66
|
+
if e.source == source and e.target == target and e.type == type:
|
|
67
|
+
return
|
|
68
|
+
|
|
69
|
+
self.edges.append(Edge(source, target, type, confidence, reason))
|
|
70
|
+
|
|
71
|
+
def mark_uncertainty(
|
|
72
|
+
self, source_node: str, line_no: int, code_snippet: str, heuristic: str
|
|
73
|
+
):
|
|
74
|
+
"""
|
|
75
|
+
Registers a 'Known Unknown'. This is a task for the ML Oracle.
|
|
76
|
+
"""
|
|
77
|
+
self._uncertainty_zones.append(
|
|
78
|
+
{
|
|
79
|
+
"source": source_node,
|
|
80
|
+
"line": line_no,
|
|
81
|
+
"code": code_snippet,
|
|
82
|
+
"heuristic": heuristic,
|
|
83
|
+
"resolved": False,
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def to_json(self) -> str:
|
|
88
|
+
data = {
|
|
89
|
+
"nodes": {k: v.to_dict() for k, v in self.nodes.items()},
|
|
90
|
+
"edges": [
|
|
91
|
+
{
|
|
92
|
+
"from": e.source,
|
|
93
|
+
"to": e.target,
|
|
94
|
+
"type": e.type,
|
|
95
|
+
"confidence": e.confidence,
|
|
96
|
+
"reason": e.reason,
|
|
97
|
+
}
|
|
98
|
+
for e in self.edges
|
|
99
|
+
],
|
|
100
|
+
"uncertainty": self._uncertainty_zones,
|
|
101
|
+
}
|
|
102
|
+
return json.dumps(data, indent=2)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class GraphBuilder:
|
|
106
|
+
"""
|
|
107
|
+
Static Analyzer that populates the SideEffectGraph.
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
def __init__(self, root: Path):
|
|
111
|
+
self.root = root
|
|
112
|
+
self.graph = SideEffectGraph()
|
|
113
|
+
|
|
114
|
+
def scan_project(self):
|
|
115
|
+
"""Scans all .py files in the root recursively."""
|
|
116
|
+
for path in self.root.rglob("*.py"):
|
|
117
|
+
self._analyze_file(path)
|
|
118
|
+
return self.graph
|
|
119
|
+
|
|
120
|
+
def _analyze_file(self, path: Path):
|
|
121
|
+
# Convert path to module name
|
|
122
|
+
try:
|
|
123
|
+
rel_path = path.relative_to(self.root)
|
|
124
|
+
module_name = ".".join(rel_path.with_suffix("").parts)
|
|
125
|
+
except ValueError:
|
|
126
|
+
module_name = path.name
|
|
127
|
+
|
|
128
|
+
node = self.graph.add_node(module_name, path)
|
|
129
|
+
|
|
130
|
+
try:
|
|
131
|
+
content = path.read_text(encoding="utf-8", errors="ignore")
|
|
132
|
+
tree = ast.parse(content)
|
|
133
|
+
self._visit_node(node, tree)
|
|
134
|
+
except Exception:
|
|
135
|
+
pass
|
|
136
|
+
|
|
137
|
+
def _visit_node(self, node: Node, tree: ast.AST):
|
|
138
|
+
"""
|
|
139
|
+
Extracts features and static edges from AST.
|
|
140
|
+
"""
|
|
141
|
+
for s in ast.walk(tree):
|
|
142
|
+
# 1. Static Imports (Confidence 1.0)
|
|
143
|
+
if isinstance(s, ast.Import):
|
|
144
|
+
for alias in s.names:
|
|
145
|
+
self.graph.add_edge(
|
|
146
|
+
node.name, alias.name, "static", 1.0, "import_stmt"
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
elif isinstance(s, ast.ImportFrom):
|
|
150
|
+
if s.module:
|
|
151
|
+
self.graph.add_edge(
|
|
152
|
+
node.name, s.module, "static", 1.0, "from_import_stmt"
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
# 2. String Literals (Feature Extraction for ML)
|
|
156
|
+
elif isinstance(s, ast.Constant) and isinstance(s.value, str):
|
|
157
|
+
# Heuristic: Only keep "interesting" strings (no whitespace, len > 3)
|
|
158
|
+
txt = s.value.strip()
|
|
159
|
+
if len(txt) > 3 and " " not in txt:
|
|
160
|
+
node.literals.add(txt)
|
|
161
|
+
|
|
162
|
+
# 3. Dynamic Triggers (The Uncertainty)
|
|
163
|
+
elif isinstance(s, ast.Call):
|
|
164
|
+
if isinstance(s.func, ast.Attribute):
|
|
165
|
+
# importlib.import_module(...)
|
|
166
|
+
if s.func.attr == "import_module":
|
|
167
|
+
node.features.add("calls_import_module")
|
|
168
|
+
self.graph.mark_uncertainty(
|
|
169
|
+
node.name,
|
|
170
|
+
getattr(s, "lineno", 0),
|
|
171
|
+
"import_module",
|
|
172
|
+
"dynamic_import",
|
|
173
|
+
)
|
|
174
|
+
elif isinstance(s.func, ast.Name):
|
|
175
|
+
# __import__(...)
|
|
176
|
+
if s.func.id == "__import__":
|
|
177
|
+
node.features.add("calls_dunder_import")
|
|
178
|
+
self.graph.mark_uncertainty(
|
|
179
|
+
node.name,
|
|
180
|
+
getattr(s, "lineno", 0),
|
|
181
|
+
"__import__",
|
|
182
|
+
"dynamic_import",
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
from .inference import SimpleTextClassifier, FeatureExtractor
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class DependencyOracle:
|
|
190
|
+
"""
|
|
191
|
+
The 'Bridge' between the Graph and the ML Model.
|
|
192
|
+
Now powered by the 'Oracle of Hooks' dataset mined from ecosystem history.
|
|
193
|
+
"""
|
|
194
|
+
|
|
195
|
+
def __init__(self, graph: SideEffectGraph):
|
|
196
|
+
self.graph = graph
|
|
197
|
+
self.knowledge_base = self._load_knowledge_base()
|
|
198
|
+
self.classifier = self._load_model()
|
|
199
|
+
self.extractor = FeatureExtractor()
|
|
200
|
+
|
|
201
|
+
def _load_model(self):
|
|
202
|
+
try:
|
|
203
|
+
# Look for the brain in the sibling directory
|
|
204
|
+
# structure: d:/playground/pytron/pytron/pack/graph.py
|
|
205
|
+
# target: d:/playground/brain/model.json
|
|
206
|
+
|
|
207
|
+
# Robust logic: find the project root and go up one
|
|
208
|
+
current = Path(__file__)
|
|
209
|
+
# Go up until we hit 'pytron' repo root
|
|
210
|
+
root = current.parent.parent.parent.parent # d:/playground
|
|
211
|
+
path = root / "brain" / "model.json"
|
|
212
|
+
|
|
213
|
+
if path.exists():
|
|
214
|
+
clf = SimpleTextClassifier()
|
|
215
|
+
clf.load(path)
|
|
216
|
+
return clf
|
|
217
|
+
except Exception:
|
|
218
|
+
pass
|
|
219
|
+
return None
|
|
220
|
+
|
|
221
|
+
def _load_knowledge_base(self) -> Dict:
|
|
222
|
+
"""Loads the mined signal data (the 'Brain')."""
|
|
223
|
+
try:
|
|
224
|
+
# Look for data.json in the sibling brain directory
|
|
225
|
+
current = Path(__file__)
|
|
226
|
+
root = current.parent.parent.parent.parent
|
|
227
|
+
path = root / "brain" / "data.json"
|
|
228
|
+
|
|
229
|
+
if path.exists():
|
|
230
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
231
|
+
except Exception:
|
|
232
|
+
pass
|
|
233
|
+
return {}
|
|
234
|
+
|
|
235
|
+
def predict(self):
|
|
236
|
+
"""
|
|
237
|
+
Iterates over uncertainty zones and uses the Knowledge Base to predict edges.
|
|
238
|
+
"""
|
|
239
|
+
if not self.knowledge_base:
|
|
240
|
+
# Fallback to hardcoded heuristics if KB is missing
|
|
241
|
+
self._predict_heuristic()
|
|
242
|
+
return
|
|
243
|
+
|
|
244
|
+
for zone in self.graph._uncertainty_zones:
|
|
245
|
+
source_name = zone["source"]
|
|
246
|
+
node = self.graph.nodes.get(source_name)
|
|
247
|
+
if not node:
|
|
248
|
+
continue
|
|
249
|
+
|
|
250
|
+
# --- PREDICTION LOGIC ---
|
|
251
|
+
# 1. Identify the Package Context of the Node
|
|
252
|
+
# e.g., "pandas.core.internals" -> "pandas"
|
|
253
|
+
root_package = source_name.split(".")[0]
|
|
254
|
+
|
|
255
|
+
# Check if we have wisdom about this package
|
|
256
|
+
if root_package in self.knowledge_base:
|
|
257
|
+
self._apply_known_wisdom(
|
|
258
|
+
source_name,
|
|
259
|
+
root_package,
|
|
260
|
+
self.knowledge_base[root_package]["signal"],
|
|
261
|
+
)
|
|
262
|
+
else:
|
|
263
|
+
# UNSEEN MODULE DETECTED!
|
|
264
|
+
# Activate "The Generalist" (Zero-Shot Prediction)
|
|
265
|
+
self._predict_unseen_module(zone, node)
|
|
266
|
+
|
|
267
|
+
# 2. Cross-Reference Literals (The "Data Bridge")
|
|
268
|
+
# If the code mentions a package string that we know is a heavy dependency
|
|
269
|
+
for literal in node.literals:
|
|
270
|
+
# Naive check: is the literal a known package in our KB?
|
|
271
|
+
if literal in self.knowledge_base and literal != root_package:
|
|
272
|
+
self.graph.add_edge(
|
|
273
|
+
source=source_name,
|
|
274
|
+
target=literal,
|
|
275
|
+
type="predicted",
|
|
276
|
+
confidence=0.60, # Lower confidence for string matching
|
|
277
|
+
reason=f"oracle_literal_match:{literal}",
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
zone["resolved"] = True
|
|
281
|
+
|
|
282
|
+
def _apply_known_wisdom(self, source_name, root_package, signal):
|
|
283
|
+
"""Applies expert rules from the Knowledge Base."""
|
|
284
|
+
# Apply Hidden Imports
|
|
285
|
+
for hidden in signal.get("hiddenimports", []):
|
|
286
|
+
if isinstance(hidden, str):
|
|
287
|
+
self.graph.add_edge(
|
|
288
|
+
source=source_name,
|
|
289
|
+
target=hidden,
|
|
290
|
+
type="predicted",
|
|
291
|
+
confidence=0.95,
|
|
292
|
+
reason=f"oracle_hook_knowledge_base[{root_package}]",
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
# Apply Utility Semantics
|
|
296
|
+
for util in signal.get("utilities", []):
|
|
297
|
+
func = util.get("function")
|
|
298
|
+
if func == "collect_submodules":
|
|
299
|
+
target_arg = util["arguments"][0] if util["arguments"] else root_package
|
|
300
|
+
if isinstance(target_arg, str):
|
|
301
|
+
self.graph.add_edge(
|
|
302
|
+
source=source_name,
|
|
303
|
+
target=f"{target_arg}.*",
|
|
304
|
+
type="predicted",
|
|
305
|
+
confidence=0.90,
|
|
306
|
+
reason="oracle_utility_signal:collect_submodules",
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
def _predict_unseen_module(self, zone, node):
|
|
310
|
+
"""
|
|
311
|
+
The Generalist: Zero-Shot prediction for unseen modules.
|
|
312
|
+
Uses the trained Naive Bayes model to classify the module's behavior.
|
|
313
|
+
"""
|
|
314
|
+
if not self.classifier:
|
|
315
|
+
# Fallback if model not loaded
|
|
316
|
+
return
|
|
317
|
+
|
|
318
|
+
source_name = zone["source"]
|
|
319
|
+
|
|
320
|
+
# 1. Get Code Content (X)
|
|
321
|
+
# We need the source code to extract features.
|
|
322
|
+
# If the node.path is a file, read it.
|
|
323
|
+
source_code = ""
|
|
324
|
+
if node.path and node.path.exists():
|
|
325
|
+
try:
|
|
326
|
+
source_code = node.path.read_text(errors="ignore")
|
|
327
|
+
except:
|
|
328
|
+
pass
|
|
329
|
+
|
|
330
|
+
if not source_code:
|
|
331
|
+
return
|
|
332
|
+
|
|
333
|
+
# 2. Extract Features
|
|
334
|
+
features = self.extractor.extract(source_code)
|
|
335
|
+
|
|
336
|
+
# 3. Predict Strategy (Y)
|
|
337
|
+
predictions = self.classifier.predict(features)
|
|
338
|
+
# predictions is list of (label, log_score).
|
|
339
|
+
# Since scores are log-probs, they are negative. Closer to 0 is better.
|
|
340
|
+
# We just take the top one.
|
|
341
|
+
|
|
342
|
+
if not predictions:
|
|
343
|
+
return
|
|
344
|
+
|
|
345
|
+
best_label, best_score = predictions[0]
|
|
346
|
+
|
|
347
|
+
# Thresholding logic for Log Probs is tricky.
|
|
348
|
+
# Simple relative check: is the best score significantly better than the next?
|
|
349
|
+
# Or just trust the rankings.
|
|
350
|
+
|
|
351
|
+
# Heuristic validation of the prediction
|
|
352
|
+
reason = f"ml_naive_bayes:{best_label}"
|
|
353
|
+
|
|
354
|
+
if best_label == "COLLECT_SUBMODULES":
|
|
355
|
+
# Constraint: Does it look like a package? (Has __path__ or is __init__)
|
|
356
|
+
if node.path.name == "__init__.py":
|
|
357
|
+
self.graph.add_edge(
|
|
358
|
+
source_name, f"{source_name}.*", "predicted", 0.82, reason
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
elif best_label == "COLLECT_DATA":
|
|
362
|
+
# Constraint: Does the directory contain non-py files?
|
|
363
|
+
# Simple check: if we predicted DATA, we imply we need to scan usage.
|
|
364
|
+
# We add a generic data-dependency edge
|
|
365
|
+
self.graph.add_edge(
|
|
366
|
+
source_name, "<resource_data>", "predicted", 0.75, reason
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
elif best_label == "HIDDEN_IMPORTS":
|
|
370
|
+
# This suggests specific imports are hidden.
|
|
371
|
+
# Hard to predict WHICH ones without a sequence model.
|
|
372
|
+
# But we can flag it for deeper inspection or scan literals harder.
|
|
373
|
+
pass
|
|
374
|
+
|
|
375
|
+
def _predict_heuristic(self):
|
|
376
|
+
"""Fallback for when no KB is available (Generic Patterns only)"""
|
|
377
|
+
pass
|
pytron/pack/inference.py
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import collections
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import List, Dict, Any, Tuple
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SimpleTextClassifier:
|
|
9
|
+
"""
|
|
10
|
+
A lightweight Naive Bayes classifier implemented from scratch.
|
|
11
|
+
Predicts Packaging Strategy (Y) based on Code Features (X).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
def __init__(self):
|
|
15
|
+
# Counts: class -> token -> count
|
|
16
|
+
self.feature_counts = collections.defaultdict(
|
|
17
|
+
lambda: collections.defaultdict(int)
|
|
18
|
+
)
|
|
19
|
+
# Counts: class -> total_tokens
|
|
20
|
+
self.class_token_counts = collections.defaultdict(int)
|
|
21
|
+
# Counts: class -> number_of_examples
|
|
22
|
+
self.class_counts = collections.defaultdict(int)
|
|
23
|
+
self.total_examples = 0
|
|
24
|
+
self.vocab = set()
|
|
25
|
+
|
|
26
|
+
def train(self, features: List[str], label: str):
|
|
27
|
+
"""
|
|
28
|
+
Ingest one training example.
|
|
29
|
+
"""
|
|
30
|
+
self.class_counts[label] += 1
|
|
31
|
+
self.total_examples += 1
|
|
32
|
+
|
|
33
|
+
for f in features:
|
|
34
|
+
self.feature_counts[label][f] += 1
|
|
35
|
+
self.class_token_counts[label] += 1
|
|
36
|
+
self.vocab.add(f)
|
|
37
|
+
|
|
38
|
+
def predict(self, features: List[str]) -> Dict[str, float]:
|
|
39
|
+
"""
|
|
40
|
+
Returns probabilities for each class.
|
|
41
|
+
"""
|
|
42
|
+
scores = {}
|
|
43
|
+
for label in self.class_counts:
|
|
44
|
+
# P(Class)
|
|
45
|
+
log_prob = math.log(self.class_counts[label] / self.total_examples)
|
|
46
|
+
|
|
47
|
+
# P(Feature | Class)
|
|
48
|
+
# Use Laplace Smoothing (add-1)
|
|
49
|
+
denominator = self.class_token_counts[label] + len(self.vocab)
|
|
50
|
+
|
|
51
|
+
for f in features:
|
|
52
|
+
# If feature is unknown in training, we ignore it (or count as 0 with smoothing)
|
|
53
|
+
# Naive Bayes assumption: multiply probabilities (add logs)
|
|
54
|
+
count = self.feature_counts[label].get(f, 0) + 1
|
|
55
|
+
log_prob += math.log(count / denominator)
|
|
56
|
+
|
|
57
|
+
scores[label] = log_prob
|
|
58
|
+
|
|
59
|
+
return sorted(scores.items(), key=lambda x: x[1], reverse=True)
|
|
60
|
+
|
|
61
|
+
def save(self, path: Path):
|
|
62
|
+
data = {
|
|
63
|
+
"feature_counts": {k: dict(v) for k, v in self.feature_counts.items()},
|
|
64
|
+
"class_token_counts": dict(self.class_token_counts),
|
|
65
|
+
"class_counts": dict(self.class_counts),
|
|
66
|
+
"total_examples": self.total_examples,
|
|
67
|
+
"vocab": list(self.vocab),
|
|
68
|
+
}
|
|
69
|
+
path.write_text(json.dumps(data))
|
|
70
|
+
|
|
71
|
+
def load(self, path: Path):
|
|
72
|
+
data = json.loads(path.read_text())
|
|
73
|
+
self.feature_counts = collections.defaultdict(
|
|
74
|
+
lambda: collections.defaultdict(int),
|
|
75
|
+
{
|
|
76
|
+
k: collections.defaultdict(int, v)
|
|
77
|
+
for k, v in data["feature_counts"].items()
|
|
78
|
+
},
|
|
79
|
+
)
|
|
80
|
+
self.class_token_counts = collections.defaultdict(
|
|
81
|
+
int, data["class_token_counts"]
|
|
82
|
+
)
|
|
83
|
+
self.class_counts = collections.defaultdict(int, data["class_counts"])
|
|
84
|
+
self.total_examples = data["total_examples"]
|
|
85
|
+
self.vocab = set(data["vocab"])
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class FeatureExtractor:
|
|
89
|
+
"""
|
|
90
|
+
Extracts 'X' (Feature Vector) from Source Code.
|
|
91
|
+
Now enhanced with 'Suspicion Flags' (Option A: Systems Approach).
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
def extract(self, source_code: str) -> List[str]:
|
|
95
|
+
features = []
|
|
96
|
+
|
|
97
|
+
# 1. Suspicion Flags (Explicit Signals)
|
|
98
|
+
# These are strong indicators of dynamic behavior.
|
|
99
|
+
flags = {
|
|
100
|
+
"has_importlib": ["importlib", "import_module"],
|
|
101
|
+
"has_pkgutil": ["pkgutil", "iter_modules"],
|
|
102
|
+
"has_exec": ["exec(", "eval("],
|
|
103
|
+
"has_sys_path": ["sys.path", ".append"],
|
|
104
|
+
"has_backends": ["backends", "plugins", "drivers"],
|
|
105
|
+
"has_ctypes": ["ctypes", "CDLL", "find_library"],
|
|
106
|
+
"has_dunder_import": ["__import__"],
|
|
107
|
+
"has_loader": ["importlib.util", "SourceFileLoader"],
|
|
108
|
+
"has_data_access": ["open(", "read_text", "pkgutil.get_data"],
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
for flag_name, keywords in flags.items():
|
|
112
|
+
# If ANY keyword is found, trigger the flag
|
|
113
|
+
if any(k in source_code for k in keywords):
|
|
114
|
+
features.append(f"FLAG:{flag_name}")
|
|
115
|
+
|
|
116
|
+
# 2. Bag of Words (Contextual Signals)
|
|
117
|
+
# Use regex to find significant identifiers
|
|
118
|
+
import re
|
|
119
|
+
|
|
120
|
+
tokens = re.findall(r"\b[a-zA-Z_]\w+\b", source_code)
|
|
121
|
+
|
|
122
|
+
# Filter common stopwords
|
|
123
|
+
stops = {
|
|
124
|
+
"self",
|
|
125
|
+
"def",
|
|
126
|
+
"class",
|
|
127
|
+
"return",
|
|
128
|
+
"import",
|
|
129
|
+
"from",
|
|
130
|
+
"if",
|
|
131
|
+
"else",
|
|
132
|
+
"None",
|
|
133
|
+
"True",
|
|
134
|
+
"False",
|
|
135
|
+
"try",
|
|
136
|
+
"except",
|
|
137
|
+
"in",
|
|
138
|
+
"is",
|
|
139
|
+
"not",
|
|
140
|
+
"and",
|
|
141
|
+
"or",
|
|
142
|
+
"for",
|
|
143
|
+
"while",
|
|
144
|
+
"with",
|
|
145
|
+
"as",
|
|
146
|
+
"pass",
|
|
147
|
+
"continue",
|
|
148
|
+
"break",
|
|
149
|
+
"raise",
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
for t in tokens:
|
|
153
|
+
if len(t) > 3 and t not in stops:
|
|
154
|
+
# We prefix tokens to distinguish from flags
|
|
155
|
+
features.append(f"TOKEN:{t}")
|
|
156
|
+
|
|
157
|
+
return features
|