Browse Source

disable ability to invoke `acpi_backlight` module as script (via `python -m acpi_backlight`); made main function private (use entry point `acpi-backlight-eval` instead)

Fabian Peter Hammerle 1 month ago
parent
commit
ed078a508d
4 changed files with 6 additions and 8 deletions
  1. 1 1
      .github/workflows/python.yml
  2. 1 5
      acpi_backlight/__init__.py
  3. 1 1
      setup.py
  4. 3 1
      tests/test_cli.py

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

@@ -49,7 +49,7 @@ jobs:
       env:
         PYTHON_VERSION: ${{ matrix.python-version }}
     - run: pipenv graph
-    - run: pipenv run pytest --cov="$(cat *.egg-info/top_level.txt)" --cov-report=term-missing --cov-fail-under=97
+    - run: pipenv run pytest --cov="$(cat *.egg-info/top_level.txt)" --cov-report=term-missing --cov-fail-under=100
     - run: pipenv run pylint --load-plugins=pylint_import_requirements "$(cat *.egg-info/top_level.txt)"
     # https://github.com/PyCQA/pylint/issues/352
     - run: pipenv run pylint tests/*

+ 1 - 5
acpi_backlight/__init__.py

@@ -52,12 +52,8 @@ def backlight_eval(expr_str: str) -> None:
     print(backlight.brightness_relative)
 
 
-def main() -> None:
+def _main() -> None:
     argparser = argparse.ArgumentParser()
     argparser.add_argument("expr_str")
     args = argparser.parse_args()
     backlight_eval(expr_str=args.expr_str)
-
-
-if __name__ == "__main__":
-    main()

+ 1 - 1
setup.py

@@ -11,7 +11,7 @@ setuptools.setup(
     packages=["acpi_backlight"],
     entry_points={
         "console_scripts": [
-            "acpi-backlight-eval=acpi_backlight:main",
+            "acpi-backlight-eval=acpi_backlight:_main",
         ]
     },
     classifiers=[

+ 3 - 1
tests/test_main.py → tests/test_cli.py

@@ -5,6 +5,8 @@ import pytest
 
 import acpi_backlight
 
+# pylint: disable=protected-access; tests
+
 
 @pytest.mark.parametrize(
     ("expr_str", "brightness"),
@@ -25,5 +27,5 @@ def test_main(tmp_path: pathlib.Path, expr_str: str, brightness: str):
     with unittest.mock.patch("sys.argv", ["", expr_str]), unittest.mock.patch(
         "acpi_backlight._ACPI_BACKLIGHT_ROOT_DIR_PATH", tmp_path
     ):
-        acpi_backlight.main()
+        acpi_backlight._main()
     assert acpi_dir_path.joinpath("brightness").read_text() == brightness