QGIS Plugin Analyzer 🛡️
👉 View Full Rules Catalog (RULES.md)
Quality Metrics:
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
Security & correctness
- Bandit-inspired Security Core: Detects
eval/exec(B307/B102), unsafepickle(B301),shell=True(B602), SQL injection (B608) and hardcoded secrets; findings carry CWE ids. - Deep Entropy Secret Scanner: Detects hardcoded API keys, passwords and tokens via regex + information entropy.
- Extended Safety Audit: Signal leaks, missing slots and UI-blocking loops, with
QgsTasksuggestions. - Qt Resource Validation: Detects missing/broken resource paths (
:/plugins/...).
QGIS standards & modernization
- Precise AST rules: i18n (
self.tr()/QCoreApplication.translate()), obsolete API, protected members, mandatory cleanup,iface-as-argument, and more. - Qt6 Migration Rules: 11 AST-based
QT6_*rules (drop-in parity withflake8-qgisQGS4xx) detecting APIs removed in Qt6. - Official Repository Compliance: Validates binaries, package size and metadata URLs before upload.
Quality & maintainability
- Cyclomatic Complexity Gate:
--max-cc Nfails CI when a function exceeds the threshold (cc_gate/cc_violationsin--json). - Design Patterns & Anti-patterns: Detects
singleton/factory/observer/strategy/decorator, plusGOD_OBJECT,SPAGHETTI_CODE,MAGIC_NUMBER,DEAD_CODE. - Halstead Metrics & Optimizations: Per-module Halstead metrics and
module_too_large/complexity_refactoringsuggestions. - Transversal
# noqa: Suppress any rule inline with# noqa(whole line) or# noqa: RULE_ID(single rule). - Enhanced Configuration Profiles: Rule-level severity control (
error,warning,info,ignore) viapyproject.toml. - Integrated Ruff Analysis: Runs Ruff through the active interpreter, exposing
ruff_metadata.tool_unavailablewhen unavailable.
Architecture & performance
- High-Performance Engine:
ProcessPoolExecutorwith single-pass AST traversal, shared worker context, a configurable worker count (--workers) and file batching. - Deep Semantic Analysis: Cross-file dependency graph (Mermaid), circular-import detection and coupling metrics.
- Project Auto-Detection: Distinguishes official QGIS plugins from generic Python projects and tailors validation accordingly.
- Advanced Ignore Engine:
.analyzerignorewith non-anchored patterns and smart default excludes (.venv,build, …).
DX & integration
- Interactive Auto-Fix: AST-based fixes (GDAL imports, PyQt bridge, logging, i18n) with Git-status verification and diff preview.
- CI Output Contract:
--json,--include-content, and a versioned/schema'dproject_context.json(schema_version,analyzer_version,ruff_metadata,patterns,optimizations). - Quality Gates in CI:
ruff+mypy+pytest(coverage floor) and the--max-ccself-analysis gate on Python 3.11–3.13. - Embedded Web Server: Built-in
servecommand to browse HTML reports. - Real-time Progress: CLI progress bar with ETA tracking.
- Zero Runtime Dependencies: Standard library only (Ruff is the only external tool).
🆕 What's New in v1.15.2
B102/B307 false-positive fix — the restored security scanner no longer flags ordinary Qt method calls.
- 🎯
exec/evalrule fixed -QDialog.exec(),self.dlg.exec()and other attribute/method calls are no longer reported as builtin arbitrary code execution; only bareexec(...)/eval(...)are flagged. - 🧪 Regression tests - attribute
.exec()/.eval()are asserted to be ignored.
📖 Full Release Notes | 🗺️ CLI Commands Roadmap
🚀 Installation and Usage
Installation with uv (Recommended):
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
3. 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
.qrcfiles 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
# noqaor.analyzerignoreto handle these cases.
⌨️ Full CLI Reference
Note: The Python package is named
qgis-plugin-analyzer, but the command-line tool is installed asqgis-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)allor 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 |
--workers N |
Number of parallel worker processes (clamped to 1..4 to bound memory). |
min(4, cpu-1) |
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, security. |
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
Written to the --output directory (default ./analysis_results):
project_context.json— machine-readable contract (schema v1):- Top level:
schema_version,analyzer_version,project_name,project_path,analyzed_at,metrics. ruff_findings+ruff_metadata(exit_code,tool_unavailable,command).patterns(design patterns) andoptimizations(module_too_large,complexity_refactoring).- Per module:
path,lines,complexity,imports,functions,classes,ast_issues,research_metrics(type-hint/docstring coverage,halstead). cc_gate/cc_violationswhen--max-ccis used with--json.
- Top level:
PROJECT_SUMMARY.md/PROJECT_SUMMARY.html— human-readable report.analyzer.log— run log.
The JSON is consumed by
ai-context-core; keep the schema keys stable (bumpschema_versionon change).
📜 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
- PyQGIS Developer Cookbook: The primary resource for PyQGIS API usage and standards.
- QGIS Plugin Repository Requirements: Mandatory criteria for plugin approval in the official repository.
- QGIS Coding Standards: Core style and organization guidelines for the QGIS project.
- QGIS HIG (Human Interface Guidelines): Standards for consistent and accessible user interface design.
- QGIS Security Scanning Documentation: Official guide on automated security analysis (Bandit, detect-secrets) for plugins.
Industry & Community Standards
- flake8-qgis Rules: Community-driven linting rules for PyQGIS (QGS101-412).
- PEP 8 Style Guide: The fundamental style guide for Python code.
- PEP 257 Docstring Conventions: Standards for docstring structure and content.
- Maintainability Index (SEI): Methodology for measuring software maintainability.
- Conventional Commits: Standard for clear, machine-readable commit history.
- Keep a Changelog: Best practices for maintainable version history.
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
- Detailed Rules Catalog: Full documentation of all audit rules implemented in this analyzer.
- Standardized Scoring Metrics: Mathematical logic and thresholds for project evaluation.
- Project Roadmap: Current status and future plans for the analyzer.
- Comparison vs Alternatives: Internal positioning notes (kept out of this README).
- Documentation Folder: Historical release notes, competitive analysis, and modernization guides.
🛠️ 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.15.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| qgis_plugin_analyzer-1.15.2.tar.gz | 124.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| qgis_plugin_analyzer-1.15.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 244.4 kB
Release files / qgis_plugin_analyzer-1.15.2.tar.gz
| Download URL | qgis_plugin_analyzer-1.15.2.tar.gz |
|---|---|
| Size | 124.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a2f2c2f879e48d2552f262422788930d2e4eb80a295a8b9a5ff5187306d82ff
|
|
BLAKE2b-256 checksum How to use checksums |
de3440f43c8487ef5d0a2055a345b9a3329d3ec0423674ae2103c43afe3aa132
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / qgis_plugin_analyzer-1.15.2-py3-none-any.whl
| Download URL | qgis_plugin_analyzer-1.15.2-py3-none-any.whl |
|---|---|
| Size | 119.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7cffd883c139915a56f7785ac628102958ee69c6e4e635ff24befa49df4f7189
|
|
BLAKE2b-256 checksum How to use checksums |
7c2d2ab4304337158bde081caa680d2f649e93471d03ec2b8f7d9d9b885942a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|