Skip to main content

Flake8 plugin for QGIS python plugins.

Project description

flake8-qgis

PyPI version Downloads CI Code on Github Code style: black Imports: isort pre-commit

A flake8 plugin for QGIS3 python plugins written in Python.

Made with Cookiecutter template cookiecutter-flake8-plugin. Inspired by flake8-simplify.

Installation

Install with pip:

pip install flake8-qgis

Usage

Just call flake8 . in your package or flake your.py.

Rules

  • QGS101: Don't use from-imports from qgis protected members (example)
  • QGS102: Don't use imports from qgis protected members (example)
  • QGS103: Don't use from-imports from PyQt directly (example)
  • QGS104: Don't use imports from PyQt directly (example)
  • QGS105: Don't pass QgisInterface as an argument (example)
  • QGS106: Don't import gdal directly, import if from osgeo package (example)

You might have good reasons to ignore some rules. To do that, use the standard Flake8 configuration. For example, within the setup.cfg file:

[flake8]
ignore = QGS101, QGS102

Examples

QGS101

# Bad
from qgs._core import QgsMapLayer, QgsVectorLayer
from qgis._core import QgsApplication

# Good
from qgs.core import QgsMapLayer, QgsVectorLayer
from qgis.core import QgsApplication

QGS102

# Bad
import qgs._core.QgsVectorLayer as QgsVectorLayer

# Good
import qgs.core.QgsVectorLayer as QgsVectorLayer

QGS103

# Bad
from PyQt5.QtCore import pyqtSignal

# Good
from qgis.PyQt.QtCore import pyqtSignal

QGS104

# Bad
import PyQt5.QtCore.pyqtSignal as pyqtSignal

# Good
import qgis.PyQt.QtCore.pyqtSignal as pyqtSignal

QGS105

# Bad: iface passed as argument
def some_function(somearg, iface):
    # do something with iface


# Good: iface imported
from qgis.utils import iface

def some_function(somearg):
    # do something with iface
# in classFactory the passing is OK, since QGIS injects it
def classFactory(iface):
    # preferably do not pass the iface to plugin

QGS106

# Bad
import gdal
import ogr

# Good
from osgeo import gdal

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8_qgis-1.0.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

flake8_qgis-1.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file flake8_qgis-1.0.0.tar.gz.

File metadata

  • Download URL: flake8_qgis-1.0.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.7

File hashes

Hashes for flake8_qgis-1.0.0.tar.gz
Algorithm Hash digest
SHA256 56ce297c4f3282dd127e04d3dd40e25dcb994ad868b839ea291ee6583e8e743d
MD5 8af3ea1dd6f033991673d1fa47603a80
BLAKE2b-256 cce07e1307a647e7a8a2b6c9dae58873ef17162bfe41fc28e473d1619a9f1943

See more details on using hashes here.

File details

Details for the file flake8_qgis-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: flake8_qgis-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.0 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.7

File hashes

Hashes for flake8_qgis-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f094e5253036d3f36a29ff25fbfdf5f37f0d4c234917a0a65e30ef89350335fd
MD5 f5bbe02b45d08c17be0473f06bf317e4
BLAKE2b-256 71c9b7a3d883141766cd03d4f5a6e3de2da9b32e9b62ebaee7f0e1854e1a1f82

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page