import json import subprocess import sys from datetime import datetime def generate_quality_report(): report = { 'project': 'OAuth Module', 'analysis_date': datetime.now().isoformat(), 'tools_used': ['flake8', 'pylint'], 'summary': {} } # Flake8 分析 result = subprocess.run([ sys.executable, '-m', 'flake8', 'oauth/', '--max-line-length=120', '--statistics', '--exit-zero' ], capture_output=True, text=True) report['flake8_issues'] = result.stdout.strip().split('\n') # Pylint 分析 result = subprocess.run([ sys.executable, '-m', 'pylint', 'oauth/', '--output-format=json', '--exit-zero' ], capture_output=True, text=True) try: report['pylint_issues'] = json.loads(result.stdout) except: report['pylint_issues'] = result.stdout # 保存报告 with open('oauth_quality_report.json', 'w', encoding='utf-8') as f: json.dump(report, f, indent=2, ensure_ascii=False) print('代码质量报告已生成: oauth_quality_report.json') generate_quality_report()