Scan dependencies for known vulnerabilities and licenses.
Overall
score
61%
Build a Python module that parses package manager commands and normalizes them into a common format.
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.
Parse package manager commands to extract:
Support these package managers:
pip install, pip uninstall)poetry add, poetry remove)npm install, npm uninstall)Return structured data containing:
pip install requests==2.28.0, extracts operation type as "ADD_PACKAGE" and package "requests" with version "2.28.0" @testpoetry add flask --group dev, extracts operation type as "ADD_PACKAGE", package "flask", and marks as dev dependency @testnpm install express@4.18.0, extracts operation type as "ADD_PACKAGE" and package "express" with version "4.18.0" @testpip uninstall numpy, extracts operation type as "REMOVE_PACKAGE" and package "numpy" @test@generates
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
"""
passProvides command intention normalization functionality for security scanning across multiple package managers.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/pypi-safetydocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10