Add flake8 pre-commit hook

Change-Id: I1893f9031091fb02e62633d2ee387aff2b967237
This commit is contained in:
Federico Ressi 2020-07-02 15:51:01 +02:00
parent 5252001658
commit cecb2b1cde
18 changed files with 88 additions and 94 deletions

View File

@ -18,6 +18,13 @@ repos:
args: [requirements.txt, test-requirements.txt, extra-requirements.txt, linters-requirements.txt, doc/requirements.txt, infrared_plugin/requirements.txt]
- id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8
rev: '3.8.3' # pick a git hash / tag to point to
hooks:
- id: flake8
additional_dependencies: [flake8-import-order]
files: ^tobiko/
# - repo: https://github.com/adrienverge/yamllint.git
# rev: v1.23.0
# hooks:

View File

@ -16,7 +16,6 @@ from __future__ import absolute_import
import logging
from oslo_log import log
import testtools
from testtools import content

View File

@ -18,10 +18,10 @@ import os
import sys
from oslo_log import log
import testtools
import yaml
import tobiko
import testtools
LOG = log.getLogger(__name__)

View File

@ -14,7 +14,6 @@
from __future__ import absolute_import
import tobiko
from tobiko.openstack.neutron import _client

View File

@ -16,7 +16,6 @@ from __future__ import absolute_import
import collections
import tobiko
from tobiko.openstack.neutron import _client

View File

@ -15,11 +15,8 @@
# under the License.
from __future__ import absolute_import
import six
import podman
import tobiko
from tobiko.podman import _exception
from tobiko.podman import _shell
@ -56,9 +53,6 @@ class PodmanClientFixture(tobiko.SharedFixture):
ssh_client = None
def __init__(self, ssh_client=None):
if six.PY2:
raise _exception.PodmanError(
"Podman isn't compatible with python 2.7")
super(PodmanClientFixture, self).__init__()
if ssh_client:
self.ssh_client = ssh_client

View File

@ -19,7 +19,6 @@ import io
import select
from oslo_log import log
import six
LOG = log.getLogger(__name__)

View File

@ -21,7 +21,6 @@ import time
from oslo_log import log
import tobiko
from tobiko.shell.sh import _command
from tobiko.shell.sh import _exception
from tobiko.shell.sh import _io

View File

@ -16,7 +16,6 @@
from __future__ import absolute_import
import collections
import getpass
import os
import socket

View File

@ -16,9 +16,8 @@ from __future__ import absolute_import
import time
import testtools
from oslo_log import log
import testtools
import tobiko
from tobiko.openstack import neutron
@ -28,6 +27,7 @@ from tobiko.openstack import topology
from tobiko.shell import ping
from tobiko.shell import sh
LOG = log.getLogger(__name__)

View File

@ -3,6 +3,8 @@ from __future__ import absolute_import
import re
from oslo_log import log
import tobiko
from tobiko.shell import sh
from tobiko.openstack import topology
@ -11,7 +13,6 @@ from tobiko.openstack import keystone
from tobiko.tripleo import pacemaker
from tobiko.tripleo import containers
from tobiko.tripleo import nova
from oslo_log import log
from tobiko.tests.faults.ha import test_cloud_recovery

View File

@ -15,10 +15,9 @@
# under the License.
from __future__ import absolute_import
import testtools
from docker import client as docker_client
from docker.models import containers
import testtools
import tobiko
from tobiko import docker

View File

@ -14,8 +14,9 @@
# under the License.
from __future__ import absolute_import
import tobiko
import testtools
import tobiko
from tobiko.openstack import stacks
from tobiko.openstack import neutron
from tobiko.openstack import nova

View File

@ -13,9 +13,8 @@
# under the License.
from __future__ import absolute_import
import yaml
import testtools
import yaml
from tobiko.openstack import nova

View File

@ -15,23 +15,11 @@ from __future__ import absolute_import
import mock
import six
from tobiko import podman
from tobiko.tests import unit
# We need to ignore this code under py2
# it's not compatible and parser will failed even if we use
# the `unittest.skipIf` decorator, because during the test discovery
# stestr and unittest will load this test
# module before running it and it will load podman
# too which isn't compatible in version leather than python 3
# Also the varlink mock module isn't compatible with py27, is using
# annotations syntaxe to generate varlink interface for the mocked service
# and it will raise related exceptions too.
# For all these reasons we can't run podman tests under a python 2 environment
if six.PY3:
from tobiko import podman
from tobiko.tests import unit
class TestShell(unit.TobikoUnitTest):
class TestShell(unit.TobikoUnitTest):
@mock.patch('tobiko.shell.sh.execute')
def test_discover_podman_socket(self, mock_execute):

View File

@ -15,9 +15,10 @@ from __future__ import absolute_import
import sys
import testtools
import tobiko
from tobiko.tests import unit
import testtools
class SomeException(tobiko.TobikoException):

View File

@ -1,7 +1,19 @@
# Copyright 2020 Red Hat
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import
from oslo_log import log
from validations_libs import validation_actions
from validations_libs import constants as v_consts

12
tox.ini
View File

@ -76,7 +76,7 @@ deps =
{[testenv]deps}
-r{toxinidir}/linters-requirements.txt
commands =
flake8 --max-complexity 10
pre-commit run -a flake8
[testenv:pylint]
@ -95,11 +95,8 @@ whitelist_externals = bash
deps = {[testenv:pep8]deps}
envdir = {toxworkdir}/pep8
commands =
pre-commit --version
pre-commit autoupdate
pre-commit run --all-files
pre-commit run -a
pre-commit install
{[testenv:pep8]commands}
mypy --ignore-missing-imports tobiko/
# Ansible lint
# [ANSIBLE0012] Commands should not change things if nothing needs doing
@ -120,10 +117,11 @@ commands =
enable-extensions = H106,H203,H204,H205,H904
show-source = true
exclude = ./.*,*lib/python*,build,dist,doc,*egg*,releasenotes,.venv
exclude = ./.*,*lib/python*,build,dist,doc,*egg*,releasenotes,.venv,.tox
application-import-names = tobiko
max-complexity = 10
import-order-style = pep8
# --- integration test environments ------------------------------------------
[integration]