CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-safety

Scan dependencies for known vulnerabilities and licenses.

Overall
score

61%

Overview
Eval results
Files

task.mdevals/scenario-1/

Package Manager Command Parser

Build a Python module that parses package manager commands and normalizes them into a common format.

Overview

Different package managers use different command syntax for similar operations. This module should parse commands from pip, poetry, and npm, and extract the operation type, package names, and version constraints in a normalized format.

Requirements

Command Parsing

Parse package manager commands to extract:

  • Operation type (add package, remove package, or update package)
  • Package name(s)
  • Version constraints (if specified)
  • Whether it's a development dependency

Supported Package Managers

Support these package managers:

  • pip (e.g., pip install, pip uninstall)
  • poetry (e.g., poetry add, poetry remove)
  • npm (e.g., npm install, npm uninstall)

Normalized Output

Return structured data containing:

  • Operation type as a standardized enum value
  • List of packages with version information
  • Development dependency flag
  • Source tool name

Test Cases

  • Given pip install requests==2.28.0, extracts operation type as "ADD_PACKAGE" and package "requests" with version "2.28.0" @test
  • Given poetry add flask --group dev, extracts operation type as "ADD_PACKAGE", package "flask", and marks as dev dependency @test
  • Given npm install express@4.18.0, extracts operation type as "ADD_PACKAGE" and package "express" with version "4.18.0" @test
  • Given pip uninstall numpy, extracts operation type as "REMOVE_PACKAGE" and package "numpy" @test

Implementation

@generates

API

from typing import Dict, List, Any, Optional
from enum import Enum

class OperationType(Enum):
    """Normalized operation types across package managers"""
    ADD_PACKAGE = "add"
    REMOVE_PACKAGE = "remove"
    UPDATE_PACKAGE = "update"

class PackageInfo:
    """Information about a package extracted from a command"""
    def __init__(self, name: str, version: Optional[str] = None, extras: Optional[List[str]] = None):
        self.name = name
        self.version = version
        self.extras = extras or []

    def to_dict(self) -> Dict[str, Any]:
        """Convert to dictionary representation"""
        pass

class CommandAnalysis:
    """Result of analyzing a package manager command"""
    def __init__(self, operation_type: OperationType, packages: List[PackageInfo],
                 is_dev_dependency: bool, tool: str):
        self.operation_type = operation_type
        self.packages = packages
        self.is_dev_dependency = is_dev_dependency
        self.tool = tool

    def to_json(self) -> str:
        """Convert analysis to JSON string"""
        pass

def analyze_command(command: str) -> CommandAnalysis:
    """
    Analyzes a package manager command and extracts normalized intent information.

    Args:
        command: Full command string (e.g., "pip install requests==2.28.0")

    Returns:
        CommandAnalysis object containing normalized operation info

    Raises:
        ValueError: If command format is invalid or unsupported
    """
    pass

Dependencies { .dependencies }

safety { .dependency }

Provides command intention normalization functionality for security scanning across multiple package managers.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/pypi-safety

tile.json