diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e9129f0..b19c635 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,44 +1,49 @@ repos: - - repo: https://github.com/FHPythonUtils/Blackt - rev: '2022.0.3' + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.14 hooks: - - id: blackt + - id: ruff + args: [ --fix ] + + - repo: https://github.com/RobertCraigie/pyright-python + rev: v1.1.347 + hooks: + - id: pyright - - repo: https://github.com/pycqa/isort - rev: 5.12.0 + - repo: https://github.com/FHPythonUtils/Blackt + rev: '2024.0.1' hooks: - - id: isort + - id: blackt - - repo: https://github.com/pycqa/pylint - rev: v3.0.0a6 + - repo: https://github.com/Lucas-C/pre-commit-hooks-safety + rev: v1.3.2 hooks: - - id: pylint - exclude: "tests/" - args: [--disable=import-error,--jobs=0] + - id: python-safety-dependencies-check + files: pyproject.toml - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: trailing-whitespace - exclude: "tests/" - id: end-of-file-fixer - exclude: "tests/" + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-json + - id: check-merge-conflict + - id: check-shebang-scripts-are-executable + - id: check-symlinks + - id: check-toml + - id: check-vcs-permalinks + - id: check-yaml + - id: detect-private-key + - id: mixed-line-ending - - repo: https://github.com/asottile/pyupgrade - rev: v3.7.0 - hooks: - - id: pyupgrade - args: [--py38-plus] - repo: https://github.com/boidolr/pre-commit-images - rev: v1.2.1 + rev: v1.5.1 hooks: - - id: optimize-avif - exclude: "tests/" - id: optimize-jpg - exclude: "tests/" - id: optimize-png - exclude: "tests/" - id: optimize-svg - exclude: "tests/" - id: optimize-webp - exclude: "tests/" + +exclude: "tests/data|documentation/reference" diff --git a/getostheme/__init__.py b/getostheme/__init__.py index 7626a59..0f5b95b 100644 --- a/getostheme/__init__.py +++ b/getostheme/__init__.py @@ -1,4 +1,4 @@ -"""Use this module to get the OS theme (dark/light) +"""Use this module to get the OS theme (dark/light). """ # pylint: disable=import-outside-toplevel from __future__ import annotations @@ -9,12 +9,14 @@ def isLightMode_Mac() -> bool: # pylint: disable=invalid-name """For MacOS BSD-3-Clause albertosottile - (https://github.com/albertosottile/darkdetect) + (https://github.com/albertosottile/darkdetect). - Raises: + Raises + ------ OSError: Cannot load objc - Returns: + Returns + ------- bool: Windows is in light mode """ import ctypes @@ -22,7 +24,8 @@ def isLightMode_Mac() -> bool: # pylint: disable=invalid-name lib = ctypes.util.find_library("objc") if not lib: - raise OSError("Cannot load objc") + msg = "Cannot load objc" + raise OSError(msg) objc = ctypes.cdll.LoadLibrary(lib) void_p = ctypes.c_void_p @@ -35,16 +38,18 @@ def isLightMode_Mac() -> bool: # pylint: disable=invalid-name # Objective C msg send msgSend = objc.objc_msgSend - def _encodeUTF8(string: str | bytes): - """Encode string as utf8 bytes + def _encodeUTF8(string: str | bytes) -> bytes: + """Encode string as utf8 bytes. Args: + ---- string (Union[str, bytes]): string to encode Returns: + ------- bytes: bytes """ - if not isinstance(string, bytes): + if isinstance(string, str): string = string.encode("utf8") return string @@ -55,9 +60,10 @@ def objcClass(classname: str | bytes): return objc.objc_getClass(_encodeUTF8(classname)) def theme() -> str: - """Get the MAC OS theme string + """Get the MAC OS theme string. - Returns: + Returns + ------- string: Theme string """ nsAutoreleasePool = objc.objc_getClass("NSAutoreleasePool") @@ -75,10 +81,7 @@ def theme() -> str: appearanceNS = msgSend(stdUserDef, objcName("stringForKey:"), void_p(key)) appearanceC = msgSend(appearanceNS, objcName("UTF8String")) - if appearanceC is not None: - out = ctypes.string_at(appearanceC) - else: - out = None + out = ctypes.string_at(appearanceC) if appearanceC is not None else None msgSend(pool, objcName("release")) @@ -91,9 +94,10 @@ def theme() -> str: def isLightMode_Windows() -> bool: # pylint: disable=invalid-name """For Windows OS MIT clxmente - (https://github.com/clxmente/Windows-Dark-Mode-Check) + (https://github.com/clxmente/Windows-Dark-Mode-Check). - Returns: + Returns + ------- bool: Windows is in light mode """ from winreg import HKEY_CURRENT_USER, ConnectRegistry, OpenKey, QueryValueEx @@ -105,9 +109,10 @@ def isLightMode_Windows() -> bool: # pylint: disable=invalid-name def isLightMode_Linux() -> bool: # pylint: disable=invalid-name - """For Linux OS MIT FredHappyface + """For Linux OS MIT FredHappyface. - Returns: + Returns + ------- bool: Linux is in light mode """ if importlib.util.find_spec("PyQt5"): # Qt5 @@ -128,9 +133,10 @@ def isLightMode_Linux() -> bool: # pylint: disable=invalid-name def isLightMode() -> bool: - """Call isLightMode_OS + """Call isLightMode_OS. - Returns: + Returns + ------- bool: OS is in light mode """ if platform.system() == "Darwin": @@ -143,13 +149,15 @@ def isLightMode() -> bool: def isDarkMode() -> bool: - """ - Returns: + """Is the OS in dark mode?. + + Returns + ------- bool: OS is in dark mode """ return not isLightMode() -def cli(): - """CLI entry point""" +def cli() -> None: + """CLI entry point.""" print("OS is in " + ("Light" if isLightMode() else "Dark") + " Mode") diff --git a/getostheme/__main__.py b/getostheme/__main__.py index 33d6567..831ff8e 100644 --- a/getostheme/__main__.py +++ b/getostheme/__main__.py @@ -1,4 +1,4 @@ -""" entry point for python -m getostheme """ +""" entry point for python -m getostheme. """ from __future__ import annotations from . import cli diff --git a/pyproject.toml b/pyproject.toml index ed49696..16e5236 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,38 +24,46 @@ readme = "README.md" getostheme = 'getostheme:cli' [tool.poetry.dependencies] -python = "^3.7" +python = "^3.8" PyQt5 = { version = "<6,>=5.15.10", optional = true } -[tool.black] -line-length = 100 -target-version = ["py38"] - -[tool.isort] -profile = "black" -indent = "Tab" - -[tool.pydocstyle] -convention = "google" -ignore = "D205,D415" +[tool.poetry.group.dev.dependencies] +pytest = "^7.4.4" +handsdown = "^2.1.0" +coverage = "^7.4.0" +ruff = "^0.1.13" +blackt = "^2024.0.1" +pyright = "^1.1.347" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" -[tool.pylint.basic] -argument-naming-style = "camelCase" -attr-naming-style = "camelCase" -function-naming-style = "camelCase" -method-naming-style = "camelCase" -variable-naming-style = "camelCase" +[tool.ruff] +line-length = 100 +indent-width = 4 +target-version = "py38" -[tool.pylint.format] -indent-string = "\t" +[tool.ruff.lint] +select = ["ALL"] +ignore = [ + "ANN101", # type annotation for self in method + "COM812", # enforce trailing comma + "D2", # pydocstyle formatting + "N802", "N803", "N806", "N812", "N813", # pep8 naming + "PLR09", # pylint refactor too many + "TCH", # type check blocks + "W191" # ignore this to allow tabs +] +fixable = ["ALL"] + +[tool.ruff.lint.per-file-ignores] +"**/{tests,docs,tools}/*" = ["D", "S101", "E402"] -[tool.pylint.master] -ignore-paths = ["tests"] +[tool.black] +line-length = 100 +target-version = ["py38"] -[tool.pylint.messages_control] -enable = ["F", "E", "W", "R", "C"] -disable = ["pointless-string-statement", "superfluous-parens"] +[tool.pyright] +venvPath = "." +venv = ".venv" diff --git a/requirements.txt b/requirements.txt index 8b13789..e69de29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +0,0 @@ -