zexus 1.6.2
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.
- package/LICENSE +0 -0
- package/README.md +2513 -0
- package/bin/zexus +2 -0
- package/bin/zpics +2 -0
- package/bin/zpm +2 -0
- package/bin/zx +2 -0
- package/bin/zx-deploy +2 -0
- package/bin/zx-dev +2 -0
- package/bin/zx-run +2 -0
- package/package.json +66 -0
- package/scripts/README.md +24 -0
- package/scripts/postinstall.js +44 -0
- package/shared_config.json +24 -0
- package/src/README.md +1525 -0
- package/src/tests/run_zexus_tests.py +117 -0
- package/src/tests/test_all_phases.zx +346 -0
- package/src/tests/test_blockchain_features.zx +306 -0
- package/src/tests/test_complexity_features.zx +321 -0
- package/src/tests/test_core_integration.py +185 -0
- package/src/tests/test_phase10_ecosystem.zx +177 -0
- package/src/tests/test_phase1_modifiers.zx +87 -0
- package/src/tests/test_phase2_plugins.zx +80 -0
- package/src/tests/test_phase3_security.zx +97 -0
- package/src/tests/test_phase4_vfs.zx +116 -0
- package/src/tests/test_phase5_types.zx +117 -0
- package/src/tests/test_phase6_metaprogramming.zx +125 -0
- package/src/tests/test_phase7_optimization.zx +132 -0
- package/src/tests/test_phase9_advanced_types.zx +157 -0
- package/src/tests/test_security_features.py +419 -0
- package/src/tests/test_security_features.zx +276 -0
- package/src/tests/test_simple_zx.zx +1 -0
- package/src/tests/test_verification_simple.zx +69 -0
- package/src/zexus/__init__.py +28 -0
- package/src/zexus/__main__.py +5 -0
- package/src/zexus/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/advanced_types.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/builtin_modules.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/capability_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/complexity_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/concurrency_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/config.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/dependency_injection.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/ecosystem.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/environment.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/error_reporter.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/hybrid_orchestrator.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/lexer.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/metaprogramming.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/module_cache.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/object.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/optimization.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/plugin_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/policy_engine.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/security.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/stdlib_integration.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/strategy_recovery.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/syntax_validator.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/type_system.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/virtual_filesystem.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/zexus_ast.cpython-312.pyc +0 -0
- package/src/zexus/__pycache__/zexus_token.cpython-312.pyc +0 -0
- package/src/zexus/advanced_types.py +401 -0
- package/src/zexus/blockchain/__init__.py +40 -0
- package/src/zexus/blockchain/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/__pycache__/crypto.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/__pycache__/ledger.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/__pycache__/transaction.cpython-312.pyc +0 -0
- package/src/zexus/blockchain/crypto.py +463 -0
- package/src/zexus/blockchain/ledger.py +255 -0
- package/src/zexus/blockchain/transaction.py +267 -0
- package/src/zexus/builtin_modules.py +284 -0
- package/src/zexus/builtin_plugins.py +317 -0
- package/src/zexus/capability_system.py +372 -0
- package/src/zexus/cli/__init__.py +2 -0
- package/src/zexus/cli/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/cli/__pycache__/main.cpython-312.pyc +0 -0
- package/src/zexus/cli/main.py +707 -0
- package/src/zexus/cli/zpm.py +203 -0
- package/src/zexus/compare_interpreter_compiler.py +146 -0
- package/src/zexus/compiler/__init__.py +169 -0
- package/src/zexus/compiler/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/compiler/__pycache__/lexer.cpython-312.pyc +0 -0
- package/src/zexus/compiler/__pycache__/parser.cpython-312.pyc +0 -0
- package/src/zexus/compiler/__pycache__/zexus_ast.cpython-312.pyc +0 -0
- package/src/zexus/compiler/bytecode.py +266 -0
- package/src/zexus/compiler/compat_runtime.py +277 -0
- package/src/zexus/compiler/lexer.py +257 -0
- package/src/zexus/compiler/parser.py +779 -0
- package/src/zexus/compiler/semantic.py +118 -0
- package/src/zexus/compiler/zexus_ast.py +454 -0
- package/src/zexus/complexity_system.py +575 -0
- package/src/zexus/concurrency_system.py +493 -0
- package/src/zexus/config.py +201 -0
- package/src/zexus/crypto_bridge.py +19 -0
- package/src/zexus/dependency_injection.py +423 -0
- package/src/zexus/ecosystem.py +434 -0
- package/src/zexus/environment.py +101 -0
- package/src/zexus/environment_manager.py +119 -0
- package/src/zexus/error_reporter.py +314 -0
- package/src/zexus/evaluator/__init__.py +12 -0
- package/src/zexus/evaluator/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/bytecode_compiler.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/core.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/expressions.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/functions.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/integration.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/statements.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/__pycache__/utils.cpython-312.pyc +0 -0
- package/src/zexus/evaluator/bytecode_compiler.py +700 -0
- package/src/zexus/evaluator/core.py +891 -0
- package/src/zexus/evaluator/expressions.py +827 -0
- package/src/zexus/evaluator/functions.py +3989 -0
- package/src/zexus/evaluator/integration.py +396 -0
- package/src/zexus/evaluator/statements.py +4303 -0
- package/src/zexus/evaluator/utils.py +126 -0
- package/src/zexus/evaluator_original.py +2041 -0
- package/src/zexus/external_bridge.py +16 -0
- package/src/zexus/find_affected_imports.sh +155 -0
- package/src/zexus/hybrid_orchestrator.py +152 -0
- package/src/zexus/input_validation.py +259 -0
- package/src/zexus/lexer.py +571 -0
- package/src/zexus/logging.py +89 -0
- package/src/zexus/lsp/__init__.py +9 -0
- package/src/zexus/lsp/completion_provider.py +207 -0
- package/src/zexus/lsp/definition_provider.py +22 -0
- package/src/zexus/lsp/hover_provider.py +71 -0
- package/src/zexus/lsp/server.py +269 -0
- package/src/zexus/lsp/symbol_provider.py +31 -0
- package/src/zexus/metaprogramming.py +321 -0
- package/src/zexus/module_cache.py +89 -0
- package/src/zexus/module_manager.py +107 -0
- package/src/zexus/object.py +973 -0
- package/src/zexus/optimization.py +424 -0
- package/src/zexus/parser/__init__.py +31 -0
- package/src/zexus/parser/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/parser/__pycache__/parser.cpython-312.pyc +0 -0
- package/src/zexus/parser/__pycache__/strategy_context.cpython-312.pyc +0 -0
- package/src/zexus/parser/__pycache__/strategy_structural.cpython-312.pyc +0 -0
- package/src/zexus/parser/integration.py +86 -0
- package/src/zexus/parser/parser.py +3977 -0
- package/src/zexus/parser/strategy_context.py +7254 -0
- package/src/zexus/parser/strategy_structural.py +1033 -0
- package/src/zexus/persistence.py +391 -0
- package/src/zexus/plugin_system.py +290 -0
- package/src/zexus/policy_engine.py +365 -0
- package/src/zexus/profiler/__init__.py +5 -0
- package/src/zexus/profiler/profiler.py +233 -0
- package/src/zexus/purity_system.py +398 -0
- package/src/zexus/runtime/__init__.py +20 -0
- package/src/zexus/runtime/async_runtime.py +324 -0
- package/src/zexus/search_old_imports.sh +65 -0
- package/src/zexus/security.py +1407 -0
- package/src/zexus/stack_trace.py +233 -0
- package/src/zexus/stdlib/__init__.py +27 -0
- package/src/zexus/stdlib/blockchain.py +341 -0
- package/src/zexus/stdlib/compression.py +167 -0
- package/src/zexus/stdlib/crypto.py +124 -0
- package/src/zexus/stdlib/datetime.py +163 -0
- package/src/zexus/stdlib/db_mongo.py +199 -0
- package/src/zexus/stdlib/db_mysql.py +162 -0
- package/src/zexus/stdlib/db_postgres.py +163 -0
- package/src/zexus/stdlib/db_sqlite.py +133 -0
- package/src/zexus/stdlib/encoding.py +230 -0
- package/src/zexus/stdlib/fs.py +195 -0
- package/src/zexus/stdlib/http.py +219 -0
- package/src/zexus/stdlib/http_server.py +248 -0
- package/src/zexus/stdlib/json_module.py +61 -0
- package/src/zexus/stdlib/math.py +360 -0
- package/src/zexus/stdlib/os_module.py +265 -0
- package/src/zexus/stdlib/regex.py +148 -0
- package/src/zexus/stdlib/sockets.py +253 -0
- package/src/zexus/stdlib/test_framework.zx +208 -0
- package/src/zexus/stdlib/test_runner.zx +119 -0
- package/src/zexus/stdlib_integration.py +341 -0
- package/src/zexus/strategy_recovery.py +256 -0
- package/src/zexus/syntax_validator.py +356 -0
- package/src/zexus/testing/zpics.py +407 -0
- package/src/zexus/testing/zpics_runtime.py +369 -0
- package/src/zexus/type_system.py +374 -0
- package/src/zexus/validation_system.py +569 -0
- package/src/zexus/virtual_filesystem.py +355 -0
- package/src/zexus/vm/__init__.py +8 -0
- package/src/zexus/vm/__pycache__/__init__.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/async_optimizer.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/bytecode.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/cache.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/jit.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/memory_manager.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/memory_pool.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/optimizer.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/parallel_vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/peephole_optimizer.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/profiler.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/register_allocator.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/register_vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/ssa_converter.cpython-312.pyc +0 -0
- package/src/zexus/vm/__pycache__/vm.cpython-312.pyc +0 -0
- package/src/zexus/vm/async_optimizer.py +420 -0
- package/src/zexus/vm/bytecode.py +428 -0
- package/src/zexus/vm/bytecode_converter.py +297 -0
- package/src/zexus/vm/cache.py +532 -0
- package/src/zexus/vm/jit.py +720 -0
- package/src/zexus/vm/memory_manager.py +520 -0
- package/src/zexus/vm/memory_pool.py +511 -0
- package/src/zexus/vm/optimizer.py +478 -0
- package/src/zexus/vm/parallel_vm.py +899 -0
- package/src/zexus/vm/peephole_optimizer.py +452 -0
- package/src/zexus/vm/profiler.py +527 -0
- package/src/zexus/vm/register_allocator.py +462 -0
- package/src/zexus/vm/register_vm.py +520 -0
- package/src/zexus/vm/ssa_converter.py +757 -0
- package/src/zexus/vm/vm.py +1392 -0
- package/src/zexus/zexus_ast.py +1782 -0
- package/src/zexus/zexus_token.py +253 -0
- package/src/zexus/zpm/__init__.py +15 -0
- package/src/zexus/zpm/installer.py +116 -0
- package/src/zexus/zpm/package_manager.py +208 -0
- package/src/zexus/zpm/publisher.py +98 -0
- package/src/zexus/zpm/registry.py +110 -0
- package/src/zexus.egg-info/PKG-INFO +2235 -0
- package/src/zexus.egg-info/SOURCES.txt +876 -0
- package/src/zexus.egg-info/dependency_links.txt +1 -0
- package/src/zexus.egg-info/entry_points.txt +3 -0
- package/src/zexus.egg-info/not-zip-safe +1 -0
- package/src/zexus.egg-info/requires.txt +14 -0
- package/src/zexus.egg-info/top_level.txt +2 -0
- package/zexus.json +14 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Ecosystem features: package management, profiling hooks, marketplace integration.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict, List, Optional, Tuple, Set, Callable
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
import hashlib
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DependencyType(Enum):
|
|
13
|
+
"""Type of dependency."""
|
|
14
|
+
RUNTIME = "runtime"
|
|
15
|
+
DEVELOPMENT = "development"
|
|
16
|
+
OPTIONAL = "optional"
|
|
17
|
+
PEER = "peer"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass
|
|
21
|
+
class PackageVersion:
|
|
22
|
+
"""Package version information."""
|
|
23
|
+
version: str
|
|
24
|
+
released: datetime
|
|
25
|
+
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
26
|
+
|
|
27
|
+
def is_compatible_with(self, required_version: str) -> bool:
|
|
28
|
+
"""Check version compatibility."""
|
|
29
|
+
# Simplified: exact match or wildcard
|
|
30
|
+
if required_version == "*":
|
|
31
|
+
return True
|
|
32
|
+
if required_version.startswith("^"):
|
|
33
|
+
return self.version.startswith(required_version[1])
|
|
34
|
+
return self.version == required_version
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass
|
|
38
|
+
class PackageDependency:
|
|
39
|
+
"""Package dependency specification."""
|
|
40
|
+
name: str
|
|
41
|
+
version: str # Version constraint (e.g., "^1.0.0", "1.2.3", "*")
|
|
42
|
+
type: DependencyType = DependencyType.RUNTIME
|
|
43
|
+
optional: bool = False
|
|
44
|
+
|
|
45
|
+
def is_satisfied_by(self, installed_version: str) -> bool:
|
|
46
|
+
"""Check if installed version satisfies constraint."""
|
|
47
|
+
if self.version == "*":
|
|
48
|
+
return True
|
|
49
|
+
if self.version.startswith("^"):
|
|
50
|
+
return installed_version.startswith(self.version[1])
|
|
51
|
+
return installed_version == self.version
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass
|
|
55
|
+
class PackageMetadata:
|
|
56
|
+
"""Package metadata."""
|
|
57
|
+
name: str
|
|
58
|
+
version: str
|
|
59
|
+
author: str = ""
|
|
60
|
+
description: str = ""
|
|
61
|
+
license: str = ""
|
|
62
|
+
homepage: str = ""
|
|
63
|
+
repository: str = ""
|
|
64
|
+
keywords: List[str] = field(default_factory=list)
|
|
65
|
+
dependencies: Dict[str, PackageDependency] = field(default_factory=dict)
|
|
66
|
+
|
|
67
|
+
def get_hash(self) -> str:
|
|
68
|
+
"""Get package hash for integrity checking."""
|
|
69
|
+
content = f"{self.name}@{self.version}"
|
|
70
|
+
return hashlib.sha256(content.encode()).hexdigest()[:16]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class PackageRegistry:
|
|
74
|
+
"""Central package registry."""
|
|
75
|
+
|
|
76
|
+
def __init__(self):
|
|
77
|
+
"""Initialize package registry."""
|
|
78
|
+
self.packages: Dict[str, Dict[str, PackageMetadata]] = {} # name -> version -> metadata
|
|
79
|
+
self.cache: Dict[str, bytes] = {} # package_id -> bytecode
|
|
80
|
+
|
|
81
|
+
def publish(self, metadata: PackageMetadata, bytecode: Optional[bytes] = None):
|
|
82
|
+
"""Publish a package."""
|
|
83
|
+
if metadata.name not in self.packages:
|
|
84
|
+
self.packages[metadata.name] = {}
|
|
85
|
+
|
|
86
|
+
self.packages[metadata.name][metadata.version] = metadata
|
|
87
|
+
|
|
88
|
+
if bytecode:
|
|
89
|
+
package_id = f"{metadata.name}@{metadata.version}"
|
|
90
|
+
self.cache[package_id] = bytecode
|
|
91
|
+
|
|
92
|
+
def find_package(self, name: str, version: str) -> Optional[PackageMetadata]:
|
|
93
|
+
"""Find package by name and version."""
|
|
94
|
+
if name not in self.packages:
|
|
95
|
+
return None
|
|
96
|
+
return self.packages[name].get(version)
|
|
97
|
+
|
|
98
|
+
def find_compatible_version(self, name: str, constraint: str) -> Optional[str]:
|
|
99
|
+
"""Find compatible version for constraint."""
|
|
100
|
+
if name not in self.packages:
|
|
101
|
+
return None
|
|
102
|
+
|
|
103
|
+
versions = list(self.packages[name].keys())
|
|
104
|
+
|
|
105
|
+
# Simplified: match exact or take latest
|
|
106
|
+
if constraint == "*":
|
|
107
|
+
return versions[-1] if versions else None
|
|
108
|
+
|
|
109
|
+
if constraint.startswith("^"):
|
|
110
|
+
prefix = constraint[1]
|
|
111
|
+
matching = [v for v in versions if v.startswith(prefix)]
|
|
112
|
+
return matching[-1] if matching else None
|
|
113
|
+
|
|
114
|
+
if constraint in versions:
|
|
115
|
+
return constraint
|
|
116
|
+
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
def resolve_dependencies(self, package: PackageMetadata,
|
|
120
|
+
resolved: Optional[Set[str]] = None) -> Dict[str, PackageMetadata]:
|
|
121
|
+
"""Resolve package dependencies recursively."""
|
|
122
|
+
if resolved is None:
|
|
123
|
+
resolved = set()
|
|
124
|
+
|
|
125
|
+
result = {}
|
|
126
|
+
package_id = f"{package.name}@{package.version}"
|
|
127
|
+
|
|
128
|
+
if package_id in resolved:
|
|
129
|
+
return result
|
|
130
|
+
|
|
131
|
+
resolved.add(package_id)
|
|
132
|
+
|
|
133
|
+
for dep_name, dep in package.dependencies.items():
|
|
134
|
+
version = self.find_compatible_version(dep_name, dep.version)
|
|
135
|
+
if version:
|
|
136
|
+
dep_pkg = self.find_package(dep_name, version)
|
|
137
|
+
if dep_pkg:
|
|
138
|
+
result[f"{dep_name}@{version}"] = dep_pkg
|
|
139
|
+
# Recursively resolve
|
|
140
|
+
result.update(self.resolve_dependencies(dep_pkg, resolved))
|
|
141
|
+
|
|
142
|
+
return result
|
|
143
|
+
|
|
144
|
+
def list_packages(self) -> List[str]:
|
|
145
|
+
"""List all package names."""
|
|
146
|
+
return list(self.packages.keys())
|
|
147
|
+
|
|
148
|
+
def list_versions(self, name: str) -> List[str]:
|
|
149
|
+
"""List all versions of a package."""
|
|
150
|
+
return list(self.packages.get(name, {}).keys())
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class PackageManager:
|
|
154
|
+
"""Package management system."""
|
|
155
|
+
|
|
156
|
+
def __init__(self, registry: Optional[PackageRegistry] = None):
|
|
157
|
+
"""Initialize package manager."""
|
|
158
|
+
self.registry = registry or PackageRegistry()
|
|
159
|
+
self.installed: Dict[str, str] = {} # name -> version
|
|
160
|
+
self.lock_file: Dict[str, Tuple[str, str]] = {} # name -> (version, hash)
|
|
161
|
+
|
|
162
|
+
def install(self, name: str, version: str = "*") -> bool:
|
|
163
|
+
"""Install package."""
|
|
164
|
+
resolved_version = self.registry.find_compatible_version(name, version)
|
|
165
|
+
if not resolved_version:
|
|
166
|
+
return False
|
|
167
|
+
|
|
168
|
+
package = self.registry.find_package(name, resolved_version)
|
|
169
|
+
if not package:
|
|
170
|
+
return False
|
|
171
|
+
|
|
172
|
+
# Resolve and install dependencies
|
|
173
|
+
deps = self.registry.resolve_dependencies(package)
|
|
174
|
+
for dep_id, dep_pkg in deps.items():
|
|
175
|
+
self.installed[dep_pkg.name] = dep_pkg.version
|
|
176
|
+
self.lock_file[dep_pkg.name] = (dep_pkg.version, dep_pkg.get_hash())
|
|
177
|
+
|
|
178
|
+
# Install package itself
|
|
179
|
+
self.installed[name] = resolved_version
|
|
180
|
+
self.lock_file[name] = (resolved_version, package.get_hash())
|
|
181
|
+
|
|
182
|
+
return True
|
|
183
|
+
|
|
184
|
+
def uninstall(self, name: str) -> bool:
|
|
185
|
+
"""Uninstall package."""
|
|
186
|
+
if name in self.installed:
|
|
187
|
+
del self.installed[name]
|
|
188
|
+
if name in self.lock_file:
|
|
189
|
+
del self.lock_file[name]
|
|
190
|
+
return True
|
|
191
|
+
return False
|
|
192
|
+
|
|
193
|
+
def is_installed(self, name: str, version: Optional[str] = None) -> bool:
|
|
194
|
+
"""Check if package is installed."""
|
|
195
|
+
if name not in self.installed:
|
|
196
|
+
return False
|
|
197
|
+
if version:
|
|
198
|
+
return self.installed[name] == version
|
|
199
|
+
return True
|
|
200
|
+
|
|
201
|
+
def get_installed_packages(self) -> Dict[str, str]:
|
|
202
|
+
"""Get all installed packages."""
|
|
203
|
+
return self.installed.copy()
|
|
204
|
+
|
|
205
|
+
def verify_integrity(self, name: str) -> bool:
|
|
206
|
+
"""Verify package integrity."""
|
|
207
|
+
if name not in self.lock_file:
|
|
208
|
+
return False
|
|
209
|
+
|
|
210
|
+
version, expected_hash = self.lock_file[name]
|
|
211
|
+
package = self.registry.find_package(name, version)
|
|
212
|
+
|
|
213
|
+
if not package:
|
|
214
|
+
return False
|
|
215
|
+
|
|
216
|
+
return package.get_hash() == expected_hash
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
class PerformanceProfiler:
|
|
220
|
+
"""Performance profiler for functions."""
|
|
221
|
+
|
|
222
|
+
def __init__(self):
|
|
223
|
+
"""Initialize profiler."""
|
|
224
|
+
self.profiles: Dict[str, 'FunctionProfile'] = {}
|
|
225
|
+
self.hooks: List[Callable] = []
|
|
226
|
+
|
|
227
|
+
def profile_function(self, name: str) -> 'FunctionProfile':
|
|
228
|
+
"""Create profile for function."""
|
|
229
|
+
if name not in self.profiles:
|
|
230
|
+
self.profiles[name] = FunctionProfile(name)
|
|
231
|
+
return self.profiles[name]
|
|
232
|
+
|
|
233
|
+
def register_hook(self, hook: Callable):
|
|
234
|
+
"""Register profiling hook."""
|
|
235
|
+
self.hooks.append(hook)
|
|
236
|
+
|
|
237
|
+
def record_call(self, name: str, duration: float, args_size: int = 0, return_size: int = 0):
|
|
238
|
+
"""Record function call."""
|
|
239
|
+
if name not in self.profiles:
|
|
240
|
+
self.profile_function(name)
|
|
241
|
+
|
|
242
|
+
profile = self.profiles[name]
|
|
243
|
+
profile.record_call(duration, args_size, return_size)
|
|
244
|
+
|
|
245
|
+
# Trigger hooks
|
|
246
|
+
for hook in self.hooks:
|
|
247
|
+
try:
|
|
248
|
+
hook(profile, duration)
|
|
249
|
+
except Exception:
|
|
250
|
+
pass
|
|
251
|
+
|
|
252
|
+
def get_profile(self, name: str) -> Optional['FunctionProfile']:
|
|
253
|
+
"""Get function profile."""
|
|
254
|
+
return self.profiles.get(name)
|
|
255
|
+
|
|
256
|
+
def get_slowest_functions(self, count: int = 10) -> List[Tuple[str, float]]:
|
|
257
|
+
"""Get slowest functions."""
|
|
258
|
+
items = [(name, prof.total_time) for name, prof in self.profiles.items()]
|
|
259
|
+
items.sort(key=lambda x: x[1], reverse=True)
|
|
260
|
+
return items[:count]
|
|
261
|
+
|
|
262
|
+
def get_hottest_functions(self, count: int = 10) -> List[Tuple[str, int]]:
|
|
263
|
+
"""Get most frequently called functions."""
|
|
264
|
+
items = [(name, prof.call_count) for name, prof in self.profiles.items()]
|
|
265
|
+
items.sort(key=lambda x: x[1], reverse=True)
|
|
266
|
+
return items[:count]
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
@dataclass
|
|
270
|
+
class FunctionProfile:
|
|
271
|
+
"""Profile for a single function."""
|
|
272
|
+
name: str
|
|
273
|
+
call_count: int = 0
|
|
274
|
+
total_time: float = 0.0
|
|
275
|
+
min_time: float = float('inf')
|
|
276
|
+
max_time: float = 0.0
|
|
277
|
+
total_args_size: int = 0
|
|
278
|
+
total_return_size: int = 0
|
|
279
|
+
|
|
280
|
+
def record_call(self, duration: float, args_size: int = 0, return_size: int = 0):
|
|
281
|
+
"""Record a call."""
|
|
282
|
+
self.call_count += 1
|
|
283
|
+
self.total_time += duration
|
|
284
|
+
self.min_time = min(self.min_time, duration)
|
|
285
|
+
self.max_time = max(self.max_time, duration)
|
|
286
|
+
self.total_args_size += args_size
|
|
287
|
+
self.total_return_size += return_size
|
|
288
|
+
|
|
289
|
+
def get_avg_time(self) -> float:
|
|
290
|
+
"""Get average call time."""
|
|
291
|
+
return self.total_time / self.call_count if self.call_count > 0 else 0.0
|
|
292
|
+
|
|
293
|
+
def get_avg_args_size(self) -> float:
|
|
294
|
+
"""Get average arguments size."""
|
|
295
|
+
return self.total_args_size / self.call_count if self.call_count > 0 else 0.0
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
class PluginMarketplace:
|
|
299
|
+
"""Plugin marketplace for discovering and managing plugins."""
|
|
300
|
+
|
|
301
|
+
def __init__(self):
|
|
302
|
+
"""Initialize marketplace."""
|
|
303
|
+
self.plugins: Dict[str, 'MarketplacePlugin'] = {}
|
|
304
|
+
self.categories: Dict[str, List[str]] = {} # category -> plugin names
|
|
305
|
+
self.ratings: Dict[str, Tuple[float, int]] = {} # plugin_name -> (avg_rating, count)
|
|
306
|
+
|
|
307
|
+
@dataclass
|
|
308
|
+
class MarketplacePlugin:
|
|
309
|
+
"""Plugin listing in marketplace."""
|
|
310
|
+
name: str
|
|
311
|
+
version: str
|
|
312
|
+
author: str
|
|
313
|
+
description: str
|
|
314
|
+
category: str
|
|
315
|
+
requires_capabilities: Set[str] = field(default_factory=set)
|
|
316
|
+
homepage: str = ""
|
|
317
|
+
downloads: int = 0
|
|
318
|
+
|
|
319
|
+
def __hash__(self):
|
|
320
|
+
return hash(f"{self.name}@{self.version}")
|
|
321
|
+
|
|
322
|
+
def publish_plugin(self, plugin: 'PluginMarketplace.MarketplacePlugin'):
|
|
323
|
+
"""Publish plugin to marketplace."""
|
|
324
|
+
self.plugins[plugin.name] = plugin
|
|
325
|
+
|
|
326
|
+
if plugin.category not in self.categories:
|
|
327
|
+
self.categories[plugin.category] = []
|
|
328
|
+
if plugin.name not in self.categories[plugin.category]:
|
|
329
|
+
self.categories[plugin.category].append(plugin.name)
|
|
330
|
+
|
|
331
|
+
def search_by_name(self, query: str) -> List['PluginMarketplace.MarketplacePlugin']:
|
|
332
|
+
"""Search plugins by name."""
|
|
333
|
+
results = []
|
|
334
|
+
for name, plugin in self.plugins.items():
|
|
335
|
+
if query.lower() in name.lower():
|
|
336
|
+
results.append(plugin)
|
|
337
|
+
return results
|
|
338
|
+
|
|
339
|
+
def search_by_category(self, category: str) -> List['PluginMarketplace.MarketplacePlugin']:
|
|
340
|
+
"""Search plugins by category."""
|
|
341
|
+
names = self.categories.get(category, [])
|
|
342
|
+
return [self.plugins[name] for name in names if name in self.plugins]
|
|
343
|
+
|
|
344
|
+
def get_trending(self, count: int = 10) -> List['PluginMarketplace.MarketplacePlugin']:
|
|
345
|
+
"""Get trending plugins (most downloaded)."""
|
|
346
|
+
plugins = sorted(
|
|
347
|
+
self.plugins.values(),
|
|
348
|
+
key=lambda p: p.downloads,
|
|
349
|
+
reverse=True
|
|
350
|
+
)
|
|
351
|
+
return plugins[:count]
|
|
352
|
+
|
|
353
|
+
def rate_plugin(self, name: str, rating: float) -> bool:
|
|
354
|
+
"""Rate a plugin (1-5 stars)."""
|
|
355
|
+
if name not in self.plugins:
|
|
356
|
+
return False
|
|
357
|
+
|
|
358
|
+
if rating < 1 or rating > 5:
|
|
359
|
+
return False
|
|
360
|
+
|
|
361
|
+
if name not in self.ratings:
|
|
362
|
+
self.ratings[name] = (rating, 1)
|
|
363
|
+
else:
|
|
364
|
+
avg, count = self.ratings[name]
|
|
365
|
+
new_avg = (avg * count + rating) / (count + 1)
|
|
366
|
+
self.ratings[name] = (new_avg, count + 1)
|
|
367
|
+
|
|
368
|
+
return True
|
|
369
|
+
|
|
370
|
+
def get_rating(self, name: str) -> Optional[Tuple[float, int]]:
|
|
371
|
+
"""Get plugin rating."""
|
|
372
|
+
return self.ratings.get(name)
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
class EcosystemManager:
|
|
376
|
+
"""Central ecosystem manager."""
|
|
377
|
+
|
|
378
|
+
def __init__(self):
|
|
379
|
+
"""Initialize ecosystem manager."""
|
|
380
|
+
self.package_manager = PackageManager()
|
|
381
|
+
self.profiler = PerformanceProfiler()
|
|
382
|
+
self.marketplace = PluginMarketplace()
|
|
383
|
+
|
|
384
|
+
def get_package_manager(self) -> PackageManager:
|
|
385
|
+
"""Get package manager."""
|
|
386
|
+
return self.package_manager
|
|
387
|
+
|
|
388
|
+
def get_profiler(self) -> PerformanceProfiler:
|
|
389
|
+
"""Get profiler."""
|
|
390
|
+
return self.profiler
|
|
391
|
+
|
|
392
|
+
def get_marketplace(self) -> PluginMarketplace:
|
|
393
|
+
"""Get marketplace."""
|
|
394
|
+
return self.marketplace
|
|
395
|
+
|
|
396
|
+
def get_ecosystem_stats(self) -> Dict[str, Any]:
|
|
397
|
+
"""Get ecosystem statistics."""
|
|
398
|
+
packages = self.package_manager.get_installed_packages()
|
|
399
|
+
|
|
400
|
+
total_calls = sum(p.call_count for p in self.profiler.profiles.values())
|
|
401
|
+
total_time = sum(p.total_time for p in self.profiler.profiles.values())
|
|
402
|
+
|
|
403
|
+
return {
|
|
404
|
+
"installed_packages": len(packages),
|
|
405
|
+
"total_function_calls": total_calls,
|
|
406
|
+
"total_execution_time": total_time,
|
|
407
|
+
"profiled_functions": len(self.profiler.profiles),
|
|
408
|
+
"marketplace_plugins": len(self.marketplace.plugins),
|
|
409
|
+
"plugin_categories": len(self.marketplace.categories)
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
# Global ecosystem manager
|
|
414
|
+
_global_ecosystem = EcosystemManager()
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def get_ecosystem() -> EcosystemManager:
|
|
418
|
+
"""Get global ecosystem manager."""
|
|
419
|
+
return _global_ecosystem
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def get_package_manager() -> PackageManager:
|
|
423
|
+
"""Get global package manager."""
|
|
424
|
+
return _global_ecosystem.package_manager
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def get_profiler() -> PerformanceProfiler:
|
|
428
|
+
"""Get global profiler."""
|
|
429
|
+
return _global_ecosystem.profiler
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
def get_marketplace() -> PluginMarketplace:
|
|
433
|
+
"""Get global marketplace."""
|
|
434
|
+
return _global_ecosystem.marketplace
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# environment.py
|
|
2
|
+
|
|
3
|
+
class Environment:
|
|
4
|
+
def __init__(self, outer=None):
|
|
5
|
+
self.store = {}
|
|
6
|
+
self.outer = outer
|
|
7
|
+
self.exports = {}
|
|
8
|
+
self.modules = {}
|
|
9
|
+
self._debug = False
|
|
10
|
+
|
|
11
|
+
def get(self, name):
|
|
12
|
+
"""Get a value from the environment"""
|
|
13
|
+
# Check local store
|
|
14
|
+
value = self.store.get(name)
|
|
15
|
+
if value is not None:
|
|
16
|
+
return value
|
|
17
|
+
|
|
18
|
+
# Check modules
|
|
19
|
+
if "." in name:
|
|
20
|
+
module_name, var_name = name.split(".", 1)
|
|
21
|
+
module = self.modules.get(module_name)
|
|
22
|
+
if module:
|
|
23
|
+
return module.get(var_name)
|
|
24
|
+
|
|
25
|
+
# Check outer scope
|
|
26
|
+
if self.outer:
|
|
27
|
+
return self.outer.get(name)
|
|
28
|
+
|
|
29
|
+
return None
|
|
30
|
+
|
|
31
|
+
def set(self, name, value):
|
|
32
|
+
"""Set a value in the environment (creates new variable)"""
|
|
33
|
+
if "." in name:
|
|
34
|
+
module_name, var_name = name.split(".", 1)
|
|
35
|
+
module = self.modules.get(module_name)
|
|
36
|
+
if module:
|
|
37
|
+
module.set(var_name, value)
|
|
38
|
+
else:
|
|
39
|
+
# Create new module environment
|
|
40
|
+
module = Environment(self)
|
|
41
|
+
module.set(var_name, value)
|
|
42
|
+
self.modules[module_name] = module
|
|
43
|
+
else:
|
|
44
|
+
self.store[name] = value
|
|
45
|
+
|
|
46
|
+
def assign(self, name, value):
|
|
47
|
+
"""Assign to an existing variable or create if doesn't exist.
|
|
48
|
+
|
|
49
|
+
This is used for reassignment (like in loops). It will:
|
|
50
|
+
1. Update the variable in the scope where it was first defined
|
|
51
|
+
2. Create a new variable in current scope if it doesn't exist anywhere
|
|
52
|
+
"""
|
|
53
|
+
# Check if variable exists in current scope
|
|
54
|
+
if name in self.store:
|
|
55
|
+
self.store[name] = value
|
|
56
|
+
return
|
|
57
|
+
|
|
58
|
+
# Check if exists in outer scopes by checking the store directly
|
|
59
|
+
if self.outer:
|
|
60
|
+
# Recursively check if the name exists in any outer scope
|
|
61
|
+
if self._has_variable(name):
|
|
62
|
+
# Try to assign in outer scope
|
|
63
|
+
self.outer.assign(name, value)
|
|
64
|
+
return
|
|
65
|
+
|
|
66
|
+
# Variable doesn't exist anywhere, create it in current scope
|
|
67
|
+
self.store[name] = value
|
|
68
|
+
|
|
69
|
+
def _has_variable(self, name):
|
|
70
|
+
"""Check if a variable name exists in this scope or any outer scope."""
|
|
71
|
+
if name in self.store:
|
|
72
|
+
return True
|
|
73
|
+
if self.outer and hasattr(self.outer, '_has_variable'):
|
|
74
|
+
return self.outer._has_variable(name)
|
|
75
|
+
return False
|
|
76
|
+
|
|
77
|
+
def export(self, name, value):
|
|
78
|
+
"""Export a value"""
|
|
79
|
+
self.exports[name] = value
|
|
80
|
+
self.store[name] = value
|
|
81
|
+
|
|
82
|
+
def get_exports(self):
|
|
83
|
+
"""Get all exported values"""
|
|
84
|
+
return self.exports.copy()
|
|
85
|
+
|
|
86
|
+
def import_module(self, name, module_env):
|
|
87
|
+
"""Import a module environment"""
|
|
88
|
+
self.modules[name] = module_env
|
|
89
|
+
|
|
90
|
+
def enable_debug(self):
|
|
91
|
+
"""Enable debug logging"""
|
|
92
|
+
self._debug = True
|
|
93
|
+
|
|
94
|
+
def disable_debug(self):
|
|
95
|
+
"""Disable debug logging"""
|
|
96
|
+
self._debug = False
|
|
97
|
+
|
|
98
|
+
def debug_log(self, message):
|
|
99
|
+
"""Log debug message if debug is enabled"""
|
|
100
|
+
if self._debug:
|
|
101
|
+
print(f"[ENV] {message}")
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# environment_manager.py
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from .environment import Environment
|
|
6
|
+
|
|
7
|
+
class EnvironmentManager:
|
|
8
|
+
def __init__(self, base_path=None):
|
|
9
|
+
"""Initialize the environment manager
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
base_path: Base path for resolving module paths. Defaults to cwd.
|
|
13
|
+
"""
|
|
14
|
+
self.base_path = Path(base_path or os.getcwd())
|
|
15
|
+
self.module_cache = {}
|
|
16
|
+
self.search_paths = [
|
|
17
|
+
self.base_path,
|
|
18
|
+
self.base_path / "zpm_modules", # Keep zpm_modules as primary module path
|
|
19
|
+
self.base_path / "lib"
|
|
20
|
+
]
|
|
21
|
+
self._debug = False
|
|
22
|
+
|
|
23
|
+
def normalize_path(self, path):
|
|
24
|
+
"""Normalize a file path"""
|
|
25
|
+
return str(Path(path).resolve())
|
|
26
|
+
|
|
27
|
+
def resolve_module_path(self, file_path):
|
|
28
|
+
"""Resolve a module path to an absolute path
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
file_path: File path as a string (from UseStatement/FromStatement)
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
Absolute Path object or None if not found
|
|
35
|
+
"""
|
|
36
|
+
try:
|
|
37
|
+
# Handle absolute paths
|
|
38
|
+
if str(file_path).startswith("/"):
|
|
39
|
+
path = Path(file_path)
|
|
40
|
+
if path.exists():
|
|
41
|
+
return path.resolve()
|
|
42
|
+
|
|
43
|
+
# Handle relative paths
|
|
44
|
+
if str(file_path).startswith("./") or str(file_path).startswith("../"):
|
|
45
|
+
path = (self.base_path / file_path).resolve()
|
|
46
|
+
if path.exists():
|
|
47
|
+
return path
|
|
48
|
+
|
|
49
|
+
# Search in module paths
|
|
50
|
+
for search_path in self.search_paths:
|
|
51
|
+
# Try exact path
|
|
52
|
+
path = search_path / file_path
|
|
53
|
+
if path.exists():
|
|
54
|
+
return path.resolve()
|
|
55
|
+
|
|
56
|
+
# Try with .zx extension
|
|
57
|
+
path_with_ext = search_path / f"{file_path}.zx"
|
|
58
|
+
if path_with_ext.exists():
|
|
59
|
+
return path_with_ext.resolve()
|
|
60
|
+
|
|
61
|
+
# Try with index.zx in directory
|
|
62
|
+
path_index = search_path / file_path / "index.zx"
|
|
63
|
+
if path_index.exists():
|
|
64
|
+
return path_index.resolve()
|
|
65
|
+
|
|
66
|
+
except Exception as e:
|
|
67
|
+
if self._debug:
|
|
68
|
+
print(f"[ENV] Error resolving module path '{file_path}': {e}")
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
return None
|
|
72
|
+
|
|
73
|
+
def get_module(self, file_path):
|
|
74
|
+
"""Get a cached module environment
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
file_path: Absolute path to module file
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
Cached Environment or None
|
|
81
|
+
"""
|
|
82
|
+
normalized = self.normalize_path(file_path)
|
|
83
|
+
return self.module_cache.get(normalized)
|
|
84
|
+
|
|
85
|
+
def cache_module(self, file_path, module_env):
|
|
86
|
+
"""Cache a module environment
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
file_path: Absolute path to module file
|
|
90
|
+
module_env: Environment instance to cache
|
|
91
|
+
"""
|
|
92
|
+
normalized = self.normalize_path(file_path)
|
|
93
|
+
self.module_cache[normalized] = module_env
|
|
94
|
+
|
|
95
|
+
def clear_cache(self):
|
|
96
|
+
"""Clear the module cache"""
|
|
97
|
+
self.module_cache.clear()
|
|
98
|
+
if self._debug:
|
|
99
|
+
print("[ENV] Module cache cleared")
|
|
100
|
+
|
|
101
|
+
def add_search_path(self, path):
|
|
102
|
+
"""Add a path to module search paths
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
path: Directory path to add to search paths
|
|
106
|
+
"""
|
|
107
|
+
path = Path(path).resolve()
|
|
108
|
+
if path not in self.search_paths:
|
|
109
|
+
self.search_paths.append(path)
|
|
110
|
+
if self._debug:
|
|
111
|
+
print(f"[ENV] Added search path: {path}")
|
|
112
|
+
|
|
113
|
+
def enable_debug(self):
|
|
114
|
+
"""Enable debug logging"""
|
|
115
|
+
self._debug = True
|
|
116
|
+
|
|
117
|
+
def disable_debug(self):
|
|
118
|
+
"""Disable debug logging"""
|
|
119
|
+
self._debug = False
|