CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-fastcore

Python supercharged for fastai development

56

1.36x
Overview
Eval results
Files

task.mdevals/scenario-5/

Code Analyzer

Build a code analysis tool that scans a project directory and generates statistics about the codebase.

Requirements

The tool should provide the following functionality:

File Discovery

Search a given directory recursively to find all relevant source code files. The tool should support:

  • Finding files matching specific patterns (e.g., all Python files, all test files)
  • Filtering files based on multiple criteria (file extensions, name patterns, directory exclusions)
  • Returning both relative paths and full Path objects for further processing

File Analysis

For each discovered file, collect the following metrics:

  • File size in bytes
  • Number of lines in the file
  • File modification timestamp

Statistics Generation

Generate and display summary statistics:

  • Total number of files found per file type
  • Total lines of code across all files
  • Average file size
  • List of the largest files (by line count)

Output

The tool should accept a directory path as input and output:

  1. A list of all discovered files grouped by type (e.g., Python files, test files, configuration files)
  2. Summary statistics showing totals and averages
  3. A sorted list of the top 5 largest files by line count

Test Cases

  • Given a test directory structure with Python files (.py), test files (*_test.py), and JSON files (.json), the tool correctly identifies and categorizes each file type @test
  • Given a directory with nested subdirectories, the tool recursively finds all matching files at any depth @test
  • Given files with various sizes, the tool correctly calculates and reports the total line count and average file size @test

Implementation

@generates

API

def find_files_by_pattern(root_dir: str, pattern: str) -> list:
    """
    Find all files in root_dir matching the given pattern.

    Args:
        root_dir: Directory to search
        pattern: File pattern to match (e.g., "*.py", "**/*_test.py")

    Returns:
        List of file paths matching the pattern
    """
    pass

def find_files_by_extension(root_dir: str, extensions: list) -> dict:
    """
    Find all files with specified extensions and group them by type.

    Args:
        root_dir: Directory to search
        extensions: List of file extensions (e.g., ['.py', '.json'])

    Returns:
        Dictionary mapping extension to list of file paths
    """
    pass

def analyze_file(filepath: str) -> dict:
    """
    Analyze a single file and return metrics.

    Args:
        filepath: Path to the file

    Returns:
        Dictionary with keys: 'size', 'lines', 'modified_time'
    """
    pass

def generate_statistics(root_dir: str, file_pattern: str = "**/*.py") -> dict:
    """
    Generate comprehensive statistics for files matching the pattern.

    Args:
        root_dir: Directory to analyze
        file_pattern: Pattern to match files

    Returns:
        Dictionary with keys: 'total_files', 'total_lines', 'avg_size', 'largest_files'
    """
    pass

Dependencies { .dependencies }

fastcore { .dependency }

Provides file search and path utilities.

Install with Tessl CLI

npx tessl i tessl/pypi-fastcore

tile.json