From ce95fde8bc607468aacedd5a45f7c3f71f7f8c4d Mon Sep 17 00:00:00 2001 From: "Matt.Wang" Date: Mon, 21 Feb 2022 22:34:26 +0800 Subject: [PATCH 1/3] deps: add flake8 --- poetry.lock | 92 +++++++++++++++++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/poetry.lock b/poetry.lock index 718b6df..dc156c6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -29,6 +29,60 @@ asgiref = ">=3.3.2,<4" argon2 = ["argon2-cffi (>=19.1.0)"] bcrypt = ["bcrypt"] +[[package]] +name = "flake8" +version = "4.0.1" +description = "the modular source code checker: pep8 pyflakes and co" +category = "main" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +importlib-metadata = {version = "<4.3", markers = "python_version < \"3.8\""} +mccabe = ">=0.6.0,<0.7.0" +pycodestyle = ">=2.8.0,<2.9.0" +pyflakes = ">=2.4.0,<2.5.0" + +[[package]] +name = "importlib-metadata" +version = "4.2.0" +description = "Read metadata from Python packages" +category = "main" +optional = false +python-versions = ">=3.6" + +[package.dependencies] +typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} +zipp = ">=0.5" + +[package.extras] +docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] +testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"] + +[[package]] +name = "mccabe" +version = "0.6.1" +description = "McCabe checker, plugin for flake8" +category = "main" +optional = false +python-versions = "*" + +[[package]] +name = "pycodestyle" +version = "2.8.0" +description = "Python style guide checker" +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" + +[[package]] +name = "pyflakes" +version = "2.4.0" +description = "passive checker of Python programs" +category = "main" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + [[package]] name = "pytz" version = "2021.3" @@ -53,10 +107,22 @@ category = "main" optional = false python-versions = ">=3.6" +[[package]] +name = "zipp" +version = "3.6.0" +description = "Backport of pathlib-compatible object wrapper for zip files" +category = "main" +optional = false +python-versions = ">=3.6" + +[package.extras] +docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] +testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"] + [metadata] lock-version = "1.1" python-versions = "^3.6" -content-hash = "5401953f6d311a657ea92d8efeee6758312057278992d69b0f63a9bbc1f71a7c" +content-hash = "ec478b870e5c4dc7c0dc6d68918fca8ba71ddc4a5708a2f8c11725a875bba7f6" [metadata.files] asgiref = [ @@ -67,6 +133,26 @@ django = [ {file = "Django-3.2.12-py3-none-any.whl", hash = "sha256:9b06c289f9ba3a8abea16c9c9505f25107809fb933676f6c891ded270039d965"}, {file = "Django-3.2.12.tar.gz", hash = "sha256:9772e6935703e59e993960832d66a614cf0233a1c5123bc6224ecc6ad69e41e2"}, ] +flake8 = [ + {file = "flake8-4.0.1-py2.py3-none-any.whl", hash = "sha256:479b1304f72536a55948cb40a32dce8bb0ffe3501e26eaf292c7e60eb5e0428d"}, + {file = "flake8-4.0.1.tar.gz", hash = "sha256:806e034dda44114815e23c16ef92f95c91e4c71100ff52813adf7132a6ad870d"}, +] +importlib-metadata = [ + {file = "importlib_metadata-4.2.0-py3-none-any.whl", hash = "sha256:057e92c15bc8d9e8109738a48db0ccb31b4d9d5cfbee5a8670879a30be66304b"}, + {file = "importlib_metadata-4.2.0.tar.gz", hash = "sha256:b7e52a1f8dec14a75ea73e0891f3060099ca1d8e6a462a4dff11c3e119ea1b31"}, +] +mccabe = [ + {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, + {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, +] +pycodestyle = [ + {file = "pycodestyle-2.8.0-py2.py3-none-any.whl", hash = "sha256:720f8b39dde8b293825e7ff02c475f3077124006db4f440dcbc9a20b76548a20"}, + {file = "pycodestyle-2.8.0.tar.gz", hash = "sha256:eddd5847ef438ea1c7870ca7eb78a9d47ce0cdb4851a5523949f2601d0cbbe7f"}, +] +pyflakes = [ + {file = "pyflakes-2.4.0-py2.py3-none-any.whl", hash = "sha256:3bb3a3f256f4b7968c9c788781e4ff07dce46bdf12339dcda61053375426ee2e"}, + {file = "pyflakes-2.4.0.tar.gz", hash = "sha256:05a85c2872edf37a4ed30b0cce2f6093e1d0581f8c19d7393122da7e25b2b24c"}, +] pytz = [ {file = "pytz-2021.3-py2.py3-none-any.whl", hash = "sha256:3672058bc3453457b622aab7a1c3bfd5ab0bdae451512f6cf25f64ed37f5b87c"}, {file = "pytz-2021.3.tar.gz", hash = "sha256:acad2d8b20a1af07d4e4c9d2e9285c5ed9104354062f275f3fcd88dcef4f1326"}, @@ -79,3 +165,7 @@ typing-extensions = [ {file = "typing_extensions-4.1.1-py3-none-any.whl", hash = "sha256:21c85e0fe4b9a155d0799430b0ad741cdce7e359660ccbd8b530613e8df88ce2"}, {file = "typing_extensions-4.1.1.tar.gz", hash = "sha256:1a9462dcc3347a79b1f1c0271fbe79e844580bb598bafa1ed208b94da3cdcd42"}, ] +zipp = [ + {file = "zipp-3.6.0-py3-none-any.whl", hash = "sha256:9fe5ea21568a0a70e50f273397638d39b03353731e6cbbb3fd8502a33fec40bc"}, + {file = "zipp-3.6.0.tar.gz", hash = "sha256:71c644c5369f4a6e07636f0aa966270449561fcea2e3d6747b8d23efaa9d7832"}, +] diff --git a/pyproject.toml b/pyproject.toml index 680ba61..dba72a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ python = "^3.6" Django = "^3" [tool.poetry.dev-dependencies] +flake8 = "^4.0.1" [build-system] requires = ["poetry-core>=1.0.0"] From 9212de0b872caf7c239529025a488ff7ff219659 Mon Sep 17 00:00:00 2001 From: "Matt.Wang" Date: Mon, 21 Feb 2022 22:35:55 +0800 Subject: [PATCH 2/3] chore: add flake8 config and fix coding style based on flake8 warnings --- .flake8 | 3 +++ registry/admin.py | 2 +- registry/helper.py | 1 + registry/models.py | 2 -- registry/tests.py | 2 +- registry/views.py | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..b29b1a1 --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +max_line_length = 120 +exclude = .git,__pycache__,setup.py,registry/migrations diff --git a/registry/admin.py b/registry/admin.py index 0af897c..0dab77d 100644 --- a/registry/admin.py +++ b/registry/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from .models import Entry -# Register your models here. + @admin.register(Entry) class EntryAdmin(admin.ModelAdmin): list_display = ('key', 'value', 'type', 'enabled', 'comment', ) diff --git a/registry/helper.py b/registry/helper.py index 6be6aef..1a05a51 100644 --- a/registry/helper.py +++ b/registry/helper.py @@ -1,5 +1,6 @@ from .models import Entry + class Meta(type): def __getitem__(self, key): try: diff --git a/registry/models.py b/registry/models.py index 6080a56..2bfb581 100644 --- a/registry/models.py +++ b/registry/models.py @@ -3,7 +3,6 @@ from django.utils.translation import gettext_lazy as _ -# Create your models here. class Entry(models.Model): class Types: STRING = 'str' @@ -46,6 +45,5 @@ def clean(self): except ValueError: raise ValidationError({'value': _('Invalid value of the specified type.')}) - class Meta: verbose_name_plural = 'entries' diff --git a/registry/tests.py b/registry/tests.py index 7ce503c..a79ca8b 100644 --- a/registry/tests.py +++ b/registry/tests.py @@ -1,3 +1,3 @@ -from django.test import TestCase +# from django.test import TestCase # Create your tests here. diff --git a/registry/views.py b/registry/views.py index 91ea44a..fd0e044 100644 --- a/registry/views.py +++ b/registry/views.py @@ -1,3 +1,3 @@ -from django.shortcuts import render +# from django.shortcuts import render # Create your views here. From 539c6892e9c0af252e8293be432ec0c18cad8916 Mon Sep 17 00:00:00 2001 From: "Matt.Wang" Date: Mon, 21 Feb 2022 22:47:41 +0800 Subject: [PATCH 3/3] ci: add flake8 checking in CI action --- .github/workflows/ci.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e16de4e..ff3037d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,3 +34,6 @@ jobs: - name: Install project dependencies run: poetry install + + - name: Run flake8 + run: poetry run flake8