style: fix code formatting and linting issues

- Remove unused imports in stats_client.py and download_stats.py
- Fix import sorting in test files
- Remove unnecessary f-strings in server.py and demo script
- Clean up whitespace and formatting issues
- Ensure all files pass ruff and isort checks

Signed-off-by: longhao <hal.long@outlook.com>
This commit is contained in:
longhao 2025-05-27 21:13:09 +08:00 committed by Hal
parent 99c603ed37
commit 3d9d7b4208
5 changed files with 66 additions and 68 deletions

View File

@ -7,7 +7,6 @@ to analyze PyPI package popularity and trends.
"""
import asyncio
import json
from datetime import datetime
from pypi_query_mcp.tools.download_stats import (
@ -44,27 +43,27 @@ async def demo_package_download_stats():
print(f"Summary: {metadata.get('summary', 'No summary available')[:80]}...")
# Display download counts
print(f"\nDownload Counts:")
print("\nDownload Counts:")
print(f" Last Day: {downloads.get('last_day', 0):,}")
print(f" Last Week: {downloads.get('last_week', 0):,}")
print(f" Last Month: {downloads.get('last_month', 0):,}")
# Display analysis
if analysis:
print(f"\nAnalysis:")
print("\nAnalysis:")
print(f" Total Downloads: {analysis.get('total_downloads', 0):,}")
print(f" Highest Period: {analysis.get('highest_period', 'N/A')}")
growth = analysis.get('growth_indicators', {})
if growth:
print(f" Growth Indicators:")
print(" Growth Indicators:")
for indicator, value in growth.items():
print(f" {indicator}: {value}")
# Display repository info if available
project_urls = metadata.get('project_urls', {})
if project_urls:
print(f"\nRepository Links:")
print("\nRepository Links:")
for name, url in project_urls.items():
if url:
print(f" {name}: {url}")
@ -110,7 +109,7 @@ async def demo_package_download_trends():
# Show recent data points (last 7 days)
if time_series:
print(f"\nRecent Download Data (last 7 days):")
print("\nRecent Download Data (last 7 days):")
recent_data = [item for item in time_series if item.get('category') == 'without_mirrors'][-7:]
for item in recent_data:
date = item.get('date', 'unknown')
@ -146,7 +145,7 @@ async def demo_top_packages():
if top_packages.get("note"):
print(f"Note: {top_packages['note']}")
print(f"\nRankings:")
print("\nRankings:")
for package in packages_list:
rank = package.get("rank", "?")
name = package.get("package", "unknown")
@ -166,7 +165,7 @@ async def demo_package_comparison():
# Compare web frameworks
frameworks = ["django", "flask", "fastapi", "tornado"]
print(f"\n🔍 Comparing Web Frameworks (last month downloads):")
print("\n🔍 Comparing Web Frameworks (last month downloads):")
print("-" * 70)
comparison_data = []

View File

@ -2,7 +2,6 @@
import asyncio
import logging
from datetime import datetime, timedelta
from typing import Any
import httpx

View File

@ -541,7 +541,7 @@ async def get_top_downloaded_packages(
logger.info(f"MCP tool: Getting top {actual_limit} packages for period: {period}")
result = await get_top_packages_by_downloads(period, actual_limit)
logger.info(f"Successfully retrieved top packages list")
logger.info("Successfully retrieved top packages list")
return result
except Exception as e:
logger.error(f"Error getting top packages: {e}")

View File

@ -1,12 +1,11 @@
"""PyPI package download statistics tools."""
import logging
from datetime import datetime, timedelta
from datetime import datetime
from typing import Any
from ..core.pypi_client import PyPIClient
from ..core.stats_client import PyPIStatsClient
from ..core.exceptions import InvalidPackageNameError, NetworkError, PackageNotFoundError
logger = logging.getLogger(__name__)

View File

@ -1,17 +1,18 @@
"""Tests for download statistics functionality."""
import pytest
from unittest.mock import AsyncMock, patch
import pytest
from pypi_query_mcp.core.exceptions import PackageNotFoundError
from pypi_query_mcp.tools.download_stats import (
get_package_download_stats,
get_package_download_trends,
get_top_packages_by_downloads,
_analyze_download_stats,
_analyze_download_trends,
_extract_download_count,
get_package_download_stats,
get_package_download_trends,
get_top_packages_by_downloads,
)
from pypi_query_mcp.core.exceptions import PackageNotFoundError, InvalidPackageNameError
class TestDownloadStats: