c2r 1.0.0__cp311-cp311-win_amd64.whl → 1.0.1__cp311-cp311-win_amd64.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.
c2r/cli.py CHANGED
@@ -2,6 +2,7 @@ import click
2
2
  import os
3
3
  import sys
4
4
  import shutil
5
+ import json
5
6
  import subprocess
6
7
  from pathlib import Path
7
8
 
@@ -88,12 +89,34 @@ lazy_static = "1.4"
88
89
 
89
90
  main_rs_content = "// Ferrum Generated Main Entry\n\nfn main() {\n println!(\"Hello from Ferrum migrated code!\");\n}\n"
90
91
 
92
+ total_safety_score = 0
93
+ file_count = 0
94
+ report_lines = []
95
+
91
96
  for cpp_file in files_to_process:
92
97
  click.echo(f"Processing {cpp_file.name}...")
93
98
  with open(cpp_file, "r") as f:
94
99
  code = f.read()
95
100
 
96
- rust_code = reconstructor.translate(code)
101
+ # Use new analyze_report API
102
+ json_report = reconstructor.analyze_report(code)
103
+ report = json.loads(json_report)
104
+ rust_code = report["generated_code"]
105
+ safety_score = report["safety_score"]
106
+ unsafe_events = report["unsafe_events"]
107
+
108
+ total_safety_score += safety_score
109
+ file_count += 1
110
+
111
+ report_lines.append(f"## {cpp_file.name}")
112
+ report_lines.append(f"- **Safety Score:** {safety_score:.2f}%")
113
+ if unsafe_events:
114
+ report_lines.append("- **Risks Detected:**")
115
+ for event in unsafe_events:
116
+ report_lines.append(f" - ⚠️ {event}")
117
+ else:
118
+ report_lines.append("- **Status:** Clean")
119
+ report_lines.append("")
97
120
 
98
121
  # Heuristic: if file is named main.cpp, it's main.rs
99
122
  if "main" in cpp_file.name.lower():
@@ -108,8 +131,58 @@ lazy_static = "1.4"
108
131
  f.write(main_rs_content)
109
132
  click.echo("Generated src/main.rs")
110
133
 
134
+ # Generate Formal Report
135
+ avg_score = total_safety_score / file_count if file_count > 0 else 100.0
136
+ report_content = f"""# Migration Report: {input_path.name}
137
+
138
+ **Total Files:** {file_count}
139
+ **Average Safety Score:** {avg_score:.2f}%
140
+
141
+ {chr(10).join(report_lines)}
142
+ """
143
+ with open(output_path / "migration_report.md", "w") as f:
144
+ f.write(report_content)
145
+ click.echo("Generated migration_report.md")
146
+
111
147
  click.echo("\n✅ Migration Complete. Your Rust project is ready.")
112
148
  click.echo(f"Run: cd {output_path} && cargo build")
113
149
 
150
+ @main.command()
151
+ @click.argument('input_path', type=click.Path(exists=True))
152
+ def analyze(input_path):
153
+ """Analyze a C++ project without generating code."""
154
+ input_path = Path(input_path)
155
+ click.echo(f"🔍 Analyzing: {input_path}")
156
+
157
+ try:
158
+ c2r.init_logging()
159
+ except:
160
+ pass
161
+
162
+ reconstructor = c2r.Reconstructor()
163
+
164
+ files = []
165
+ if input_path.is_file():
166
+ files.append(input_path)
167
+ else:
168
+ files.extend(input_path.glob("**/*.cpp"))
169
+
170
+ for cpp_file in files:
171
+ click.echo(f"\n📄 {cpp_file.name}")
172
+ with open(cpp_file, "r") as f:
173
+ code = f.read()
174
+
175
+ json_report = reconstructor.analyze_report(code)
176
+ report = json.loads(json_report)
177
+
178
+ score = report["safety_score"]
179
+ click.echo(f" Safety Score: {score:.2f}%")
180
+
181
+ if report["unsafe_events"]:
182
+ for risk in report["unsafe_events"]:
183
+ click.echo(f" 🔴 RISK: {risk}")
184
+ else:
185
+ click.echo(" ✅ No critical risks detected.")
186
+
114
187
  if __name__ == '__main__':
115
188
  main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: c2r
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -13,7 +13,7 @@ Requires-Dist: click
13
13
  Summary: Deterministic C++ to Rust Transpiler with Industrial-Grade Static Analysis
14
14
  Author-email: Ferrum Team <dev@ferrum.io>
15
15
  License: MIT
16
- Requires-Python: >=3.8
16
+ Requires-Python: >=3.8, <3.13
17
17
  Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
18
18
 
19
19
  # c2r: The Industrial C++ to Rust Transpiler
@@ -0,0 +1,8 @@
1
+ c2r\__init__.py,sha256=ucQESw8DmMUlgbIvhowpcUSqVmdq9NvqLm_U5RE1nuA,22
2
+ c2r\cli.py,sha256=y0m8UBQSkFsK5ORm-6Y1XcTzCTSzNo82_5QMvYvOuBM,5615
3
+ c2r-1.0.1.dist-info\METADATA,sha256=o92oYul96zIdHFAIWOYj52Fnidj5xRakpLPpGEb-CxU,3483
4
+ c2r-1.0.1.dist-info\WHEEL,sha256=X79LywvMB9iCuFHu88xBAFTJDhRqJi6Yh9hhoCI9jao,97
5
+ c2r-1.0.1.dist-info\entry_points.txt,sha256=bUGIN_7y_IZymC9EXuRhEzwdCkdDz9VEYpatKro6kTU,35
6
+ c2r_core\__init__.py,sha256=2sQzOqoWTXAyeQMssALXGlR2daKyZoxUBFRzUTfZ8lU,115
7
+ c2r_core\c2r_core.cp311-win_amd64.pyd,sha256=WjzJAM7fOmIwOTJzILHmjgccQVHlkIl-lOoA9jnr_QQ,2414592
8
+ c2r-1.0.1.dist-info\RECORD,,
Binary file
@@ -1,8 +0,0 @@
1
- c2r\__init__.py,sha256=ucQESw8DmMUlgbIvhowpcUSqVmdq9NvqLm_U5RE1nuA,22
2
- c2r\cli.py,sha256=Dc9JKOA9fR1GhzoSnViYHav8jRNC_nWqpjK0Cmux8Bo,3390
3
- c2r-1.0.0.dist-info\METADATA,sha256=rmNPR6mlaCHuuYyl9veN-Z4bGI_b2kkt0xlHAxKvLC8,3476
4
- c2r-1.0.0.dist-info\WHEEL,sha256=X79LywvMB9iCuFHu88xBAFTJDhRqJi6Yh9hhoCI9jao,97
5
- c2r-1.0.0.dist-info\entry_points.txt,sha256=bUGIN_7y_IZymC9EXuRhEzwdCkdDz9VEYpatKro6kTU,35
6
- c2r_core\__init__.py,sha256=2sQzOqoWTXAyeQMssALXGlR2daKyZoxUBFRzUTfZ8lU,115
7
- c2r_core\c2r_core.cp311-win_amd64.pyd,sha256=rSRg9eP_xi4Zra6rdfD4UVT9nS2hWGflXUpo05PjVpw,2232832
8
- c2r-1.0.0.dist-info\RECORD,,
File without changes