### Install Pymetrica from Source Source: https://pypi.org/project/pymetrica/1.5.6 Clone the repository and install Pymetrica from source using pip. ```bash git clone https://github.com/JuanJFarina/pymetrica cd pymetrica pip install -e . ``` -------------------------------- ### Install Pymetrica from PyPI Source: https://pypi.org/project/pymetrica/1.5.6 Install the latest published package from PyPI using pip. ```bash pip install pymetrica ``` -------------------------------- ### Install Pymetrica from Source Source: https://pypi.org/project/pymetrica Clone the repository and install Pymetrica in editable mode. This method is useful for development. ```bash git clone https://github.com/JuanJFarina/pymetrica cd pymetrica pip install -e . ``` -------------------------------- ### Install Pymetrica from PyPI Source: https://pypi.org/project/pymetrica Install the latest published package using pip. Requires Python 3.10 or newer. ```bash pip install pymetrica ``` -------------------------------- ### Get Base Statistics with Pymetrica Source: https://pypi.org/project/pymetrica/1.5.6 Use the 'base-stats' command to get an initial overview of a codebase. ```bash pymetrica base-stats path/to/project ``` -------------------------------- ### Pymetrica Short Report Example Source: https://pypi.org/project/pymetrica/1.5.6 Example output of a short terminal report from Pymetrica, showing key metrics like Abstract Lines Of Code, Cyclomatic Complexity, Halstead Volume, Primitive Obsession, Maintainability Cost, and Instability. ```text ---------------------------------------------------------------------------------------------------- Short Report ---------------------------------------------------------------------------------------------------- Metric: Abstract Lines Of Code aloc_number: 6 aloc_percentage: 15.0 ---------------------------------------------------------------------------------------------------- Metric: Cyclomatic Complexity cc_number: 23 lloc_per_cc: 1.7391304347826086 ---------------------------------------------------------------------------------------------------- Metric: Halstead Volume hv_number: 704.5342159112735 hv_per_lloc: 17.613355397781838 ---------------------------------------------------------------------------------------------------- Metric: Primitive Obsession all_primitives_percent: 0.0 targeted_primitives_percent: 0.0 ---------------------------------------------------------------------------------------------------- Metric: Maintainability Cost maintainability_cost: 50.678396768622775 raw_line_cost: 50.638396768622776 ---------------------------------------------------------------------------------------------------- Metric: Instability root: 0.0 ---------------------------------------------------------------------------------------------------- ``` -------------------------------- ### Run Pymetrica CLI Source: https://pypi.org/project/pymetrica/1.5.6 Access the Pymetrica command-line interface after installation. ```bash pymetrica ``` -------------------------------- ### Run Pymetrica with Basic Hook Report Source: https://pypi.org/project/pymetrica/1.5.6 Analyze a project using the 'run-all' command with the BASIC_HOOK report backend to enforce thresholds. ```bash pymetrica run-all -rt BASIC_HOOK path/to/project ``` -------------------------------- ### Analyze a Python Project with Pymetrica Source: https://pypi.org/project/pymetrica/1.5.6 Use the 'run-all' command to analyze a specified Python project path. ```bash pymetrica run-all path/to/project ``` -------------------------------- ### List All Pymetrica CLI Commands Source: https://pypi.org/project/pymetrica/1.5.6 View all available commands for the Pymetrica CLI. ```bash pymetrica status pymetrica base-stats pymetrica aloc pymetrica cc pymetrica hv pymetrica po pymetrica mc pymetrica li pymetrica run-all ``` -------------------------------- ### Pymetrica Architecture Overview Source: https://pypi.org/project/pymetrica/1.5.6 Illustrates the flow of Pymetrica's analysis pipeline, from codebase parsing to report generation. ```text Codebase Parsing ↓ Code Representation ↓ Metric Calculators ↓ Results ↓ Report Generators ``` -------------------------------- ### Run Pymetrica with Hook Report Backend Source: https://pypi.org/project/pymetrica Enforce thresholds in automation by using the BASIC_HOOK report backend. This command analyzes the project and reports threshold violations. ```bash pymetrica run-all -rt BASIC_HOOK path/to/project ``` -------------------------------- ### Run Pymetrica Analysis Source: https://pypi.org/project/pymetrica/1.5.6 Execute Pymetrica analysis on a specified project path. Use `--long-report` for detailed summaries and `-rt BASIC_HOOK` for CI integration with exit status. ```bash pymetrica run-all path/to/project ``` -------------------------------- ### Typical Pymetrica CLI Usage Pattern Source: https://pypi.org/project/pymetrica/1.5.6 General pattern for using Pymetrica commands with a directory path. ```bash pymetrica DIR_PATH ``` -------------------------------- ### Analyze Cyclomatic Complexity with Pymetrica Source: https://pypi.org/project/pymetrica/1.5.6 Focus on a single metric like cyclomatic complexity (cc) using its dedicated command. ```bash pymetrica cc path/to/project ``` -------------------------------- ### Generate Architecture Diagram Source: https://pypi.org/project/pymetrica/1.5.6 Use this command to generate a Mermaid diagram (`.mmd` file) representing the layered architecture of a specified project path. The diagram focuses on top-level layers and components, omitting root-level files and `__init__.py`-style files. ```bash pymetrica base-stats --diagram path/to/project ``` -------------------------------- ### Pymetrica Pre-commit Hooks Configuration Source: https://pypi.org/project/pymetrica/1.5.6 Set up Pymetrica pre-commit hooks in your .pre-commit-config.yaml file. ```yaml repos: - repo: https://github.com/JuanJFarina/pymetrica rev: v1.5.4 hooks: - id: pymetrica - id: pymetrica-mc - id: pymetrica-po ``` -------------------------------- ### Run Project Tests Source: https://pypi.org/project/pymetrica/1.5.6 Execute the project's tests using pytest. These tests cover the parser, core metric calculators, diagram generation, and bundled sample codebases. ```bash pytest ``` -------------------------------- ### Python API Usage for Code Analysis Source: https://pypi.org/project/pymetrica/1.5.6 Demonstrates a typical programmatic workflow using Pymetrica's Python API to parse a codebase, calculate various metrics, and generate a terminal report. Ensure the path to your project is correctly specified. ```python from pymetrica.codebase_parser import create_diagram, parse_codebase from pymetrica.metric_calculators import ( AlocCalculator, CCCalculator, HalsteadVolumeCalculator, InstabilityCalculator, MaintainabilityCostCalculator, PrimitiveObsessionCalculator, ) from pymetrica.report_generators import REPORTS_MAPPING codebase = parse_codebase("path/to/project") metrics = [ AlocCalculator().calculate_metric(codebase), CCCalculator().calculate_metric(codebase), HalsteadVolumeCalculator().calculate_metric(codebase), PrimitiveObsessionCalculator().calculate_metric(codebase), MaintainabilityCostCalculator().calculate_metric(codebase), InstabilityCalculator().calculate_metric(codebase), ] report_generator = REPORTS_MAPPING["BASIC_TERMINAL"](metrics) print(report_generator.long_report().content) create_diagram(codebase, filename="architecture.mmd") ``` -------------------------------- ### Pymetrica Single Metric Analysis Source: https://pypi.org/project/pymetrica/1.5.6 Analyze a specific metric, such as Cyclomatic Complexity (cc), for a project. This command defaults to printing the descriptive report format. ```bash pymetrica cc path/to/project ``` -------------------------------- ### Generate Mermaid Diagram Source: https://pypi.org/project/pymetrica Use this command to generate a Mermaid diagram representing the layered architecture of a project. The output is a .mmd file. ```bash pymetrica base-stats --diagram path/to/project ``` -------------------------------- ### Pymetrica Configuration in pyproject.toml Source: https://pypi.org/project/pymetrica/1.5.6 Configure thresholds and exclusion patterns for Pymetrica in the pyproject.toml file. ```toml [tool.pymetrica] aloc_fail_threshold = 30 cc_fail_threshold = 10 hv_fail_threshold = 30 po_all_fail_threshold = 10 po_targeted_fail_threshold = 2 mc_fail_threshold = 25 exclude = ["generated/*", "vendor/*"] top_findings = 5 ``` -------------------------------- ### Configure Pymetrica Thresholds and Exclusions Source: https://pypi.org/project/pymetrica Define custom thresholds and exclusion patterns for Pymetrica analysis in the `[tool.pymetrica]` section of `pyproject.toml`. Thresholds can be set to 0 to disable failure gating. ```toml [tool.pymetrica] aloc_fail_threshold = 30 cc_fail_threshold = 10 hv_fail_threshold = 30 po_all_fail_threshold = 10 po_targeted_fail_threshold = 2 mc_fail_threshold = 25 exclude = ["generated/*", "vendor/*"] top_findings = 5 ``` -------------------------------- ### Instability Formula Source: https://pypi.org/project/pymetrica/1.5.6 The formula for calculating package instability based on efferent and afferent coupling. Values range from 0 (stable) to 1 (unstable). ```mathematics Instability = Efferent Coupling / (Afferent Coupling + Efferent Coupling) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.