Browse Source

Fix flake8 failures and make its execution more consistent

- upgrade flake8 to 3.6.0
- remove use of hacking since pre-commit replaced it
- mentioned minimal flake8 version on pre-commit config
- fixed newer linting errors
- disable W504 as it seems not possible to fix (conflict with W403)
- replaced buggy tox deps installation with native pip install, which
  address the issue of missing to install new deps when the reqs files
  are updated, developer being forced to to recreate the virtualenv.
- prepare for migration from tox-pep8 to tox-linters, now these being
  just aliases.

Change-Id: I310578dce215aaf00a5b2d54716f90da9a1ecb4d
Depends-On: https://review.openstack.org/#/c/613726/
Sorin Sbarnea 6 months ago
parent
commit
539d13e816

+ 4
- 1
.pre-commit-config.yaml View File

@@ -2,10 +2,13 @@
2 2
 # See https://pre-commit.com/hooks.html for more hooks
3 3
 repos:
4 4
 -   repo: https://github.com/pre-commit/pre-commit-hooks
5
-    rev: v1.2.1-1
5
+    rev: v2.0.0
6 6
     hooks:
7 7
     -   id: check-added-large-files
8 8
     -   id: end-of-file-fixer
9 9
     -   id: flake8
10 10
         args: ['--config=setup.cfg']
11
+        language: python
12
+        types: [python]
13
+        additional_dependencies: [flake8>=3.6.0]
11 14
     -   id: trailing-whitespace

+ 3
- 3
jenkins_jobs/alphanum.py View File

@@ -32,9 +32,9 @@ sorted( foo, key=AlphanumSort)
32 32
 import re
33 33
 
34 34
 
35
-re_chunk = re.compile("([\D]+|[\d]+)")
36
-re_letters = re.compile("\D+")
37
-re_numbers = re.compile("\d+")
35
+re_chunk = re.compile(r"([\D]+|[\d]+)")
36
+re_letters = re.compile(r"\D+")
37
+re_numbers = re.compile(r"\d+")
38 38
 
39 39
 
40 40
 def getchunk(item):

+ 1
- 1
jenkins_jobs/cache.py View File

@@ -43,7 +43,7 @@ class JobCache(object):
43 43
     def __init__(self, jenkins_url, flush=False):
44 44
         cache_dir = self.get_cache_dir()
45 45
         # One cache per remote Jenkins URL:
46
-        host_vary = re.sub('[^A-Za-z0-9\-\~]', '_', jenkins_url)
46
+        host_vary = re.sub(r'[^A-Za-z0-9\-\~]', '_', jenkins_url)
47 47
         self.cachefilename = os.path.join(
48 48
             cache_dir, 'cache-host-jobs-' + host_vary + '.yml')
49 49
 

+ 1
- 1
jenkins_jobs/formatter.py View File

@@ -81,7 +81,7 @@ class CustomFormatter(Formatter):
81 81
     Custom formatter to allow non-existing key references when formatting a
82 82
     string
83 83
     """
84
-    _expr = """
84
+    _expr = r"""
85 85
         (?<!{){({{)*                # non-pair opening {
86 86
         (?:obj:)?                   # obj:
87 87
         (?P<key>\w+)                # key

+ 9
- 9
jenkins_jobs/modules/builders.py View File

@@ -2888,7 +2888,7 @@ def cmake(registry, xml_parent, data):
2888 2888
 
2889 2889
 
2890 2890
 def dsl(registry, xml_parent, data):
2891
-    """yaml: dsl
2891
+    r"""yaml: dsl
2892 2892
     Process Job DSL
2893 2893
 
2894 2894
     Requires the Jenkins :jenkins-wiki:`Job DSL plugin <Job+DSL+Plugin>`.
@@ -3475,7 +3475,7 @@ def jms_messaging(registry, xml_parent, data):
3475 3475
 
3476 3476
 
3477 3477
 def openshift_build_verify(registry, xml_parent, data):
3478
-    """yaml: openshift-build-verify
3478
+    r"""yaml: openshift-build-verify
3479 3479
     Performs the equivalent of an 'oc get builds` command invocation for the
3480 3480
     provided buildConfig key provided; once the list of builds are obtained,
3481 3481
     the state of the latest build is inspected for up to a minute to see if
@@ -3524,7 +3524,7 @@ def openshift_build_verify(registry, xml_parent, data):
3524 3524
 
3525 3525
 
3526 3526
 def openshift_builder(registry, xml_parent, data):
3527
-    """yaml: openshift-builder
3527
+    r"""yaml: openshift-builder
3528 3528
     Perform builds in OpenShift for the job.
3529 3529
     Requires the Jenkins :jenkins-wiki:`OpenShift
3530 3530
     Pipeline Plugin <OpenShift+Pipeline+Plugin>`.
@@ -3580,7 +3580,7 @@ def openshift_builder(registry, xml_parent, data):
3580 3580
 
3581 3581
 
3582 3582
 def openshift_creator(registry, xml_parent, data):
3583
-    """yaml: openshift-creator
3583
+    r"""yaml: openshift-creator
3584 3584
     Performs the equivalent of an oc create command invocation;
3585 3585
     this build step takes in the provided JSON or YAML text, and if it
3586 3586
     conforms to OpenShift schema, creates whichever
@@ -3628,7 +3628,7 @@ def openshift_creator(registry, xml_parent, data):
3628 3628
 
3629 3629
 
3630 3630
 def openshift_dep_verify(registry, xml_parent, data):
3631
-    """yaml: openshift-dep-verify
3631
+    r"""yaml: openshift-dep-verify
3632 3632
     Determines whether the expected set of DeploymentConfig's,
3633 3633
     ReplicationController's, and active replicas are present based on prior
3634 3634
     use of the scaler (2) and deployer (3) steps
@@ -3679,7 +3679,7 @@ def openshift_dep_verify(registry, xml_parent, data):
3679 3679
 
3680 3680
 
3681 3681
 def openshift_deployer(registry, xml_parent, data):
3682
-    """yaml: openshift-deployer
3682
+    r"""yaml: openshift-deployer
3683 3683
     Start a deployment in OpenShift for the job.
3684 3684
     Requires the Jenkins :jenkins-wiki:`OpenShift
3685 3685
     Pipeline Plugin <OpenShift+Pipeline+Plugin>`.
@@ -3725,7 +3725,7 @@ def openshift_deployer(registry, xml_parent, data):
3725 3725
 
3726 3726
 
3727 3727
 def openshift_img_tagger(registry, xml_parent, data):
3728
-    """yaml: openshift-img-tagger
3728
+    r"""yaml: openshift-img-tagger
3729 3729
     Performs the equivalent of an oc tag command invocation in order to
3730 3730
     manipulate tags for images in OpenShift ImageStream's
3731 3731
     Requires the Jenkins :jenkins-wiki:`OpenShift
@@ -3776,7 +3776,7 @@ def openshift_img_tagger(registry, xml_parent, data):
3776 3776
 
3777 3777
 
3778 3778
 def openshift_scaler(registry, xml_parent, data):
3779
-    """yaml: openshift-scaler
3779
+    r"""yaml: openshift-scaler
3780 3780
     Scale deployments in OpenShift for the job.
3781 3781
     Requires the Jenkins :jenkins-wiki:`OpenShift
3782 3782
     Pipeline Plugin <OpenShift+Pipeline+Plugin>`.
@@ -3823,7 +3823,7 @@ def openshift_scaler(registry, xml_parent, data):
3823 3823
 
3824 3824
 
3825 3825
 def openshift_svc_verify(registry, xml_parent, data):
3826
-    """yaml: openshift-svc-verify
3826
+    r"""yaml: openshift-svc-verify
3827 3827
     Verify a service is up in OpenShift for the job.
3828 3828
     Requires the Jenkins :jenkins-wiki:`OpenShift
3829 3829
     Pipeline Plugin <OpenShift+Pipeline+Plugin>`.

+ 3
- 3
jenkins_jobs/modules/project_multibranch.py View File

@@ -290,7 +290,7 @@ class WorkflowMultiBranchDefaults(WorkflowMultiBranch):
290 290
 
291 291
 
292 292
 def bitbucket_scm(xml_parent, data):
293
-    """Configure BitBucket scm
293
+    r"""Configure BitBucket scm
294 294
 
295 295
     Requires the :jenkins-wiki:`Bitbucket Branch Source Plugin
296 296
     <Bitbucket+Branch+Source+Plugin>`.
@@ -626,7 +626,7 @@ def gerrit_scm(xml_parent, data):
626 626
 
627 627
 
628 628
 def git_scm(xml_parent, data):
629
-    """Configure Git SCM
629
+    r"""Configure Git SCM
630 630
 
631 631
     Requires the :jenkins-wiki:`Git Plugin <Git+Plugin>`.
632 632
 
@@ -738,7 +738,7 @@ def git_scm(xml_parent, data):
738 738
 
739 739
 
740 740
 def github_scm(xml_parent, data):
741
-    """Configure GitHub SCM
741
+    r"""Configure GitHub SCM
742 742
 
743 743
     Requires the :jenkins-wiki:`GitHub Branch Source Plugin
744 744
     <GitHub+Branch+Source+Plugin>`.

+ 5
- 5
jenkins_jobs/modules/publishers.py View File

@@ -1658,7 +1658,7 @@ def violations(registry, xml_parent, data):
1658 1658
 
1659 1659
 
1660 1660
 def findbugs(registry, xml_parent, data):
1661
-    """yaml: findbugs
1661
+    r"""yaml: findbugs
1662 1662
     FindBugs reporting for builds
1663 1663
 
1664 1664
     Requires the Jenkins :jenkins-wiki:`FindBugs Plugin
@@ -2962,7 +2962,7 @@ def sounds(parser, xml_parent, data):
2962 2962
 
2963 2963
 
2964 2964
 def performance(registry, xml_parent, data):
2965
-    """yaml: performance
2965
+    r"""yaml: performance
2966 2966
     Publish performance test results from jmeter and junit.
2967 2967
     Requires the Jenkins :jenkins-wiki:`Performance Plugin
2968 2968
     <Performance+Plugin>`.
@@ -4391,7 +4391,7 @@ def warnings(registry, xml_parent, data):
4391 4391
 
4392 4392
 
4393 4393
 def sloccount(registry, xml_parent, data):
4394
-    """yaml: sloccount
4394
+    r"""yaml: sloccount
4395 4395
     Generates the trend report for SLOCCount
4396 4396
 
4397 4397
     Requires the Jenkins :jenkins-wiki:`SLOCCount Plugin <SLOCCount+Plugin>`.
@@ -7220,7 +7220,7 @@ def jms_messaging(registry, xml_parent, data):
7220 7220
 
7221 7221
 
7222 7222
 def openshift_build_canceller(registry, xml_parent, data):
7223
-    """yaml: openshift-build-canceller
7223
+    r"""yaml: openshift-build-canceller
7224 7224
     This action is intended to provide cleanup for a Jenkins job which failed
7225 7225
     because a build is hung (instead of terminating with a failure code);
7226 7226
     this step will allow you to perform the equivalent of a oc cancel-build
@@ -7271,7 +7271,7 @@ def openshift_build_canceller(registry, xml_parent, data):
7271 7271
 
7272 7272
 
7273 7273
 def openshift_deploy_canceller(registry, xml_parent, data):
7274
-    """yaml: openshift-deploy-canceller
7274
+    r"""yaml: openshift-deploy-canceller
7275 7275
     This action is intended to provide cleanup for any OpenShift deployments
7276 7276
     left running when the Job completes; this step will allow you to perform
7277 7277
     the equivalent of a oc deploy --cancel for the provided deployment config.

+ 3
- 3
jenkins_jobs/modules/scm.py View File

@@ -46,7 +46,7 @@ import jenkins_jobs.modules.helpers as helpers
46 46
 
47 47
 
48 48
 def git(registry, xml_parent, data):
49
-    """yaml: git
49
+    r"""yaml: git
50 50
     Specifies the git SCM repository for this job.
51 51
     Requires the Jenkins :jenkins-wiki:`Git Plugin <Git+Plugin>`.
52 52
 
@@ -994,7 +994,7 @@ def svn(registry, xml_parent, data):
994 994
 
995 995
 
996 996
 def tfs(registry, xml_parent, data):
997
-    """yaml: tfs
997
+    r"""yaml: tfs
998 998
     Specifies the Team Foundation Server repository for this job.
999 999
     Requires the Jenkins :jenkins-wiki:`Team Foundation Server Plugin
1000 1000
     <Team+Foundation+Server+Plugin>`.
@@ -1216,7 +1216,7 @@ def hg(self, xml_parent, data):
1216 1216
 
1217 1217
 
1218 1218
 def openshift_img_streams(registry, xml_parent, data):
1219
-    """yaml: openshift-img-streams
1219
+    r"""yaml: openshift-img-streams
1220 1220
     Rather than a Build step extension plugin, this is an extension of the
1221 1221
     Jenkins SCM plugin, where this baked-in polling mechanism provided by
1222 1222
     Jenkins is leveraged by exposing some of the common semantics between

+ 1
- 1
jenkins_jobs/sphinx/yaml.py View File

@@ -29,7 +29,7 @@ from sphinx.ext.autodoc import FunctionDocumenter
29 29
 from sphinx.locale import _
30 30
 
31 31
 
32
-yaml_sig_re = re.compile('yaml:\s*(.*)')
32
+yaml_sig_re = re.compile(r'yaml:\s*(.*)')
33 33
 
34 34
 
35 35
 class PyYAMLFunction(PyModulelevel):

+ 3
- 1
setup.cfg View File

@@ -101,6 +101,8 @@ jenkins_jobs.modules =
101 101
 [flake8]
102 102
 # These are ignored intentionally in openstack-infra projects; please
103 103
 # don't submit patches that solely correct them or enable them.
104
-ignore = E125,E128,H
104
+# W504 is controversial an apparently conflicting with W503, being impossible
105
+# to solve both of them while still keeping the line length limited.
106
+ignore = E125,E128,H,W504
105 107
 show-source = True
106 108
 exclude = .virtualenv,.venv,.tox,dist,build,*.egg,.test

+ 1
- 2
test-requirements.txt View File

@@ -1,7 +1,6 @@
1 1
 # The order of packages is significant, because pip processes them in the order
2 2
 # of appearance. Changing the order has an impact on the overall integration
3 3
 # process, which may cause wedges in the gate later.
4
-hacking>=1.1.0 # Apache-2.0
5 4
 
6 5
 coverage>=4.0 # Apache-2.0
7 6
 fixtures>=3.0.0 # Apache-2.0/BSD
@@ -13,4 +12,4 @@ stestr>=2.0.0 # Apache-2.0/BSD
13 12
 tox>=2.9.1 # MIT
14 13
 mock>=2.0 # BSD
15 14
 sphinxcontrib-programoutput
16
-pre-commit
15
+pre-commit>=1.12.0

+ 16
- 5
tox.ini View File

@@ -1,7 +1,9 @@
1 1
 [tox]
2 2
 minversion = 2.2
3
-envlist = docs, pep8, py34, py35, py36, py27, cover
3
+envlist = linters, docs, py34, py35, py36, py27, cover
4 4
 skip_missing_interpreters = true
5
+# custom vars (no meaning to tox)
6
+install_test_deps = pip install -q -r test-requirements.txt
5 7
 
6 8
 [testenv]
7 9
 setenv =
@@ -11,11 +13,11 @@ setenv =
11 13
          VIRTUAL_ENV={envdir}
12 14
 usedevelop = True
13 15
 install_command = pip install {opts} {packages}
14
-deps = -r{toxinidir}/test-requirements.txt
15 16
 # cleanup is needed mostly for dev environmnts and assures that if  dev
16 17
 # is switching branch, no lefovers will impact execution.
17 18
 # No git commands here because test should run even from a source archive.
18 19
 commands =
20
+    {[tox]install_test_deps}
19 21
     - find . -type f -name "*.pyc" -delete
20 22
     - find . -type d -name "__pycache__" -delete
21 23
     # test that we can call jjb using both variants with same results
@@ -39,15 +41,22 @@ setenv =
39 41
     {[testenv]setenv}
40 42
     PYTHON=coverage run --source jenkins_jobs --parallel-mode
41 43
 commands =
44
+    {[tox]install_test_deps}
42 45
     stestr run {posargs}
43 46
     coverage combine
44 47
     coverage html -d cover
45 48
     coverage xml -o cover/coverage.xml
46 49
 
47
-[testenv:pep8]
50
+[testenv:linters]
48 51
 basepython = python3
49 52
 commands =
50
-   python -m pre_commit run --all
53
+    {[tox]install_test_deps}
54
+    python -m pre_commit run --all
55
+
56
+# points to linters, kept only for developer convenience
57
+[testenv:pep8]
58
+envdir={toxworkdir}/linters
59
+commands = {[testenv:linters]commands}
51 60
 
52 61
 [testenv:pyflakes]
53 62
 deps = pyflakes
@@ -63,7 +72,9 @@ commands = jenkins-jobs test -o .test/old/out/ .test/old/config/
63 72
 commands = jenkins-jobs test -o .test/new/out/ .test/new/config/
64 73
 
65 74
 [testenv:docs]
66
-commands = python setup.py build_sphinx {posargs}
75
+commands =
76
+    {[tox]install_test_deps}
77
+    python setup.py build_sphinx {posargs}
67 78
 
68 79
 [testenv:docs-linkcheck]
69 80
 # If you are behind a proxy, for this test to work you will need to set

Loading…
Cancel
Save