Skip to main content

QGIS Plugin Analyzer 🛡️

👉 View Full Rules Catalog (RULES.md)

GitHub release (latest by date) PyPI version PyPI downloads Python Version License GitHub stars GitHub forks Maintenance Conventional Commits

Quality Metrics:

Module Stability Maintainability Security Score Type Coverage Docstring Coverage Tests

The QGIS Plugin Analyzer is a static analysis tool designed specifically for QGIS (PyQGIS) plugin developers. Its goal is to elevate plugin quality by ensuring they follow community best practices and are optimized for AI-assisted development.

✨ Main Features

  • Quality Blindage: Comprehensive test suite with 76% global coverage and >95% on core AST visitors.
  • Gen 6 Architecture: Modernized agentic system with observability, memory lifecycle, and CodeWhale runtime bridge.
  • Scaffold System: Integrated blueprints for standardizing QGIS and mining plugin generation.
  • Security Core (Bandit-inspired): Professional vulnerability scanning detecting eval, exec, shell injections, and SQL injection risks.
  • Deep Entropy Secret Scanner: Detects hardcoded API keys, passwords, and sensitive tokens using regex and information entropy.
  • High-Performance Engine: Parallel analysis powered by ProcessPoolExecutor with single-pass AST traversal and shared worker context.
  • Project Auto-Detection: Intelligently distinguishes between official QGIS Plugins and Generic Python Projects, tailoring validation logic accordingly.
  • Advanced Ignore Engine: Robust .analyzerignore support with non-anchored patterns and smart default excludes (.venv, build, etc.).
  • Deep Semantic Analysis: Cross-file dependency graphing (Mermaid), circular import detection, and module coupling metrics.
  • Interactive Auto-Fix Mode: Automatically fix common QGIS issues (GDAL imports, PyQt bridge, logging, i18n) with safety checks.
  • Official Repository Compliance: Proactive validation of binaries, package size, and metadata URLs.
  • Real-time Progress: CLI feedback with a progress bar and ETA tracking.
  • Enhanced Configuration Profiles: Rule-level severity control (error, warning, info, ignore) via pyproject.toml.
  • Integrated Ruff Analysis: Combines custom QGIS rules with the fastest linter in the Python ecosystem.
  • AST-based i18n Audit: Portable AST rule recognizing self.tr() and QCoreApplication.translate(), excluding docstrings/technical strings and honoring # no-i18n / # noqa.
  • Cyclomatic Complexity Gate: --max-cc N fails CI when any function exceeds the threshold, with cc_gate/cc_violations in --json.
  • Qt6 Migration Rules: 11 AST-based QT6_* rules (drop-in parity with flake8-qgis QGS4xx) detecting APIs removed in Qt6.
  • CI Output Contract: --json, --include-content, and a versioned/schema'd project_context.json for machine-readable integration.
  • Qt Resource Validation: Detect missing or broken resource paths (:/plugins/...) in your code.
  • Extended Safety Audit: Detection of signal leaks, missing slots, and UI-blocking loops (QgsTask suggestions).
  • Embedded Web Server: View reports instantly with the built-in serve command.
  • AI-Ready: Generates structured summaries and optimized contexts for LLMs.
  • Zero Runtime Dependencies: Works using only the Python standard library (Ruff as an external tool).

🆕 What's New in v1.14.0

Analyzer Generalization - The analyzer now audits any QGIS plugin with a portable AST-based i18n rule (recognizing self.tr() and QCoreApplication.translate(), plus inline # no-i18n), a --max-cc N complexity gate for CI, and 11 Qt6 migration rules matching flake8-qgis QGS4xx.

  • 🌐 AST-based i18n - Replaced the string heuristic with a precise AST rule; no more false positives on translated strings.
  • 🚦 --max-cc gate - Fail CI on excessive cyclomatic complexity.
  • 🆙 Qt6 migration rules - Drop-in parity with flake8-qgis QGS4xx.
  • 🐍 Python 3.11 - Raised the floor and dropped the hand-rolled TOML parser for stdlib tomllib.
  • 📦 CI output contract - --json, --include-content, versioned project_context.json.
  • 🕒 Stale-cache detection - summary warns when results are outdated.

📖 Full Release Notes | 🗺️ CLI Commands Roadmap

⚖️ Why use this Analyzer? (Comparison)

Feature QGIS Plugin Analyzer flake8-qgis Ruff (Standard) Official Repo Bot
Run Locally / Offline ✅ (Your Machine) ✅ ✅ ❌ (Upload Only)
Static Linting ✅ (Ruff + Custom) ✅ (flake8) ✅ (General) ✅ (Limited)
QGIS-Specific Rules ✅ (Precise AST) ✅ (Regex/AST) ❌ ✅
Interactive Auto-Fix ✅ ❌ ❌ ❌
Semantic Analysis ✅ ❌ ❌ ❌
Security Audit ✅ (Bandit-style) ❌ ❌ ✅ (Server-side)
Secret Scanning ✅ (Entropy) ❌ ❌ ✅ (Server-side)
HTML/MD Reports ✅ ❌ ❌ ❌
AI Context Gen ✅ (Project Brain) ❌ ❌ ❌

Key Differentiators

  1. Shift Left (Run Locally): The biggest advantage is being able to run the same high-standard checks as the Official Repository before you upload your plugin. No more "reject-fix-upload" loops.
  2. High-Performance Hybrid Engine: Combines multi-core AST processing with deep understanding of cross-file relationships and Qt-specific patterns.
  3. Safety-First Auto-Fixing: AST-based transformations with Git status verification and interactive diff previews.
  4. Zero Runtime Stack: Minimal footprint, ultra-fast execution, and easy CI integration.
  5. AI-Centric Design: Built to help developers and AI agents understand complex QGIS plugins instantly.

🚀 Installation and Usage

If you have uv installed, you can install the analyzer quickly and in isolation:

1. As a global tool (isolated):

uv tool install git+https://github.com/geociencio/qgis-plugin-analyzer.git

2. Standard pip installation (Git):

pip install git+https://github.com/geociencio/qgis-plugin-analyzer.git

2. Local installation for development:

git clone https://github.com/geociencio/qgis-plugin-analyzer
cd qgis-plugin-analyzer
uv sync

Installation with pip:

pip install .

Main Commands:

1. Analyze a Plugin (Full Analysis):

qgis-analyzer analyze /path/to/your/plugin -o ./quality_report

2. Specialized Analysis (NEW in v1.9.0):

# Internationalization audit only
qgis-analyzer analyze i18n /path/to/your/plugin

# Security vulnerability scanning only
qgis-analyzer analyze security /path/to/your/plugin

# Performance and UI blocking detection only
qgis-analyzer analyze performance /path/to/your/plugin

# Dependency and coupling analysis only
qgis-analyzer analyze architecture /path/to/your/plugin

# QGIS metadata validation only
qgis-analyzer analyze metadata /path/to/your/plugin

3. Auto-Fix issues (Dry Run):

qgis-analyzer fix /path/to/your/plugin

4. Legacy Support: The default command remains analysis if no subcommand is specified:

qgis-analyzer /path/to/your/plugin

🔄 Pre-commit Hook

You can run qgis-plugin-analyzer automatically before every commit to ensure quality. Add this to your .pre-commit-config.yaml:

  - repo: https://github.com/geociencio/qgis-plugin-analyzer
    rev: main  # Use 'main' for latest features or a specific tag like v1.5.0
    hooks:
      - id: qgis-plugin-analyzer

🤖 GitHub Action

Use it directly in your CI/CD workflows:

steps:
  - uses: actions/checkout@v4
  - name: Run QGIS Quality Check
    uses: geociencio/qgis-plugin-analyzer@main
    with:
      path: .
      output: quality_report
      args: --profile release

⚙️ Configuration (pyproject.toml)

You can customize the analyzer's behavior using a [tool.qgis-analyzer] section in your pyproject.toml.

[tool.qgis-analyzer]
# Profiles allow different settings for CI vs Local
[tool.qgis-analyzer.profiles.default]
strict = false
generate_html = false  # CLI default

[tool.qgis-analyzer.profiles.release]
strict = true
fail_on_error = true

[tool.qgis-analyzer.profiles.default.rules]
GDAL_DIRECT_IMPORT = "error"    # Ban direct 'import gdal'
IFACE_AS_ARGUMENT = "warning"   # Warn on iface passed as an argument
MANUAL_RESOURCE_PATH = "ignore" # Ignore resource path checks

# i18n rule configuration (AST-based):
[tool.qgis-analyzer.profiles.default.rules.MISSING_I18N]
extra_ignore_calls = ["customSetLabel"]
extra_exact_ignores = ["My App Name"]

⚠️ Technical Limitations

This tool performs Static Analysis (AST & Regex parsing). It does not execute your code or load QGIS libraries.

  • Dynamic Imports: Imports inside functions or conditional blocks might be analyzed differently than top-level imports.
  • Runtime Validation: Checks like "Missing Resources" rely on static string analysis of .qrc files and path strings. It cannot verify resources loaded dynamically at runtime.
  • False Positives: While we strive for accuracy, complex meta-programming or unusual patterns might trigger false positives. Use # noqa or .analyzerignore to handle these cases.

⌨️ Full CLI Reference

Note: The Python package is named qgis-plugin-analyzer, but the command-line tool is installed as qgis-analyzer.

qgis-analyzer analyze [scope] [path]

Audits an existing QGIS plugin repository with optional specialized scopes.

NEW in v1.9.0: Specialized analysis scopes for targeted auditing.

Available Scopes:

  • i18n - Internationalization and translation audit (detects untranslated strings)
  • security - Security vulnerability scanning (unsafe calls, hardcoded secrets, SQL injection)
  • performance - Performance and UI blocking detection (blocking loops, missing indexes)
  • architecture - Dependency and coupling analysis (imports, QGIS API usage)
  • metadata - QGIS metadata validation (metadata.txt compliance)
  • all or no scope - Full analysis (default, legacy compatible)

Arguments:

Argument Description Default
scope (Optional) Analysis scope: i18n, security, performance, architecture, metadata, or all. all
project_path (Required) Path to the plugin directory to analyze. .
-o, --output Directory where HTML/Markdown reports will be saved. ./analysis_results
-r, --report Explicitly generate detailed HTML/Markdown reports. False
-p, --profile Configuration profile from pyproject.toml (default, release). default
--json Emit machine-readable JSON (project_context.json) to stdout. False
--include-content Embed module source content in the JSON output. False
--max-cc N Fail analysis if any function exceeds this cyclomatic complexity. off

Examples:

# Full analysis (legacy compatible)
qgis-analyzer analyze .
qgis-analyzer analyze /path/to/plugin

# Specialized i18n analysis
qgis-analyzer analyze i18n .

# Security-only scan with reports
qgis-analyzer analyze security . --report

qgis-analyzer fix

Automatically fix common QGIS issues identified during analysis.

Argument Description Default
path (Required) Path to the plugin directory. N/A
--dry-run Show proposed changes without applying them. True
--apply Apply fixes to the files (disables dry-run). False
--auto-approve Apply fixes without interactive confirmation. False
--rules Comma-separated list of rule IDs to fix. Fix all
-o, --output Directory to read previous analysis from. ./analysis_results

qgis-analyzer summary

Shows a professional, color-coded summary of findings directly in your terminal.

Argument Description Default
-b, --by Granularity of the summary: total, modules, functions, classes. total
-i, --input Path to the project_context.json file to summarize. analysis_results/project_context.json

qgis-analyzer security

Performs a focused security scan on a file or directory.

Argument Description Default
path (Required) Path to the file or directory to scan. N/A
--deep Run more intensive (but slower) security checks. False
-p, --profile Configuration profile. default

qgis-analyzer version

Shows the current version of the analyzer.

Example:

# Executive summary
qgis-analyzer summary

# Identify high-complexity functions
qgis-analyzer summary --by functions

qgis-analyzer list-rules

Displays the full catalog of implemented QGIS audit rules with their severity and descriptions.

qgis-analyzer graph

Visualizes the project's dependency graph.

Argument Description Default
project_path Path to the plugin directory. .
--format Output format: text or mermaid. text

qgis-analyzer serve

Starts a local web server to view the generated HTML reports.

Argument Description Default
path Path to the analysis results directory. ./analysis_results
--port Port to run the server on. 8000

qgis-analyzer init

Initializes a recommended .analyzerignore file in the current directory with common Python and QGIS development exclusions.

📊 Generated Reports

  • project_context.json: Full structured data for external integrations.

📜 Audit Rules

For a complete list of all implemented checks, their severity, and recommendations, please refer to the:

👉 Detailed Rules Catalog (RULES.md)

📚 References and Standards

The development of this analyzer is based on official QGIS community guidelines, geospatial standards, and industry best practices:

Official QGIS Documentation

Industry & Community Standards

Security Standards

  • Bandit (PyCQA): The security rules implemented (B1xx - B6xx) are directly derived from the Bandit project's rule set for identifying common security issues in Python code.
  • CWE (Common Weakness Enumeration): Security findings are mapped to standard CWE IDs (e.g., CWE-78 Command Injection, CWE-89 SQL Injection) for industry-standard classification.
  • OWASP Top 10: The "Hardcoded Secret" and "Injection" checks align with critical OWASP vulnerabilities.

Internal Resources

🛠️ Contributing

Contributions are welcome! Please refer to our Contributing Guide to learn how to report bugs, propose rules, and submit code changes.

Audit rules are located in src/analyzer/rules/ (regex catalog) and src/analyzer/visitors/ (AST visitors). Feel free to add new rules following the existing pattern!


⚖️ License

This project is licensed under the GNU General Public License v3 (GPL v3). See the LICENSE file for details.


Developed for the SecInterp team and the QGIS community.

Metadata

Release files for qgis-plugin-analyzer 1.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qgis-plugin-analyzer 1.14.0
File Size Uploaded
qgis_plugin_analyzer-1.14.0.tar.gz 115.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qgis-plugin-analyzer 1.14.0
File Interpreter ABI Platform
qgis_plugin_analyzer-1.14.0-py3-none-any.whl Python 3 none any Details

Total release size: 228.9 kB

Release files / qgis_plugin_analyzer-1.14.0.tar.gz

Download URL qgis_plugin_analyzer-1.14.0.tar.gz
Size 115.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e8016c5cee02d6cb9f070b2ddbebc73054497dd98b9334267d47070786870602
BLAKE2b-256 checksum
How to use checksums
07ab44ee05ec0572814001e0ab8d8571834ec1dd16eac2adf582707a9c3739c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release files / qgis_plugin_analyzer-1.14.0-py3-none-any.whl

Download URL qgis_plugin_analyzer-1.14.0-py3-none-any.whl
Size 113.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d73461c2be8f3a1d5eb13ad7a2a239c9009fbffd1539dfcce571e18c3fed3f5
BLAKE2b-256 checksum
How to use checksums
3ba406cb4f6070452c9d2be9a7cddab1b1cf62e15a06142773a6829d91346ca8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.12

Release history Release notifications | RSS feed

1.16.0

2 release files

1.15.2

2 release files

1.15.1

2 release files

1.15.0

2 release files

This release

1.14.0 This release

2 release files

1.13.2

2 release files

1.13.1

2 release files

1.12.0

2 release files

1.10.1

2 release files

1.10.0

2 release files

1.9.0

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page