Browse Source

format code via black

Fabian Peter Hammerle 10 months ago
parent
commit
6145e6ae2a
8 changed files with 198 additions and 73 deletions
  1. 18 1
      .github/workflows/python.yml
  2. 9 1
      Pipfile
  3. 114 24
      Pipfile.lock
  4. 1 0
      README.md
  5. 14 13
      acpi_backlight/__init__.py
  6. 1 1
      acpi_backlight/evaluate.py
  7. 12 10
      setup.py
  8. 29 23
      tests/test_evaluate.py

+ 18 - 1
.github/workflows/python.yml

@@ -11,6 +11,23 @@ on:
   - cron: '0 20 * * 5'
 
 jobs:
+  code-format:
+    runs-on: ubuntu-18.04
+    strategy:
+      matrix:
+        python-version:
+        - 3.8
+    steps:
+    - uses: actions/checkout@v1
+    - uses: actions/setup-python@v1
+      with:
+        python-version: ${{ matrix.python-version }}
+    - run: pip install --upgrade pipenv==2020.8.13
+    - run: pipenv install --python "$PYTHON_VERSION" --deploy --dev
+      env:
+        PYTHON_VERSION: ${{ matrix.python-version }}
+    - run: pipenv graph
+    - run: pipenv run black --check .
   tests:
     runs-on: ubuntu-18.04
     strategy:
@@ -26,7 +43,7 @@ jobs:
     - uses: actions/setup-python@v1
       with:
         python-version: ${{ matrix.python-version }}
-    - run: pip install --upgrade pipenv==2020.6.2
+    - run: pip install --upgrade pipenv==2020.8.13
     - run: pipenv install --python "$PYTHON_VERSION" --deploy --dev
       env:
         PYTHON_VERSION: ${{ matrix.python-version }}

+ 9 - 1
Pipfile

@@ -7,10 +7,18 @@ name = "pypi"
 acpi-backlight = {editable = true, path = "."}
 
 [dev-packages]
+# black requires python>=3.6
+# https://github.com/psf/black/commit/e74117f172e29e8a980e2c9de929ad50d3769150#diff-2eeaed663bd0d25b7e608891384b7298R51
+black = {version = "==20.8b1", markers = "python_version >= '3.6'"}
 pytest = "*"
 
+# python3.5 compatibility
 # workaround https://github.com/pytest-dev/pytest/issues/3953
 pathlib2 = {version = "*", markers="python_version < '3.6'"}
-# zipp v2.0.0 dropped support for python3.5
 # https://github.com/jaraco/zipp/commit/05a3c52b4d41690e0471a2e283cffb500dc0329a
 zipp = "<2"
+
+[requires]
+python_version = "3"
+
+# Pipfile syntax: https://github.com/pypa/pipfile#pipfile

+ 114 - 24
Pipfile.lock

@@ -1,10 +1,12 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "90ead5fbcddf0ef730c9398cc1df5a5f169e67ea8afdc61eb41bcc2a8942f3ed"
+            "sha256": "19d3aa32c28fa427dc09dc87f0c9755c1711d982b8c960e422610ee8a7bb080e"
         },
         "pipfile-spec": 6,
-        "requires": {},
+        "requires": {
+            "python_version": "3"
+        },
         "sources": [
             {
                 "name": "pypi",
@@ -20,27 +22,48 @@
         }
     },
     "develop": {
+        "appdirs": {
+            "hashes": [
+                "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41",
+                "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"
+            ],
+            "version": "==1.4.4"
+        },
         "attrs": {
             "hashes": [
-                "sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c",
-                "sha256:f7b7ce16570fe9965acd6d30101a28f62fb4a7f9e926b3bbc9b61f8b04247e72"
+                "sha256:26b54ddbbb9ee1d34d5d3668dd37d6cf74990ab23c828c2888dccdceee395594",
+                "sha256:fce7fc47dfc976152e82d53ff92fa0407700c21acd20886a13777a0d20e655dc"
+            ],
+            "version": "==20.2.0"
+        },
+        "black": {
+            "hashes": [
+                "sha256:1c02557aa099101b9d21496f8a914e9ed2222ef70336404eeeac8edba836fbea"
+            ],
+            "index": "pypi",
+            "markers": "python_version >= '3.6'",
+            "version": "==20.8b1"
+        },
+        "click": {
+            "hashes": [
+                "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a",
+                "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"
             ],
-            "version": "==19.3.0"
+            "version": "==7.1.2"
         },
-        "importlib-metadata": {
+        "iniconfig": {
             "hashes": [
-                "sha256:0505dd08068cfec00f53a74a0ad927676d7757da81b7436a6eefe4c7cf75c545",
-                "sha256:15ec6c0fd909e893e3a08b3a7c76ecb149122fb14b7efe1199ddd4c7c57ea958"
+                "sha256:80cf40c597eb564e86346103f609d74efce0f6b4d4f30ec8ce9e2c26411ba437",
+                "sha256:e5f92f89355a67de0595932a6c6c02ab4afddc6fcdc0bfc5becd0d60884d3f69"
             ],
-            "markers": "python_version < '3.8'",
-            "version": "==1.6.1"
+            "version": "==1.0.1"
         },
-        "more-itertools": {
+        "mypy-extensions": {
             "hashes": [
-                "sha256:68c70cc7167bdf5c7c9d8f6954a7837089c6a36bf565383919bb595efb8a17e5",
-                "sha256:b78134b2063dd214000685165d81c154522c3ee0a1c0d4d113c80361c234c5a2"
+                "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d",
+                "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"
             ],
-            "version": "==8.4.0"
+            "version": "==0.4.3"
         },
         "packaging": {
             "hashes": [
@@ -58,6 +81,13 @@
             "markers": "python_version < '3.6'",
             "version": "==2.3.5"
         },
+        "pathspec": {
+            "hashes": [
+                "sha256:7d91249d21749788d07a2d0f94147accd8f845507400749ea19c1ec9054a12b0",
+                "sha256:da45173eb3a6f2a5a487efba21f050af2b41948be6ab52b6a1e3ff22bb8b7061"
+            ],
+            "version": "==0.8.0"
+        },
         "pluggy": {
             "hashes": [
                 "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0",
@@ -67,10 +97,10 @@
         },
         "py": {
             "hashes": [
-                "sha256:a673fa23d7000440cc885c17dbd34fafcb7d7a6e230b29f6766400de36a33c44",
-                "sha256:f3b3a4c36512a4c4f024041ab51866f11761cc169670204b235f6b20523d4e6b"
+                "sha256:366389d1db726cd2fcfc79732e75410e5fe4d31db13692115529d34069a043c2",
+                "sha256:9ca6883ce56b4e8da7e79ac18787889fa5206c79dcc67fb065376cd2fe03f342"
             ],
-            "version": "==1.8.2"
+            "version": "==1.9.0"
         },
         "pyparsing": {
             "hashes": [
@@ -81,11 +111,37 @@
         },
         "pytest": {
             "hashes": [
-                "sha256:5c0db86b698e8f170ba4582a492248919255fcd4c79b1ee64ace34301fb589a1",
-                "sha256:7979331bfcba207414f5e1263b5a0f8f521d0f457318836a7355531ed1a4c7d8"
+                "sha256:1cd09785c0a50f9af72220dd12aa78cfa49cbffc356c61eab009ca189e018a33",
+                "sha256:d010e24666435b39a4cf48740b039885642b6c273a3f77be3e7e03554d2806b7"
             ],
             "index": "pypi",
-            "version": "==5.4.3"
+            "version": "==6.1.0"
+        },
+        "regex": {
+            "hashes": [
+                "sha256:088afc8c63e7bd187a3c70a94b9e50ab3f17e1d3f52a32750b5b77dbe99ef5ef",
+                "sha256:1fe0a41437bbd06063aa184c34804efa886bcc128222e9916310c92cd54c3b4c",
+                "sha256:41bb65f54bba392643557e617316d0d899ed5b4946dccee1cb6696152b29844b",
+                "sha256:4318d56bccfe7d43e5addb272406ade7a2274da4b70eb15922a071c58ab0108c",
+                "sha256:4707f3695b34335afdfb09be3802c87fa0bc27030471dbc082f815f23688bc63",
+                "sha256:5533a959a1748a5c042a6da71fe9267a908e21eded7a4f373efd23a2cbdb0ecc",
+                "sha256:5f18875ac23d9aa2f060838e8b79093e8bb2313dbaaa9f54c6d8e52a5df097be",
+                "sha256:60b0e9e6dc45683e569ec37c55ac20c582973841927a85f2d8a7d20ee80216ab",
+                "sha256:84e9407db1b2eb368b7ecc283121b5e592c9aaedbe8c78b1a2f1102eb2e21d19",
+                "sha256:8d69cef61fa50c8133382e61fd97439de1ae623fe943578e477e76a9d9471637",
+                "sha256:9a02d0ae31d35e1ec12a4ea4d4cca990800f66a917d0fb997b20fbc13f5321fc",
+                "sha256:9bc13e0d20b97ffb07821aa3e113f9998e84994fe4d159ffa3d3a9d1b805043b",
+                "sha256:a6f32aea4260dfe0e55dc9733ea162ea38f0ea86aa7d0f77b15beac5bf7b369d",
+                "sha256:ae91972f8ac958039920ef6e8769277c084971a142ce2b660691793ae44aae6b",
+                "sha256:c570f6fa14b9c4c8a4924aaad354652366577b4f98213cf76305067144f7b100",
+                "sha256:d23a18037313714fb3bb5a94434d3151ee4300bae631894b1ac08111abeaa4a3",
+                "sha256:eaf548d117b6737df379fdd53bdde4f08870e66d7ea653e230477f071f861121",
+                "sha256:ebbe29186a3d9b0c591e71b7393f1ae08c83cb2d8e517d2a822b8f7ec99dfd8b",
+                "sha256:eda4771e0ace7f67f58bc5b560e27fb20f32a148cbc993b0c3835970935c2707",
+                "sha256:f1b3afc574a3db3b25c89161059d857bd4909a1269b0b3cb3c904677c8c4a3f7",
+                "sha256:f2388013e68e750eaa16ccbea62d4130180c26abb1d8e5d584b9baf69672b30f"
+            ],
+            "version": "==2020.9.27"
         },
         "six": {
             "hashes": [
@@ -94,12 +150,46 @@
             ],
             "version": "==1.15.0"
         },
-        "wcwidth": {
+        "toml": {
+            "hashes": [
+                "sha256:926b612be1e5ce0634a2ca03470f95169cf16f939018233a670519cb4ac58b0f",
+                "sha256:bda89d5935c2eac546d648028b9901107a595863cb36bae0c73ac804a9b4ce88"
+            ],
+            "version": "==0.10.1"
+        },
+        "typed-ast": {
+            "hashes": [
+                "sha256:0666aa36131496aed8f7be0410ff974562ab7eeac11ef351def9ea6fa28f6355",
+                "sha256:0c2c07682d61a629b68433afb159376e24e5b2fd4641d35424e462169c0a7919",
+                "sha256:249862707802d40f7f29f6e1aad8d84b5aa9e44552d2cc17384b209f091276aa",
+                "sha256:24995c843eb0ad11a4527b026b4dde3da70e1f2d8806c99b7b4a7cf491612652",
+                "sha256:269151951236b0f9a6f04015a9004084a5ab0d5f19b57de779f908621e7d8b75",
+                "sha256:4083861b0aa07990b619bd7ddc365eb7fa4b817e99cf5f8d9cf21a42780f6e01",
+                "sha256:498b0f36cc7054c1fead3d7fc59d2150f4d5c6c56ba7fb150c013fbc683a8d2d",
+                "sha256:4e3e5da80ccbebfff202a67bf900d081906c358ccc3d5e3c8aea42fdfdfd51c1",
+                "sha256:6daac9731f172c2a22ade6ed0c00197ee7cc1221aa84cfdf9c31defeb059a907",
+                "sha256:715ff2f2df46121071622063fc7543d9b1fd19ebfc4f5c8895af64a77a8c852c",
+                "sha256:73d785a950fc82dd2a25897d525d003f6378d1cb23ab305578394694202a58c3",
+                "sha256:8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1ba129eb293ec30b",
+                "sha256:8ce678dbaf790dbdb3eba24056d5364fb45944f33553dd5869b7580cdbb83614",
+                "sha256:aaee9905aee35ba5905cfb3c62f3e83b3bec7b39413f0a7f19be4e547ea01ebb",
+                "sha256:bcd3b13b56ea479b3650b82cabd6b5343a625b0ced5429e4ccad28a8973f301b",
+                "sha256:c9e348e02e4d2b4a8b2eedb48210430658df6951fa484e59de33ff773fbd4b41",
+                "sha256:d205b1b46085271b4e15f670058ce182bd1199e56b317bf2ec004b6a44f911f6",
+                "sha256:d43943ef777f9a1c42bf4e552ba23ac77a6351de620aa9acf64ad54933ad4d34",
+                "sha256:d5d33e9e7af3b34a40dc05f498939f0ebf187f07c385fd58d591c533ad8562fe",
+                "sha256:fc0fea399acb12edbf8a628ba8d2312f583bdbdb3335635db062fa98cf71fca4",
+                "sha256:fe460b922ec15dd205595c9b5b99e2f056fd98ae8f9f56b888e7a17dc2b757e7"
+            ],
+            "version": "==1.4.1"
+        },
+        "typing-extensions": {
             "hashes": [
-                "sha256:beb4802a9cebb9144e99086eff703a642a13d6a0052920003a230f3294bbe784",
-                "sha256:c4d647b99872929fdb7bdcaa4fbe7f01413ed3d98077df798530e5b04f116c83"
+                "sha256:7cb407020f00f7bfc3cb3e7881628838e69d8f3fcab2f64742a5e76b2f841918",
+                "sha256:99d4073b617d30288f569d3f13d2bd7548c3a7e4c8de87db09a9d29bb3a4a60c",
+                "sha256:dafc7639cde7f1b6e1acc0f457842a83e722ccca8eef5270af2d74792619a89f"
             ],
-            "version": "==0.2.5"
+            "version": "==3.7.4.3"
         },
         "zipp": {
             "hashes": [

+ 1 - 0
README.md

@@ -1,5 +1,6 @@
 # acpi-backlight
 
+[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
 [![CI Pipeline Status](https://github.com/fphammerle/acpi-backlight/workflows/tests/badge.svg)](https://github.com/fphammerle/acpi-backlight/actions)
 
 ## setup

+ 14 - 13
acpi_backlight/__init__.py

@@ -5,35 +5,34 @@ import os
 
 import acpi_backlight.evaluate
 
-_ACPI_BACKLIGHT_ROOT_DIR_PATH = '/sys/class/backlight'
+_ACPI_BACKLIGHT_ROOT_DIR_PATH = "/sys/class/backlight"
 
 
 class Backlight:
-
-    def __init__(self, name='intel_backlight'):
+    def __init__(self, name="intel_backlight"):
         self._acpi_dir_path = os.path.join(_ACPI_BACKLIGHT_ROOT_DIR_PATH, name)
 
     @property
     def _brightness_path(self):
-        return os.path.join(self._acpi_dir_path, 'brightness')
+        return os.path.join(self._acpi_dir_path, "brightness")
 
     @property
     def _max_brightness_path(self):
-        return os.path.join(self._acpi_dir_path, 'max_brightness')
+        return os.path.join(self._acpi_dir_path, "max_brightness")
 
     @property
     def _brightness_absolute(self):
-        with open(self._brightness_path, 'r') as brightness_file:
+        with open(self._brightness_path, "r") as brightness_file:
             return int(brightness_file.read())
 
     @_brightness_absolute.setter
     def _brightness_absolute(self, brightness_absolute):
-        with open(self._brightness_path, 'w') as brightness_file:
+        with open(self._brightness_path, "w") as brightness_file:
             return brightness_file.write(str(round(brightness_absolute)))
 
     @property
     def _max_brightness_absolute(self):
-        with open(self._max_brightness_path, 'r') as max_brightness_file:
+        with open(self._max_brightness_path, "r") as max_brightness_file:
             return int(max_brightness_file.read())
 
     @property
@@ -42,24 +41,26 @@ class Backlight:
 
     @brightness_relative.setter
     def brightness_relative(self, brightness_relative):
-        self._brightness_absolute = max(0, min(1, brightness_relative)) \
-            * self._max_brightness_absolute
+        self._brightness_absolute = (
+            max(0, min(1, brightness_relative)) * self._max_brightness_absolute
+        )
 
 
 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},
+        names={"b": backlight.brightness_relative},
     )
     print(backlight.brightness_relative)
 
 
 def main():
     argparser = argparse.ArgumentParser()
-    argparser.add_argument('expr_str')
+    argparser.add_argument("expr_str")
     args = argparser.parse_args()
     backlight_eval(expr_str=args.expr_str)
 
-if __name__ == '__main__':
+
+if __name__ == "__main__":
     main()

+ 1 - 1
acpi_backlight/evaluate.py

@@ -31,5 +31,5 @@ def _evaluate(node, names):
 
 
 def evaluate_expression(expr_str, names):
-    expr = ast.parse(expr_str, mode='eval')
+    expr = ast.parse(expr_str, mode="eval")
     return _evaluate(expr.body, names=names)

+ 12 - 10
setup.py

@@ -3,17 +3,19 @@
 import setuptools
 
 setuptools.setup(
-    name='acpi-backlight',
+    name="acpi-backlight",
     use_scm_version=True,
-    author='Fabian Peter Hammerle',
-    author_email='fabian@hammerle.me',
-    url='https://github.com/fphammerle/acpi-backlight',
-    packages=['acpi_backlight'],
-    entry_points={'console_scripts': [
-        'acpi-backlight-eval=acpi_backlight:main',
-    ]},
-    setup_requires=['setuptools_scm'],
-    tests_require=['pytest'],
+    author="Fabian Peter Hammerle",
+    author_email="fabian@hammerle.me",
+    url="https://github.com/fphammerle/acpi-backlight",
+    packages=["acpi_backlight"],
+    entry_points={
+        "console_scripts": [
+            "acpi-backlight-eval=acpi_backlight:main",
+        ]
+    },
+    setup_requires=["setuptools_scm"],
+    tests_require=["pytest"],
     classifiers=[
         "License :: OSI Approved :: MIT License",
         "Operating System :: POSIX :: Linux",

+ 29 - 23
tests/test_evaluate.py

@@ -5,33 +5,39 @@ import pytest
 from acpi_backlight.evaluate import evaluate_expression
 
 
-@pytest.mark.parametrize(('expr_str', 'names', 'expected'), [
-    ('0', {}, 0),
-    ('0.0', {}, 0),
-    ('1.0', {}, 1),
-    ('-1', {}, -1),
-    ('0.1 + 0.2', {}, 0.3),
-    ('0.3 - 0.2', {}, 0.1),
-    ('0.2 * 3', {}, 0.6),
-    ('0.6 / 3', {}, 0.2),
-    ('0.6 / 3 + 0.1', {}, 0.3),
-    ('(0.6 - 0.2) / 2', {}, 0.2),
-    ('b', {'b': 0.4}, 0.4),
-    ('-b', {'b': 0.3}, -0.3),
-    ('0.1 + b', {'b': 0.2}, 0.3),
-])
+@pytest.mark.parametrize(
+    ("expr_str", "names", "expected"),
+    [
+        ("0", {}, 0),
+        ("0.0", {}, 0),
+        ("1.0", {}, 1),
+        ("-1", {}, -1),
+        ("0.1 + 0.2", {}, 0.3),
+        ("0.3 - 0.2", {}, 0.1),
+        ("0.2 * 3", {}, 0.6),
+        ("0.6 / 3", {}, 0.2),
+        ("0.6 / 3 + 0.1", {}, 0.3),
+        ("(0.6 - 0.2) / 2", {}, 0.2),
+        ("b", {"b": 0.4}, 0.4),
+        ("-b", {"b": 0.3}, -0.3),
+        ("0.1 + b", {"b": 0.2}, 0.3),
+    ],
+)
 def test_evaluate_expression(expr_str, names, expected):
     assert expected == pytest.approx(evaluate_expression(expr_str, names))
 
 
-@pytest.mark.parametrize('expr_str', [
-    'read("/proc/cpuinfo")',
-    'os.exit(42)',
-    'os.system("echo evil")',
-    '0.__class__',
-    'None.__class__',
-    'eval("1")',
-])
+@pytest.mark.parametrize(
+    "expr_str",
+    [
+        'read("/proc/cpuinfo")',
+        "os.exit(42)",
+        'os.system("echo evil")',
+        "0.__class__",
+        "None.__class__",
+        'eval("1")',
+    ],
+)
 def test_evaluate_expression_fail(expr_str):
     with pytest.raises(Exception):
         evaluate_expression(expr_str, {})