hos-m2f 0.5.0__py3-none-any.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.
hos_m2f/__init__.py ADDED
@@ -0,0 +1,8 @@
1
+ """HOS-M2F: Markdown to Industry Standard Format Compiler Engine"""
2
+
3
+ __version__ = "1.0.0"
4
+ __author__ = "HOS Team"
5
+
6
+ from hos_m2f.engine.engine import Engine
7
+
8
+ __all__ = ["Engine"]
@@ -0,0 +1,5 @@
1
+ """CLI模块"""
2
+
3
+ from hos_m2f.cli.cli import CLI
4
+
5
+ __all__ = ['CLI']
hos_m2f/cli/cli.py ADDED
@@ -0,0 +1,278 @@
1
+ """CLI命令体系模块"""
2
+
3
+ import argparse
4
+ import json
5
+ import sys
6
+ from typing import Dict, Any, Optional
7
+ from hos_m2f.engine.engine import Engine
8
+ from hos_m2f.ide.preview_server import PreviewServer
9
+
10
+
11
+ class CLI:
12
+ """命令行接口"""
13
+
14
+ def __init__(self):
15
+ self.engine = Engine()
16
+ self.parser = argparse.ArgumentParser(
17
+ prog='hos-m2f',
18
+ description='HOS-M2F v1.0 - Content Compiler Engine for AI Writing and Professional Document Production',
19
+ epilog='For more information, visit the project documentation.'
20
+ )
21
+ self.subparsers = self.parser.add_subparsers(dest='command', help='Available commands')
22
+ self._setup_commands()
23
+
24
+ def _setup_commands(self):
25
+ """设置命令"""
26
+ # build命令
27
+ build_parser = self.subparsers.add_parser('build', help='Build document from Markdown')
28
+ build_parser.add_argument('input', help='Input Markdown file')
29
+ build_parser.add_argument('output', help='Output file path')
30
+ build_parser.add_argument('--mode', choices=['book', 'patent', 'sop', 'paper'], default='paper', help='Document mode')
31
+ build_parser.add_argument('--format', choices=['epub', 'pdf', 'docx', 'json'], default='epub', help='Output format')
32
+ build_parser.add_argument('--options', type=str, default='{}', help='Additional options as JSON string')
33
+
34
+ # check命令
35
+ check_parser = self.subparsers.add_parser('check', help='Check document structure and compliance')
36
+ check_parser.add_argument('input', help='Input Markdown file')
37
+ check_parser.add_argument('--mode', choices=['book', 'patent', 'sop', 'paper'], default='paper', help='Document mode')
38
+ check_parser.add_argument('--options', type=str, default='{}', help='Additional options as JSON string')
39
+
40
+ # parse命令
41
+ parse_parser = self.subparsers.add_parser('parse', help='Parse Markdown content and output structured data')
42
+ parse_parser.add_argument('input', help='Input Markdown file')
43
+ parse_parser.add_argument('--mode', choices=['book', 'patent', 'sop', 'paper'], default='paper', help='Document mode')
44
+ parse_parser.add_argument('--output', help='Output JSON file (default: stdout)')
45
+ parse_parser.add_argument('--options', type=str, default='{}', help='Additional options as JSON string')
46
+
47
+ # preview命令
48
+ preview_parser = self.subparsers.add_parser('preview', help='Start preview server')
49
+ preview_parser.add_argument('--port', type=int, default=8000, help='Port to run the server on')
50
+
51
+ # info命令
52
+ info_parser = self.subparsers.add_parser('info', help='Show information about supported modes and formats')
53
+ info_parser.add_argument('--detail', action='store_true', help='Show detailed information')
54
+
55
+ # validate命令
56
+ validate_parser = self.subparsers.add_parser('validate', help='Validate options for a specific mode')
57
+ validate_parser.add_argument('--mode', choices=['book', 'patent', 'sop', 'paper'], required=True, help='Document mode')
58
+ validate_parser.add_argument('--options', type=str, required=True, help='Options to validate as JSON string')
59
+
60
+ def run(self, args=None):
61
+ """运行命令
62
+
63
+ Args:
64
+ args: 命令行参数
65
+
66
+ Returns:
67
+ int: 退出码
68
+ """
69
+ if args is None:
70
+ args = sys.argv[1:]
71
+
72
+ parsed_args = self.parser.parse_args(args)
73
+
74
+ if not parsed_args.command:
75
+ self.parser.print_help()
76
+ return 1
77
+
78
+ try:
79
+ if parsed_args.command == 'build':
80
+ return self._run_build(parsed_args)
81
+ elif parsed_args.command == 'check':
82
+ return self._run_check(parsed_args)
83
+ elif parsed_args.command == 'parse':
84
+ return self._run_parse(parsed_args)
85
+ elif parsed_args.command == 'preview':
86
+ return self._run_preview(parsed_args)
87
+ elif parsed_args.command == 'info':
88
+ return self._run_info(parsed_args)
89
+ elif parsed_args.command == 'validate':
90
+ return self._run_validate(parsed_args)
91
+ else:
92
+ self.parser.print_help()
93
+ return 1
94
+ except Exception as e:
95
+ print(f'Error: {e}', file=sys.stderr)
96
+ return 1
97
+
98
+ def _run_build(self, args):
99
+ """运行build命令"""
100
+ # 读取输入文件
101
+ with open(args.input, 'r', encoding='utf-8') as f:
102
+ content = f.read()
103
+
104
+ # 解析选项
105
+ options = json.loads(args.options)
106
+
107
+ # 构建文档
108
+ result = self.engine.build(content, args.mode, args.format, options)
109
+
110
+ # 写入输出文件
111
+ with open(args.output, 'wb') as f:
112
+ f.write(result.binary)
113
+
114
+ print(f'Successfully built {args.output}')
115
+ print(f'Output format: {result.output_format}')
116
+ if result.metadata:
117
+ print('Metadata:', json.dumps(result.metadata, ensure_ascii=False, indent=2))
118
+
119
+ return 0
120
+
121
+ def _run_check(self, args):
122
+ """运行check命令"""
123
+ # 读取输入文件
124
+ with open(args.input, 'r', encoding='utf-8') as f:
125
+ content = f.read()
126
+
127
+ # 解析选项
128
+ options = json.loads(args.options)
129
+
130
+ # 检查文档
131
+ result = self.engine.check(content, args.mode, options)
132
+
133
+ # 输出结果
134
+ print('Check result:')
135
+ print(json.dumps(result, ensure_ascii=False, indent=2))
136
+
137
+ # 检查是否有问题
138
+ if 'compliance' in result and not result['compliance'].get('compliant', True):
139
+ print('\nIssues found:', file=sys.stderr)
140
+ for issue in result['compliance'].get('issues', []):
141
+ print(f' - {issue}', file=sys.stderr)
142
+ return 1
143
+
144
+ print('\nNo issues found!')
145
+ return 0
146
+
147
+ def _run_parse(self, args):
148
+ """运行parse命令"""
149
+ # 读取输入文件
150
+ with open(args.input, 'r', encoding='utf-8') as f:
151
+ content = f.read()
152
+
153
+ # 解析选项
154
+ options = json.loads(args.options)
155
+
156
+ # 根据模式选择解析器
157
+ if args.mode == 'book':
158
+ from hos_m2f.structure.book_parser import BookParser
159
+ parser = BookParser()
160
+ elif args.mode == 'patent':
161
+ from hos_m2f.structure.patent_parser import PatentParser
162
+ parser = PatentParser()
163
+ elif args.mode == 'sop':
164
+ from hos_m2f.structure.sop_parser import SOPParser
165
+ parser = SOPParser()
166
+ else:
167
+ from hos_m2f.structure.semantic_parser import SemanticParser
168
+ parser = SemanticParser()
169
+
170
+ # 解析内容
171
+ result = parser.parse(content, options)
172
+
173
+ # 输出结果
174
+ output_data = json.dumps(result, ensure_ascii=False, indent=2)
175
+
176
+ if args.output:
177
+ with open(args.output, 'w', encoding='utf-8') as f:
178
+ f.write(output_data)
179
+ print(f'Successfully parsed to {args.output}')
180
+ else:
181
+ print(output_data)
182
+
183
+ return 0
184
+
185
+ def _run_preview(self, args):
186
+ """运行preview命令"""
187
+ server = PreviewServer(port=args.port)
188
+ result = server.start()
189
+
190
+ if result['success']:
191
+ print(f'Preview server started on port {args.port}')
192
+ print(f'Access at: http://localhost:{args.port}')
193
+ print('Press Ctrl+C to stop the server')
194
+
195
+ # 保持运行
196
+ try:
197
+ import time
198
+ while True:
199
+ time.sleep(1)
200
+ except KeyboardInterrupt:
201
+ print('\nStopping server...')
202
+ server.stop()
203
+ print('Server stopped')
204
+ else:
205
+ print(f'Failed to start server: {result["error"]}', file=sys.stderr)
206
+ return 1
207
+
208
+ return 0
209
+
210
+ def _run_info(self, args):
211
+ """运行info命令"""
212
+ print('HOS-M2F v1.0 - Content Compiler Engine')
213
+ print('=====================================')
214
+
215
+ # 显示支持的模式
216
+ print('\nSupported modes:')
217
+ modes = self.engine.get_supported_modes()
218
+ for mode, description in modes.items():
219
+ print(f' - {mode}: {description}')
220
+
221
+ # 显示支持的格式
222
+ print('\nSupported output formats:')
223
+ formats = self.engine.get_supported_formats()
224
+ for fmt, description in formats.items():
225
+ print(f' - {fmt}: {description}')
226
+
227
+ if args.detail:
228
+ print('\nDetailed information:')
229
+ print('\nBook mode:')
230
+ print(' Description: Supports chapter structure recognition, TOC generation, metadata packaging, cover recognition')
231
+ print(' Output formats: epub, pdf, docx, json')
232
+
233
+ print('\nPatent mode:')
234
+ print(' Description: Supports automatic claim numbering, patent paragraph indentation, figure numbering')
235
+ print(' Output formats: pdf, docx, json')
236
+
237
+ print('\nSOP mode:')
238
+ print(' Description: Supports step numbering, checklist tabularization, risk level identification')
239
+ print(' Output formats: pdf, docx, json')
240
+
241
+ print('\nPaper mode:')
242
+ print(' Description: Supports technical documents and paper formatting')
243
+ print(' Output formats: pdf, docx, json')
244
+
245
+ return 0
246
+
247
+ def _run_validate(self, args):
248
+ """运行validate命令"""
249
+ # 解析选项
250
+ options = json.loads(args.options)
251
+
252
+ # 验证选项
253
+ from hos_m2f.ide.api import IDEAPI
254
+ api = IDEAPI()
255
+ result = api.validate_options(args.mode, options)
256
+
257
+ # 输出结果
258
+ print('Validation result:')
259
+ print(json.dumps(result, ensure_ascii=False, indent=2))
260
+
261
+ if not result['valid']:
262
+ print('\nValidation failed:', file=sys.stderr)
263
+ for error in result['errors']:
264
+ print(f' - {error}', file=sys.stderr)
265
+ return 1
266
+
267
+ print('\nValidation passed!')
268
+ return 0
269
+
270
+
271
+ def main():
272
+ """CLI命令入口点"""
273
+ cli = CLI()
274
+ sys.exit(cli.run())
275
+
276
+ # 命令行入口
277
+ if __name__ == '__main__':
278
+ main()
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: hos-m2f
3
+ Version: 0.5.0
4
+ Summary: HOS-M2F: Markdown to Industry Standard Format Compiler Engine
5
+ Author: HOS Team
6
+ Author-email: team@hos-m2f.com
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.8
11
+ Requires-Dist: mistune>=2.0.0
12
+ Requires-Dist: pyyaml>=6.0
13
+ Requires-Dist: click>=8.0.0
14
+ Requires-Dist: ebooklib>=0.17.0
15
+ Requires-Dist: weasyprint>=54.0
16
+ Requires-Dist: python-docx>=0.8.11
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: requires-dist
21
+ Dynamic: requires-python
22
+ Dynamic: summary
@@ -0,0 +1,8 @@
1
+ hos_m2f/__init__.py,sha256=v4k4TbKzPb3nbzgKJHaID3QTSpmTvAsGVHZ-poa870I,178
2
+ hos_m2f/cli/__init__.py,sha256=NqhmK68K2evHjP7qcyT7FUWlDqfb22CUpCOfJhnQzPs,68
3
+ hos_m2f/cli/cli.py,sha256=61agI2zcmgH5vtBNayueMGD7sVrqhMe5eFpvgd9j7r0,10639
4
+ hos_m2f-0.5.0.dist-info/METADATA,sha256=jgKHvyzDNwRenK8VP7CnFgQ-sg06JfXr-jnZJERg1uk,668
5
+ hos_m2f-0.5.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
6
+ hos_m2f-0.5.0.dist-info/entry_points.txt,sha256=NeLjg1hvVt_A2sDUVZAYbfkvnZ1nGMcTqRiDoVQzn0w,49
7
+ hos_m2f-0.5.0.dist-info/top_level.txt,sha256=DMIK2jdfJss-FB_GRZ6iw4gahhZUAvSI0fHamOPL9mE,8
8
+ hos_m2f-0.5.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.2)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ hos-m2f = hos_m2f.cli.cli:main
@@ -0,0 +1 @@
1
+ hos_m2f