[damned-lies/develop] chore: strict use of flake8
- From: Guillaume Bernard <gbernard src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies/develop] chore: strict use of flake8
- Date: Mon, 10 Oct 2022 09:29:37 +0000 (UTC)
commit f131fbbb096c8eb65efd76c3dfae3fb146a732e5
Author: Guillaume Bernard <associations guillaume-bernard fr>
Date: Mon Oct 10 11:15:13 2022 +0200
chore: strict use of flake8
.flake8 | 4 ++++
.gitlab-ci.yml | 1 +
.pre-commit-config.yaml | 5 +++++
common/tests.py | 1 -
people/tests.py | 2 +-
stats/models.py | 2 +-
stats/utils.py | 10 +++++-----
7 files changed, 17 insertions(+), 8 deletions(-)
---
diff --git a/.flake8 b/.flake8
index 64c5d0b2..7f8ef48b 100644
--- a/.flake8
+++ b/.flake8
@@ -6,6 +6,10 @@ extend-ignore =
W504
# MacCabe complexity is computed by prospector
C901
+ # See https://github.com/PyCQA/pycodestyle/issues/373
+ E203
+ # Line too long (this is managed by black)
+ E501
exclude =
# Cache and project files
.git,
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 9e026735..7c98d723 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -218,6 +218,7 @@ static-analysis:flake8:
image: python:alpine
extends:
- .static-analysis
+ allow_failure: false
before_script:
- pip install flake8
script:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 9848560d..90019e25 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -26,3 +26,8 @@ repos:
- id: djjs
# Exclude JavaScript files in vendor directories
exclude: .*/vendor/.*
+
+ - repo: https://github.com/pycqa/flake8
+ rev: '5.0.4'
+ hooks:
+ - id: flake8
diff --git a/common/tests.py b/common/tests.py
index 203d4cb8..ea353584 100644
--- a/common/tests.py
+++ b/common/tests.py
@@ -1,6 +1,5 @@
import operator
from datetime import timedelta
-from pathlib import Path
from unittest import TestCase, skipUnless
from unittest.mock import MagicMock, patch
diff --git a/people/tests.py b/people/tests.py
index f29552c7..41e2ef29 100644
--- a/people/tests.py
+++ b/people/tests.py
@@ -5,7 +5,7 @@ from django.contrib import auth
from django.contrib.staticfiles.finders import find
from django.core import mail
from django.core.exceptions import ValidationError
-from django.test import Client, TestCase, override_settings
+from django.test import Client, TestCase
from django.urls import reverse
from django.utils import timezone
from django.utils.safestring import SafeData
diff --git a/stats/models.py b/stats/models.py
index 5ae98d83..b6daa15d 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -2146,7 +2146,7 @@ class Information(models.Model):
link = self.statistics.branch.module.get_bugs_enter_url()
link += "&short_desc=%(short)s&content=%(short)s&comment=%(long)s" % {
"short": "Error regenerating POT file",
- "long": utils.ellipsize(utils.stripHTML(self.get_description()), 1600),
+ "long": utils.ellipsize(utils.strip_html(self.get_description()), 1600),
}
return link
diff --git a/stats/utils.py b/stats/utils.py
index ec6acfa4..296b8184 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -60,7 +60,7 @@ class DocFormat:
self.makefile = MakefileWrapper.find_file(branch, [self.vcs_path])
if self.makefile is None:
raise UndetectableDocFormat(gettext_noop("Unable to find a makefile for module %s") %
branch.module.name)
- has_page_files = any(f.suffix == ".page" for f in self.list_C_files())
+ has_page_files = any(f.suffix == ".page" for f in self.list_c_files())
self.format = "mallard" if has_page_files else "docbook"
self.tool = "itstool"
@@ -71,7 +71,7 @@ class DocFormat:
def use_meson(self):
return isinstance(self.makefile, MesonfileWrapper)
- def list_C_files(self):
+ def list_c_files(self):
return [p.relative_to(self.vcs_path) for p in (self.vcs_path / "C").iterdir() if p.is_file()]
def source_files(self):
@@ -88,7 +88,7 @@ class DocFormat:
break
if not sources:
# Last try: only one xml/docbook file in C/...
- xml_files = [f for f in self.list_C_files() if f.suffix in (".xml", ".docbook")]
+ xml_files = [f for f in self.list_c_files() if f.suffix in (".xml", ".docbook")]
if len(xml_files) == 1:
sources.append(xml_files[0].name)
else:
@@ -98,7 +98,7 @@ class DocFormat:
if not source_list:
suffix = [".page"] if self.format == "mallard" else [".xml", ".docbook"]
# Fallback to directory listing
- return [f for f in self.list_C_files() if f.suffix in suffix]
+ return [f for f in self.list_c_files() if f.suffix in suffix]
if isinstance(source_list, str):
sources += source_list.split()
elif source_list:
@@ -339,7 +339,7 @@ def multiple_replace(dct, text):
return regex.sub(lambda mo: dct[mo.string[mo.start() : mo.end()]], text)
-def stripHTML(string):
+def strip_html(string):
replacements = {"<ul>": "\n", "</ul>": "\n", "<li>": " * ", "\n</li>": "", "</li>": ""}
return multiple_replace(replacements, string)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]