Skip to content

Commit

Permalink
address ruff suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
FredHappyface committed Jan 20, 2024
1 parent 59f1b31 commit f71d371
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 77 deletions.
57 changes: 31 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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"
56 changes: 32 additions & 24 deletions getostheme/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,20 +9,23 @@

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
import ctypes.util

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
Expand All @@ -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

Expand All @@ -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")
Expand All @@ -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"))

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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":
Expand All @@ -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")
2 changes: 1 addition & 1 deletion getostheme/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" entry point for python -m getostheme """
""" entry point for python -m getostheme. """
from __future__ import annotations

from . import cli
Expand Down
58 changes: 33 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

0 comments on commit f71d371

Please sign in to comment.