Giter Site home page Giter Site logo

flake8-qgis's Introduction

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 qgis._core import QgsMapLayer, QgsVectorLayer
from qgis._core import QgsApplication

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

QGS102

# Bad
import qgis._core.QgsVectorLayer as QgsVectorLayer

# Good
import qgis.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

flake8-qgis's People

Contributors

jakimowb avatar joonalai avatar lehtojaa avatar lkajan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.