Repository navigation
Expand file tree
/
Copy pathbasic_usage.py
More file actions
111 lines (83 loc) · 2.87 KB
/
Copy pathbasic_usage.py
File metadata and controls
111 lines (83 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""
Basic usage examples for Load
"""
import sys
from pathlib import Path
import types
# Add src to path for development
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
# Import load functions
from load import load, enable_auto_print, disable_auto_print, set_print_limit, smart_print
def basic_examples():
"""Basic Load examples"""
print("🔥 Load Basic Examples")
print("=" * 50)
# Load stdlib modules - these always work
print("\n📚 Loading standard library modules:")
json = load('json')
print(f" json: {type(json).__name__}")
print("✅ JSON loaded")
os = load('os')
print(f" os: {type(os).__name__}")
print("✅ OS loaded")
sys = load('sys')
print(f" sys: {type(sys).__name__}")
print("✅ SYS loaded")
# Test basic functionality
print(f"\n🧪 Testing functionality:")
data = {"test": "data"}
json_str = json.dumps(data)
parsed = json.loads(json_str)
print(f"✅ JSON dumps/loads: {parsed}")
current_dir = os.getcwd()
print(f"✅ OS getcwd: {current_dir}")
python_version = sys.version_info
print(f"✅ SYS version: {python_version.major}.{python_version.minor}")
# Show cache info
print(f"\n💾 Cache info:")
from load import info
cache_info = info()
print(f"📊 Cache Statistics:")
print(f" Total cached modules: {cache_info['cache_size']}")
print(f" Auto-print enabled: {cache_info['auto_print']}")
print(f" Print limit: {cache_info['print_limit']}")
cached = ", ".join(cache_info["cached_modules"])
print(f" Cached modules: {cached}")
print(f"\n✅ Basic examples completed successfully!")
def test_auto_print():
"""Test auto-print functionality"""
print("\n📊 Testing auto-print:")
# Enable auto-print
enable_auto_print()
# This should auto-print
time_lib = load('time', silent=False)
# Disable auto-print
disable_auto_print()
# This should be silent
math_lib = load('math', silent=False)
print("✅ Auto-print test completed")
def test_aliases():
"""Test alias functionality"""
print("\n🏷️ Testing aliases:")
# Load modules
try:
operating_system = load('os')
print("✅ Successfully loaded os module")
time_module = load('time')
print("✅ Successfully loaded time module")
except Exception as e:
print(f"❌ Error loading modules: {e}")
print("✅ Alias loading completed")
# Check cache
from load import info
cache_info = info()
print(f"📊 Final cache info: {cache_info['cache_size']} modules cached")
if __name__ == "__main__":
try:
basic_examples()
test_auto_print()
test_aliases()
print("\n🎉 All basic examples completed successfully!")
except Exception as e:
print(f"\n❌ Error in basic examples: {e}")
sys.exit(1)