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:
parent
d63ef02ef3
commit
a28d999958
18 changed files with 554 additions and 390 deletions
|
|
@ -17,15 +17,17 @@ class Message:
|
|||
async def resolve_dependency_conflicts(
|
||||
conflicts: Annotated[
|
||||
list[str],
|
||||
Field(description="List of conflicting dependencies or error messages", min_length=1)
|
||||
Field(
|
||||
description="List of conflicting dependencies or error messages",
|
||||
min_length=1,
|
||||
),
|
||||
],
|
||||
python_version: Annotated[
|
||||
str | None,
|
||||
Field(description="Target Python version (e.g., '3.10', '3.11')")
|
||||
str | None, Field(description="Target Python version (e.g., '3.10', '3.11')")
|
||||
] = None,
|
||||
project_context: Annotated[
|
||||
str | None,
|
||||
Field(description="Brief description of the project and its requirements")
|
||||
Field(description="Brief description of the project and its requirements"),
|
||||
] = None,
|
||||
ctx: Context | None = None,
|
||||
) -> list[Message]:
|
||||
|
|
@ -90,11 +92,11 @@ async def plan_version_upgrade(
|
|||
current_version: Annotated[str, Field(description="Current version being used")],
|
||||
target_version: Annotated[
|
||||
str | None,
|
||||
Field(description="Target version (if known), or 'latest' for newest")
|
||||
Field(description="Target version (if known), or 'latest' for newest"),
|
||||
] = None,
|
||||
project_size: Annotated[
|
||||
str | None,
|
||||
Field(description="Project size context (small/medium/large/enterprise)")
|
||||
Field(description="Project size context (small/medium/large/enterprise)"),
|
||||
] = None,
|
||||
ctx: Context | None = None,
|
||||
) -> list[Message]:
|
||||
|
|
@ -168,15 +170,17 @@ Please provide specific commands, code examples, and timelines where applicable.
|
|||
async def audit_security_risks(
|
||||
packages: Annotated[
|
||||
list[str],
|
||||
Field(description="List of packages to audit for security risks", min_length=1)
|
||||
Field(description="List of packages to audit for security risks", min_length=1),
|
||||
],
|
||||
environment: Annotated[
|
||||
str | None,
|
||||
Field(description="Environment context (development/staging/production)")
|
||||
Field(description="Environment context (development/staging/production)"),
|
||||
] = None,
|
||||
compliance_requirements: Annotated[
|
||||
str | None,
|
||||
Field(description="Specific compliance requirements (e.g., SOC2, HIPAA, PCI-DSS)")
|
||||
Field(
|
||||
description="Specific compliance requirements (e.g., SOC2, HIPAA, PCI-DSS)"
|
||||
),
|
||||
] = None,
|
||||
ctx: Context | None = None,
|
||||
) -> list[Message]:
|
||||
|
|
@ -187,7 +191,11 @@ async def audit_security_risks(
|
|||
"""
|
||||
packages_text = ", ".join(f"'{pkg}'" for pkg in packages)
|
||||
env_text = f"\nEnvironment: {environment}" if environment else ""
|
||||
compliance_text = f"\nCompliance requirements: {compliance_requirements}" if compliance_requirements else ""
|
||||
compliance_text = (
|
||||
f"\nCompliance requirements: {compliance_requirements}"
|
||||
if compliance_requirements
|
||||
else ""
|
||||
)
|
||||
|
||||
return [
|
||||
Message(
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from pydantic import Field
|
|||
|
||||
class Message:
|
||||
"""Simple message class for prompt templates."""
|
||||
|
||||
|
||||
def __init__(self, text: str, role: str = "user"):
|
||||
self.text = text
|
||||
self.role = role
|
||||
|
|
@ -16,16 +16,13 @@ class Message:
|
|||
|
||||
async def analyze_environment_dependencies(
|
||||
environment_type: Annotated[
|
||||
str,
|
||||
Field(description="Type of environment (local, virtual, docker, conda)")
|
||||
str, Field(description="Type of environment (local, virtual, docker, conda)")
|
||||
] = "local",
|
||||
python_version: Annotated[
|
||||
str | None,
|
||||
Field(description="Python version in the environment")
|
||||
str | None, Field(description="Python version in the environment")
|
||||
] = None,
|
||||
project_path: Annotated[
|
||||
str | None,
|
||||
Field(description="Path to the project directory")
|
||||
str | None, Field(description="Path to the project directory")
|
||||
] = None,
|
||||
ctx: Context | None = None,
|
||||
) -> str:
|
||||
|
|
@ -33,7 +30,7 @@ async def analyze_environment_dependencies(
|
|||
|
||||
This prompt template helps analyze the current Python environment dependencies,
|
||||
check for outdated packages, and provide upgrade recommendations.
|
||||
|
||||
|
||||
Returns a template string with {{environment_type}}, {{python_version}}, and {{project_path}} variables.
|
||||
"""
|
||||
template = """Please analyze the Python environment dependencies {{environment_info}}.
|
||||
|
|
@ -98,16 +95,13 @@ Please include specific commands for package management and update procedures.""
|
|||
|
||||
async def check_outdated_packages(
|
||||
package_filter: Annotated[
|
||||
str | None,
|
||||
Field(description="Filter packages by name pattern (optional)")
|
||||
str | None, Field(description="Filter packages by name pattern (optional)")
|
||||
] = None,
|
||||
severity_level: Annotated[
|
||||
str,
|
||||
Field(description="Focus level: all, security, major, minor")
|
||||
str, Field(description="Focus level: all, security, major, minor")
|
||||
] = "all",
|
||||
include_dev_dependencies: Annotated[
|
||||
bool,
|
||||
Field(description="Include development dependencies in analysis")
|
||||
bool, Field(description="Include development dependencies in analysis")
|
||||
] = True,
|
||||
ctx: Context | None = None,
|
||||
) -> str:
|
||||
|
|
@ -115,7 +109,7 @@ async def check_outdated_packages(
|
|||
|
||||
This prompt template helps identify and prioritize outdated packages
|
||||
in the current environment with specific focus criteria.
|
||||
|
||||
|
||||
Returns a template string with {{package_filter}}, {{severity_level}}, and {{dev_deps}} variables.
|
||||
"""
|
||||
template = """Please check for outdated packages in my Python environment {{filter_info}}.
|
||||
|
|
@ -187,16 +181,13 @@ Include specific pip/uv commands for each update category."""
|
|||
|
||||
async def generate_update_plan(
|
||||
update_strategy: Annotated[
|
||||
str,
|
||||
Field(description="Update strategy: conservative, balanced, aggressive")
|
||||
str, Field(description="Update strategy: conservative, balanced, aggressive")
|
||||
] = "balanced",
|
||||
environment_constraints: Annotated[
|
||||
str | None,
|
||||
Field(description="Environment constraints or requirements")
|
||||
str | None, Field(description="Environment constraints or requirements")
|
||||
] = None,
|
||||
testing_requirements: Annotated[
|
||||
str | None,
|
||||
Field(description="Testing requirements before updates")
|
||||
str | None, Field(description="Testing requirements before updates")
|
||||
] = None,
|
||||
ctx: Context | None = None,
|
||||
) -> str:
|
||||
|
|
@ -204,7 +195,7 @@ async def generate_update_plan(
|
|||
|
||||
This prompt template helps create comprehensive update plans for Python environments
|
||||
with specific strategies and constraints.
|
||||
|
||||
|
||||
Returns a template string with {{strategy}}, {{constraints}}, and {{testing}} variables.
|
||||
"""
|
||||
template = """Please create a comprehensive package update plan using a {{strategy}} strategy{{constraints_text}}{{testing_text}}.
|
||||
|
|
|
|||
|
|
@ -19,15 +19,17 @@ async def plan_package_migration(
|
|||
to_package: Annotated[str, Field(description="Package to migrate to")],
|
||||
codebase_size: Annotated[
|
||||
Literal["small", "medium", "large", "enterprise"],
|
||||
Field(description="Size of the codebase being migrated")
|
||||
Field(description="Size of the codebase being migrated"),
|
||||
] = "medium",
|
||||
timeline: Annotated[
|
||||
str | None,
|
||||
Field(description="Desired timeline for migration (e.g., '2 weeks', '1 month')")
|
||||
Field(
|
||||
description="Desired timeline for migration (e.g., '2 weeks', '1 month')"
|
||||
),
|
||||
] = None,
|
||||
team_size: Annotated[
|
||||
int | None,
|
||||
Field(description="Number of developers involved in migration", ge=1, le=50)
|
||||
Field(description="Number of developers involved in migration", ge=1, le=50),
|
||||
] = None,
|
||||
ctx: Context | None = None,
|
||||
) -> list[Message]:
|
||||
|
|
@ -126,16 +128,21 @@ Please provide specific code examples, commands, and detailed timelines."""
|
|||
|
||||
async def generate_migration_checklist(
|
||||
migration_type: Annotated[
|
||||
Literal["package_replacement", "version_upgrade", "framework_migration", "dependency_cleanup"],
|
||||
Field(description="Type of migration being performed")
|
||||
Literal[
|
||||
"package_replacement",
|
||||
"version_upgrade",
|
||||
"framework_migration",
|
||||
"dependency_cleanup",
|
||||
],
|
||||
Field(description="Type of migration being performed"),
|
||||
],
|
||||
packages_involved: Annotated[
|
||||
list[str],
|
||||
Field(description="List of packages involved in the migration", min_length=1)
|
||||
Field(description="List of packages involved in the migration", min_length=1),
|
||||
],
|
||||
environment: Annotated[
|
||||
Literal["development", "staging", "production", "all"],
|
||||
Field(description="Target environment for migration")
|
||||
Field(description="Target environment for migration"),
|
||||
] = "all",
|
||||
ctx: Context | None = None,
|
||||
) -> list[Message]:
|
||||
|
|
@ -150,7 +157,7 @@ async def generate_migration_checklist(
|
|||
"package_replacement": "replacing one package with another",
|
||||
"version_upgrade": "upgrading package versions",
|
||||
"framework_migration": "migrating between frameworks",
|
||||
"dependency_cleanup": "cleaning up and optimizing dependencies"
|
||||
"dependency_cleanup": "cleaning up and optimizing dependencies",
|
||||
}
|
||||
|
||||
context_text = migration_contexts.get(migration_type, migration_type)
|
||||
|
|
|
|||
|
|
@ -15,20 +15,24 @@ class Message:
|
|||
|
||||
|
||||
async def analyze_package_quality(
|
||||
package_name: Annotated[str, Field(description="Name of the PyPI package to analyze")],
|
||||
version: Annotated[str | None, Field(description="Specific version to analyze")] = None,
|
||||
package_name: Annotated[
|
||||
str, Field(description="Name of the PyPI package to analyze")
|
||||
],
|
||||
version: Annotated[
|
||||
str | None, Field(description="Specific version to analyze")
|
||||
] = None,
|
||||
ctx: Context | None = None,
|
||||
) -> str:
|
||||
) -> list[Message]:
|
||||
"""Generate a comprehensive package quality analysis prompt template.
|
||||
|
||||
This prompt template helps analyze a Python package's quality, maintenance status,
|
||||
security, performance, and overall suitability for use in projects.
|
||||
|
||||
Returns a template string with {{package_name}} and {{version_text}} variables.
|
||||
Returns a list containing a Message object with the analysis prompt.
|
||||
"""
|
||||
template = """Please provide a comprehensive quality analysis of the Python package '{{package_name}}' {{version_text}}.
|
||||
|
||||
Analyze the following aspects:
|
||||
Analyze the following aspects and provide a detailed assessment:
|
||||
|
||||
## 📊 Package Overview
|
||||
- Package purpose and functionality
|
||||
|
|
@ -58,21 +62,24 @@ Analyze the following aspects:
|
|||
|
||||
Please provide specific examples and actionable insights where possible."""
|
||||
|
||||
return template
|
||||
return [Message(template)]
|
||||
|
||||
|
||||
async def compare_packages(
|
||||
packages: Annotated[
|
||||
list[str],
|
||||
Field(description="List of package names to compare", min_length=2, max_length=5)
|
||||
Field(
|
||||
description="List of package names to compare", min_length=2, max_length=5
|
||||
),
|
||||
],
|
||||
use_case: Annotated[
|
||||
str,
|
||||
Field(description="Specific use case or project context for comparison")
|
||||
str, Field(description="Specific use case or project context for comparison")
|
||||
],
|
||||
criteria: Annotated[
|
||||
list[str] | None,
|
||||
Field(description="Specific criteria to focus on (e.g., performance, security, ease of use)")
|
||||
Field(
|
||||
description="Specific criteria to focus on (e.g., performance, security, ease of use)"
|
||||
),
|
||||
] = None,
|
||||
ctx: Context | None = None,
|
||||
) -> str:
|
||||
|
|
@ -125,14 +132,23 @@ Please include specific examples and quantitative data where available."""
|
|||
|
||||
|
||||
async def suggest_alternatives(
|
||||
package_name: Annotated[str, Field(description="Name of the package to find alternatives for")],
|
||||
package_name: Annotated[
|
||||
str, Field(description="Name of the package to find alternatives for")
|
||||
],
|
||||
reason: Annotated[
|
||||
Literal["deprecated", "security", "performance", "licensing", "maintenance", "features"],
|
||||
Field(description="Reason for seeking alternatives")
|
||||
Literal[
|
||||
"deprecated",
|
||||
"security",
|
||||
"performance",
|
||||
"licensing",
|
||||
"maintenance",
|
||||
"features",
|
||||
],
|
||||
Field(description="Reason for seeking alternatives"),
|
||||
],
|
||||
requirements: Annotated[
|
||||
str | None,
|
||||
Field(description="Specific requirements or constraints for alternatives")
|
||||
Field(description="Specific requirements or constraints for alternatives"),
|
||||
] = None,
|
||||
ctx: Context | None = None,
|
||||
) -> str:
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from pydantic import Field
|
|||
|
||||
class Message:
|
||||
"""Simple message class for prompt templates."""
|
||||
|
||||
|
||||
def __init__(self, text: str, role: str = "user"):
|
||||
self.text = text
|
||||
self.role = role
|
||||
|
|
@ -17,15 +17,14 @@ class Message:
|
|||
async def analyze_daily_trends(
|
||||
date: Annotated[
|
||||
str | None,
|
||||
Field(description="Specific date to analyze (YYYY-MM-DD) or 'today'")
|
||||
Field(description="Specific date to analyze (YYYY-MM-DD) or 'today'"),
|
||||
] = "today",
|
||||
category: Annotated[
|
||||
str | None,
|
||||
Field(description="Package category to focus on (web, data, ml, etc.)")
|
||||
Field(description="Package category to focus on (web, data, ml, etc.)"),
|
||||
] = None,
|
||||
limit: Annotated[
|
||||
int,
|
||||
Field(description="Number of top packages to analyze", ge=5, le=50)
|
||||
int, Field(description="Number of top packages to analyze", ge=5, le=50)
|
||||
] = 20,
|
||||
ctx: Context | None = None,
|
||||
) -> str:
|
||||
|
|
@ -33,7 +32,7 @@ async def analyze_daily_trends(
|
|||
|
||||
This prompt template helps analyze the most downloaded packages on PyPI
|
||||
for a specific day and understand trending patterns.
|
||||
|
||||
|
||||
Returns a template string with {{date}}, {{category_filter}}, and {{limit}} variables.
|
||||
"""
|
||||
template = """Please analyze the daily PyPI download trends for {{date}}{{category_filter}}.
|
||||
|
|
@ -119,15 +118,15 @@ Include specific download numbers, growth percentages, and trend analysis."""
|
|||
async def find_trending_packages(
|
||||
time_period: Annotated[
|
||||
Literal["daily", "weekly", "monthly"],
|
||||
Field(description="Time period for trend analysis")
|
||||
Field(description="Time period for trend analysis"),
|
||||
] = "weekly",
|
||||
trend_type: Annotated[
|
||||
Literal["rising", "declining", "new", "all"],
|
||||
Field(description="Type of trends to focus on")
|
||||
Field(description="Type of trends to focus on"),
|
||||
] = "rising",
|
||||
domain: Annotated[
|
||||
str | None,
|
||||
Field(description="Specific domain or category (web, ai, data, etc.)")
|
||||
Field(description="Specific domain or category (web, ai, data, etc.)"),
|
||||
] = None,
|
||||
ctx: Context | None = None,
|
||||
) -> str:
|
||||
|
|
@ -135,7 +134,7 @@ async def find_trending_packages(
|
|||
|
||||
This prompt template helps identify packages that are trending up or down
|
||||
in the PyPI ecosystem over specific time periods.
|
||||
|
||||
|
||||
Returns a template string with {{time_period}}, {{trend_type}}, and {{domain_filter}} variables.
|
||||
"""
|
||||
template = """Please identify {{trend_type}} trending Python packages over the {{time_period}} period{{domain_filter}}.
|
||||
|
|
@ -242,15 +241,14 @@ Include specific trend data, growth metrics, and actionable recommendations."""
|
|||
async def track_package_updates(
|
||||
time_range: Annotated[
|
||||
Literal["today", "week", "month"],
|
||||
Field(description="Time range for update tracking")
|
||||
Field(description="Time range for update tracking"),
|
||||
] = "today",
|
||||
update_type: Annotated[
|
||||
Literal["all", "major", "security", "new"],
|
||||
Field(description="Type of updates to track")
|
||||
Field(description="Type of updates to track"),
|
||||
] = "all",
|
||||
popular_only: Annotated[
|
||||
bool,
|
||||
Field(description="Focus only on popular packages (>1M downloads)")
|
||||
bool, Field(description="Focus only on popular packages (>1M downloads)")
|
||||
] = False,
|
||||
ctx: Context | None = None,
|
||||
) -> str:
|
||||
|
|
@ -258,7 +256,7 @@ async def track_package_updates(
|
|||
|
||||
This prompt template helps track and analyze recent package updates
|
||||
on PyPI with filtering and categorization options.
|
||||
|
||||
|
||||
Returns a template string with {{time_range}}, {{update_type}}, and {{popularity_filter}} variables.
|
||||
"""
|
||||
template = """Please track and analyze Python package updates from {{time_range}}{{popularity_filter}}.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue