fix: resolve all lint issues and fix failing tests

- Fix blank line whitespace issues (W293) using ruff --unsafe-fixes
- Reformat code using ruff format for consistent styling
- Fix analyze_package_quality function to return list[Message] instead of string
- Add missing 'assessment' keyword to package analysis template
- Update tests to use real prompt functions instead of mocks for structure validation
- Fix import ordering in test files
- All 64 tests now pass with 47% code coverage

Signed-off-by: longhao <hal.long@outlook.com>
This commit is contained in:
longhao 2025-05-29 18:38:10 +08:00 committed by Hal
parent d63ef02ef3
commit a28d999958
18 changed files with 554 additions and 390 deletions

View file

@ -41,9 +41,7 @@ class DependencyParser:
return requirements
def filter_requirements_by_python_version(
self,
requirements: list[Requirement],
python_version: str
self, requirements: list[Requirement], python_version: str
) -> list[Requirement]:
"""Filter requirements based on Python version.
@ -68,7 +66,9 @@ class DependencyParser:
return filtered
def _is_requirement_applicable(self, req: Requirement, python_version: Version) -> bool:
def _is_requirement_applicable(
self, req: Requirement, python_version: Version
) -> bool:
"""Check if a requirement is applicable for the given Python version.
Args:
@ -83,12 +83,12 @@ class DependencyParser:
# Create environment for marker evaluation
env = {
'python_version': str(python_version),
'python_full_version': str(python_version),
'platform_system': 'Linux', # Default assumption
'platform_machine': 'x86_64', # Default assumption
'implementation_name': 'cpython',
'implementation_version': str(python_version),
"python_version": str(python_version),
"python_full_version": str(python_version),
"platform_system": "Linux", # Default assumption
"platform_machine": "x86_64", # Default assumption
"implementation_name": "cpython",
"implementation_version": str(python_version),
}
try:
@ -98,8 +98,7 @@ class DependencyParser:
return True # Include by default if evaluation fails
def categorize_dependencies(
self,
requirements: list[Requirement]
self, requirements: list[Requirement]
) -> dict[str, list[Requirement]]:
"""Categorize dependencies into runtime, development, and optional groups.
@ -109,36 +108,34 @@ class DependencyParser:
Returns:
Dictionary with categorized dependencies
"""
categories = {
'runtime': [],
'development': [],
'optional': {},
'extras': {}
}
categories = {"runtime": [], "development": [], "optional": {}, "extras": {}}
for req in requirements:
if not req.marker:
# No marker means it's a runtime dependency
categories['runtime'].append(req)
categories["runtime"].append(req)
continue
marker_str = str(req.marker)
# Check for extra dependencies
if 'extra ==' in marker_str:
if "extra ==" in marker_str:
extra_match = re.search(r'extra\s*==\s*["\']([^"\']+)["\']', marker_str)
if extra_match:
extra_name = extra_match.group(1)
if extra_name not in categories['extras']:
categories['extras'][extra_name] = []
categories['extras'][extra_name].append(req)
if extra_name not in categories["extras"]:
categories["extras"][extra_name] = []
categories["extras"][extra_name].append(req)
continue
# Check for development dependencies
if any(keyword in marker_str.lower() for keyword in ['dev', 'test', 'lint', 'doc']):
categories['development'].append(req)
if any(
keyword in marker_str.lower()
for keyword in ["dev", "test", "lint", "doc"]
):
categories["development"].append(req)
else:
categories['runtime'].append(req)
categories["runtime"].append(req)
return categories
@ -163,17 +160,16 @@ class DependencyParser:
Dictionary with version constraint information
"""
if not req.specifier:
return {'constraints': [], 'allows_any': True}
return {"constraints": [], "allows_any": True}
constraints = []
for spec in req.specifier:
constraints.append({
'operator': spec.operator,
'version': str(spec.version)
})
constraints.append(
{"operator": spec.operator, "version": str(spec.version)}
)
return {
'constraints': constraints,
'allows_any': len(constraints) == 0,
'specifier_str': str(req.specifier)
"constraints": constraints,
"allows_any": len(constraints) == 0,
"specifier_str": str(req.specifier),
}