-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathfix_rust_errors2.py
More file actions
92 lines (82 loc) · 4.4 KB
/
Copy pathfix_rust_errors2.py
File metadata and controls
92 lines (82 loc) · 4.4 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
import os
import re
def replace_in_file(path, old, new):
if not os.path.exists(path): return
with open(path, 'r', encoding='utf-8') as f:
c = f.read()
if old in c:
c = c.replace(old, new)
with open(path, 'w', encoding='utf-8') as f:
f.write(c)
def regex_replace_in_file(path, pattern, repl):
if not os.path.exists(path): return
with open(path, 'r', encoding='utf-8') as f:
c = f.read()
new_c = re.sub(pattern, repl, c)
if c != new_c:
with open(path, 'w', encoding='utf-8') as f:
f.write(new_c)
# ai_refactor.rs
replace_in_file('src/utils/ai_refactor.rs', 'handle_refactor(file, ', 'handle_refactor(&file, ')
replace_in_file('src/utils/ai_refactor.rs', 'use colored::Colorize;', 'use colored::Colorize;\nuse crossterm::style::stylize::Stylize;')
# test_optimizer.rs
regex_replace_in_file('src/utils/test_optimizer.rs', r'let \(io_bound, cpu_bound, memory_bound, general\): \(Vec<\_>, Vec<\_>, Vec<\_>, Vec<\_>\) = tests\s*\n\s*\.iter\(\)\s*\n\s*\.cloned\(\)\s*\n\s*\.partition\(\|t\| t\.resource_profile\.io_intensity > 0\.6\);',
'''let (io_bound, _other): (Vec<_>, Vec<_>) = tests.iter().cloned().partition(|t| t.resource_profile.io_intensity > 0.6);
let cpu_bound = vec![];
let memory_bound = vec![];
let general = vec![];''')
# plugin.rs
replace_in_file('src/commands/plugin.rs',
''' registry::install_plugin(
&pl.name,
&pl.path.display().to_string(),
&pl.source,
&pl.plugin_version,
pl.commands.clone(),
pl.starforge_version.clone(),
)''',
''' registry::install_plugin(
&pl.name,
&pl.path.display().to_string(),
&pl.source,
&pl.plugin_version,
"",
pl.commands.clone(),
pl.starforge_version.clone(),
)''')
replace_in_file('src/commands/plugin.rs',
''' registry::install_plugin(
&pl.name,
&pl.path.display().to_string(),
&pl.source,
&pl.plugin_version,
cmds,
pl.starforge_version.clone(),
)''',
''' registry::install_plugin(
&pl.name,
&pl.path.display().to_string(),
&pl.source,
&pl.plugin_version,
"",
cmds,
pl.starforge_version.clone(),
)''')
replace_in_file('src/commands/plugin.rs', '&plugin_description', '""')
replace_in_file('src/commands/plugin.rs', 'pl.description.clone()', 'None')
replace_in_file('src/commands/plugin.rs', 'registry::plugin_list_entries', 'crate::plugins::registry::plugin_list_entries')
# compliance.rs / analytics.rs
replace_in_file('src/commands/analytics.rs', '"Likely ✓".green().to_string()', '(&"Likely ✓".green().to_string()).to_string()')
replace_in_file('src/commands/analytics.rs', '"At risk ✗".red().to_string()', '(&"At risk ✗".red().to_string()).to_string()')
replace_in_file('src/commands/compliance.rs', '"yes".green().to_string()', '(&"yes".green().to_string()).to_string()')
replace_in_file('src/commands/compliance.rs', '"no".red().to_string()', '(&"no".red().to_string()).to_string()')
replace_in_file('src/commands/compliance.rs', '"PASSED".green().to_string()', '(&"PASSED".green().to_string()).to_string()')
replace_in_file('src/commands/compliance.rs', '"FAILED".red().to_string()', '(&"FAILED".red().to_string()).to_string()')
# ai_deploy_docs.rs
replace_in_file('src/commands/ai_deploy_docs.rs', 'write_file(&path, content)?;', 'write_file(&path, &content)?;')
# ai_validation.rs
replace_in_file('src/utils/ai_validation.rs', 'let mut warnings = Vec::new();', 'let mut warnings: Vec<String> = Vec::new();')
# contract.rs
replace_in_file('src/commands/contract.rs', 'ContractCommands::Version(args) => handle_version(args),', 'ContractCommands::Version(args) => handle_version(args).await,')
# wait, maybe it's not async or not imported? Let's assume it needs .await
print("Applied fixes 2")