Browse Source

pipeline: run pylint

Fabian Peter Hammerle 2 weeks ago
parent
commit
b3b0c1cf59
5 changed files with 85 additions and 14 deletions
  1. 3 0
      .github/workflows/python.yml
  2. 3 4
      Pipfile
  3. 71 3
      Pipfile.lock
  4. 4 2
      acpi_backlight/__init__.py
  5. 4 5
      acpi_backlight/evaluate.py

+ 3 - 0
.github/workflows/python.yml

@@ -49,6 +49,9 @@ jobs:
         PYTHON_VERSION: ${{ matrix.python-version }}
     - run: pipenv graph
     - run: pipenv run pytest --cov=acpi_backlight --cov-report=term-missing --cov-fail-under=64
+    - run: pipenv run pylint --load-plugins=pylint_import_requirements acpi_backlight
+    # https://github.com/PyCQA/pylint/issues/352
+    - run: pipenv run pylint tests/*
     - run: pipenv run mypy acpi_backlight tests
     # >=1.9.0 to detect branch name
     # https://github.com/coveralls-clients/coveralls-python/pull/207

+ 3 - 4
Pipfile

@@ -11,19 +11,18 @@ acpi-backlight = {editable = true, path = "."}
 # https://github.com/psf/black/commit/e74117f172e29e8a980e2c9de929ad50d3769150#diff-2eeaed663bd0d25b7e608891384b7298R51
 black = {version = "==20.8b1", markers = "python_version >= '3.6'"}
 mypy = "*"
+pylint = "*"
+pylint-import-requirements = "*"
 pytest = "*"
 pytest-cov = "*"
 
 # python3.5 compatibility
+isort = "<5"
 # workaround https://github.com/pytest-dev/pytest/issues/3953
 pathlib2 = {version = "*", markers="python_version < '3.6'"}
 # https://github.com/jaraco/zipp/commit/05a3c52b4d41690e0471a2e283cffb500dc0329a
 zipp = "<2"
 
-# python<3.8 compatibility
-# workaround https://github.com/pytest-dev/pytest/issues/7273
-importlib_metadata = {markers = "python_version < '3.8'"}
-
 [requires]
 python_version = "3"
 

+ 71 - 3
Pipfile.lock

@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "6a8848331caf2e96c42a7f12649018df4347fb022a536382ccaf48a6904d21b7"
+            "sha256": "d28f4118d88e4a515756cfa9768faaef7dfcb3ec7fc2c98ae70dc643776c7c81"
         },
         "pipfile-spec": 6,
         "requires": {
@@ -29,6 +29,13 @@
             ],
             "version": "==1.4.4"
         },
+        "astroid": {
+            "hashes": [
+                "sha256:2f4078c2a41bf377eea06d71c9d2ba4eb8f6b1af2135bec27bbbb7d8f12bb703",
+                "sha256:bc58d83eb610252fd8de6363e39d4f1d0619c894b0ed24603b881c02e64c7386"
+            ],
+            "version": "==2.4.2"
+        },
         "attrs": {
             "hashes": [
                 "sha256:26b54ddbbb9ee1d34d5d3668dd37d6cf74990ab23c828c2888dccdceee395594",
@@ -95,8 +102,6 @@
                 "sha256:77a540690e24b0305878c37ffd421785a6f7e53c8b5720d211b211de8d0e95da",
                 "sha256:cefa1a2f919b866c5beb7c9f7b0ebb4061f30a8a9bf16d609b000e2dfaceb9c3"
             ],
-            "index": "pypi",
-            "markers": "python_version < '3.8'",
             "version": "==2.0.0"
         },
         "iniconfig": {
@@ -106,6 +111,47 @@
             ],
             "version": "==1.0.1"
         },
+        "isort": {
+            "hashes": [
+                "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1",
+                "sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd"
+            ],
+            "index": "pypi",
+            "version": "==4.3.21"
+        },
+        "lazy-object-proxy": {
+            "hashes": [
+                "sha256:0c4b206227a8097f05c4dbdd323c50edf81f15db3b8dc064d08c62d37e1a504d",
+                "sha256:194d092e6f246b906e8f70884e620e459fc54db3259e60cf69a4d66c3fda3449",
+                "sha256:1be7e4c9f96948003609aa6c974ae59830a6baecc5376c25c92d7d697e684c08",
+                "sha256:4677f594e474c91da97f489fea5b7daa17b5517190899cf213697e48d3902f5a",
+                "sha256:48dab84ebd4831077b150572aec802f303117c8cc5c871e182447281ebf3ac50",
+                "sha256:5541cada25cd173702dbd99f8e22434105456314462326f06dba3e180f203dfd",
+                "sha256:59f79fef100b09564bc2df42ea2d8d21a64fdcda64979c0fa3db7bdaabaf6239",
+                "sha256:8d859b89baf8ef7f8bc6b00aa20316483d67f0b1cbf422f5b4dc56701c8f2ffb",
+                "sha256:9254f4358b9b541e3441b007a0ea0764b9d056afdeafc1a5569eee1cc6c1b9ea",
+                "sha256:9651375199045a358eb6741df3e02a651e0330be090b3bc79f6d0de31a80ec3e",
+                "sha256:97bb5884f6f1cdce0099f86b907aa41c970c3c672ac8b9c8352789e103cf3156",
+                "sha256:9b15f3f4c0f35727d3a0fba4b770b3c4ebbb1fa907dbcc046a1d2799f3edd142",
+                "sha256:a2238e9d1bb71a56cd710611a1614d1194dc10a175c1e08d75e1a7bcc250d442",
+                "sha256:a6ae12d08c0bf9909ce12385803a543bfe99b95fe01e752536a60af2b7797c62",
+                "sha256:ca0a928a3ddbc5725be2dd1cf895ec0a254798915fb3a36af0964a0a4149e3db",
+                "sha256:cb2c7c57005a6804ab66f106ceb8482da55f5314b7fcb06551db1edae4ad1531",
+                "sha256:d74bb8693bf9cf75ac3b47a54d716bbb1a92648d5f781fc799347cfc95952383",
+                "sha256:d945239a5639b3ff35b70a88c5f2f491913eb94871780ebfabb2568bd58afc5a",
+                "sha256:eba7011090323c1dadf18b3b689845fd96a61ba0a1dfbd7f24b921398affc357",
+                "sha256:efa1909120ce98bbb3777e8b6f92237f5d5c8ea6758efea36a473e1d38f7d3e4",
+                "sha256:f3900e8a5de27447acbf900b4750b0ddfd7ec1ea7fbaf11dfa911141bc522af0"
+            ],
+            "version": "==1.4.3"
+        },
+        "mccabe": {
+            "hashes": [
+                "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42",
+                "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"
+            ],
+            "version": "==0.6.1"
+        },
         "mypy": {
             "hashes": [
                 "sha256:2c6cde8aa3426c1682d35190b59b71f661237d74b053822ea3d748e2c9578a7c",
@@ -170,6 +216,22 @@
             ],
             "version": "==1.9.0"
         },
+        "pylint": {
+            "hashes": [
+                "sha256:bb4a908c9dadbc3aac18860550e870f58e1a02c9f2c204fdf5693d73be061210",
+                "sha256:bfe68f020f8a0fece830a22dd4d5dddb4ecc6137db04face4c3420a46a52239f"
+            ],
+            "index": "pypi",
+            "version": "==2.6.0"
+        },
+        "pylint-import-requirements": {
+            "hashes": [
+                "sha256:39d0993baa0991c2c6258d310aacd5f69c850ba59cb3d2ae8aa69886886b7135",
+                "sha256:bc138263bf1f79d8d1bf3d3f6786248024a71b4202cd19a189f1346f3e5b20a7"
+            ],
+            "index": "pypi",
+            "version": "==2.0.5"
+        },
         "pyparsing": {
             "hashes": [
                 "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1",
@@ -267,6 +329,12 @@
             ],
             "version": "==3.7.4.3"
         },
+        "wrapt": {
+            "hashes": [
+                "sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7"
+            ],
+            "version": "==1.12.1"
+        },
         "zipp": {
             "hashes": [
                 "sha256:c70410551488251b0fee67b460fb9a536af8d6f9f008ad10ac51f615b6a521b1",

+ 4 - 2
acpi_backlight/__init__.py

@@ -9,6 +9,9 @@ _ACPI_BACKLIGHT_ROOT_DIR_PATH = "/sys/class/backlight"
 
 
 class Backlight:
+
+    # pylint: disable=too-few-public-methods; does not count properties
+
     def __init__(self, name="intel_backlight"):
         self._acpi_dir_path = os.path.join(_ACPI_BACKLIGHT_ROOT_DIR_PATH, name)
 
@@ -49,8 +52,7 @@ class Backlight:
 def backlight_eval(expr_str):
     backlight = acpi_backlight.Backlight()
     backlight.brightness_relative = acpi_backlight.evaluate.evaluate_expression(
-        expr_str=expr_str,
-        names={"b": backlight.brightness_relative},
+        expr_str=expr_str, names={"b": backlight.brightness_relative}
     )
     print(backlight.brightness_relative)
 

+ 4 - 5
acpi_backlight/evaluate.py

@@ -17,17 +17,16 @@ _OPERATORS = {
 def _evaluate(node, names):
     if isinstance(node, ast.Num):
         return node.n
-    elif isinstance(node, ast.Name):
+    if isinstance(node, ast.Name):
         return names[node.id]
-    elif isinstance(node, ast.UnaryOp):
+    if isinstance(node, ast.UnaryOp):
         operand = _evaluate(node.operand, names=names)
         return _OPERATORS[type(node.op)](operand)
-    elif isinstance(node, ast.BinOp):
+    if isinstance(node, ast.BinOp):
         operand_left = _evaluate(node.left, names=names)
         operand_right = _evaluate(node.right, names=names)
         return _OPERATORS[type(node.op)](operand_left, operand_right)
-    else:
-        raise Exception(node)
+    raise Exception(node)
 
 
 def evaluate_expression(expr_str, names):