Skip to content

Commit e5dbea3

Browse files
committed
Run ruff format and fix linting issues
- Apply ruff format to all Python files - Fix import sorting (remove unused collections and sys imports) - Replace percent formatting with f-strings (non-logger calls only) - Fix line length in __init__.py docstring - Add build/dist exclusions to ruff config - Ignore F403 for wildcard import in __init__.py (public API)
1 parent a4da4b7 commit e5dbea3

4 files changed

Lines changed: 28 additions & 21 deletions

File tree

libloader/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
__author__ = "Christopher Toth"
55
__author_email__ = "q@q-continuum.net"
66
__doc__ = """
7-
Quickly and easily load shared libraries on various platforms. Also includes a libloader.com module for loading com modules on Windows.
7+
Quickly and easily load shared libraries on various platforms. Also includes a
8+
libloader.com module for loading com modules on Windows.
89
"""

libloader/com.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
23
from pywintypes import com_error
34
from win32com.client import gencache
45

@@ -30,5 +31,5 @@ def load_com(*names):
3031
continue
3132
if result is None:
3233
logger.error("Failed to load any COM objects. Tried: %s", failed_names)
33-
raise com_error("Unable to load any of the provided com objects: %s" % failed_names)
34+
raise com_error(f"Unable to load any of the provided com objects: {failed_names}")
3435
return result

libloader/libloader.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import ctypes
2-
import collections
3-
import platform
4-
import os
5-
import sys
62
import logging
3+
import os
4+
import platform
75

86
# Set up logger
97
logger = logging.getLogger(__name__)
@@ -39,19 +37,17 @@ class LibraryLoadError(OSError):
3937
def load_library(library, x86_path=".", x64_path=".", *args, **kwargs):
4038
logger.debug("Attempting to load library: %s", library)
4139
logger.debug("x86_path: %s, x64_path: %s", os.path.abspath(x86_path), os.path.abspath(x64_path))
42-
40+
4341
lib = find_library_path(library, x86_path=x86_path, x64_path=x64_path)
4442
logger.debug("Resolved library path: %s", lib)
45-
43+
4644
loaded = _do_load(lib, *args, **kwargs)
4745
if loaded is not None:
4846
logger.info("Successfully loaded library: %s", os.path.basename(lib))
4947
return loaded
50-
48+
5149
logger.error("Failed to load library: %s", lib)
52-
raise LibraryLoadError(
53-
"unable to load %r. Provided library path: %r" % (library, lib)
54-
)
50+
raise LibraryLoadError(f"unable to load {library!r}. Provided library path: {lib!r}")
5551

5652

5753
def _do_load(file, *args, **kwargs):
@@ -68,27 +64,27 @@ def _do_load(file, *args, **kwargs):
6864
def find_library_path(libname, x86_path=".", x64_path="."):
6965
system = platform.system()
7066
prefix = TYPES[system]["prefix"]
71-
libname_with_prefix = "%s%s" % (prefix, libname)
67+
libname_with_prefix = f"{prefix}{libname}"
7268
logger.debug("Library name with prefix: %s", libname_with_prefix)
73-
69+
7470
arch = platform.architecture()[0]
7571
logger.debug("Detected architecture: %s", arch)
76-
72+
7773
if arch == "64bit":
7874
path = os.path.join(x64_path, libname_with_prefix)
7975
logger.debug("Using 64-bit path: %s", x64_path)
8076
else:
8177
path = os.path.join(x86_path, libname_with_prefix)
8278
logger.debug("Using 32-bit path: %s", x86_path)
83-
79+
8480
ext = get_library_extension()
8581
logger.debug("Using library extension: %s", ext)
86-
87-
path = "%s%s" % (path, ext)
82+
83+
path = f"{path}{ext}"
8884
abs_path = os.path.abspath(path)
89-
85+
9086
logger.debug("Path exists: %s", os.path.exists(abs_path))
91-
87+
9288
return abs_path
9389

9490

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ dev = [
3939
[tool.ruff]
4040
line-length = 100
4141
target-version = "py38"
42+
exclude = [
43+
".git",
44+
"__pycache__",
45+
"build",
46+
"dist",
47+
"*.egg-info",
48+
]
4249

4350
[tool.ruff.lint]
4451
select = [
@@ -49,7 +56,9 @@ select = [
4956
"UP", # pyupgrade
5057
"B", # flake8-bugbear
5158
]
52-
ignore = []
59+
ignore = [
60+
"F403", # Allow wildcard imports in __init__.py for public API
61+
]
5362

5463
[tool.pyright]
5564
pythonVersion = "3.8"

0 commit comments

Comments
 (0)