Skip to content

Commit

Permalink
Fix bugs identified by pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
elParaguayo committed Nov 12, 2023
1 parent e6d24a4 commit 1c0b3e2
Show file tree
Hide file tree
Showing 37 changed files with 376 additions and 155 deletions.
102 changes: 51 additions & 51 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import setuptools_scm

sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))

from qtile_extras.widget import widgets
from qtile_extras.widget import widgets # noqa: E402


class Mock(MagicMock):
Expand All @@ -32,48 +32,48 @@ def __dir__(self):


MOCK_MODULES = [
'libqtile.widget.wlan',
'stravalib',
'stravalib.model',
'pint',
'qtile_extras.resources.stravadata.locations',
'libqtile._ffi_pango',
'libqtile.backend.x11._ffi_xcursors',
'libqtile.widget._pulse_audio',
'cairocffi',
'cairocffi.xcb',
'cairocffi.pixbuf',
'cffi',
'dateutil',
'dateutil.parser',
'dbus_next',
'dbus_next.aio',
'dbus_next.service',
'dbus_next.errors',
'dbus_next.constants',
'iwlib',
'keyring',
'mpd',
'psutil',
'trollius',
'xcffib',
'xcffib.randr',
'xcffib.render',
'xcffib.wrappers',
'xcffib.xfixes',
'xcffib.xinerama',
'xcffib.xproto',
'xdg.IconTheme',
"libqtile.widget.wlan",
"stravalib",
"stravalib.model",
"pint",
"qtile_extras.resources.stravadata.locations",
"libqtile._ffi_pango",
"libqtile.backend.x11._ffi_xcursors",
"libqtile.widget._pulse_audio",
"cairocffi",
"cairocffi.xcb",
"cairocffi.pixbuf",
"cffi",
"dateutil",
"dateutil.parser",
"dbus_next",
"dbus_next.aio",
"dbus_next.service",
"dbus_next.errors",
"dbus_next.constants",
"iwlib",
"keyring",
"mpd",
"psutil",
"trollius",
"xcffib",
"xcffib.randr",
"xcffib.render",
"xcffib.wrappers",
"xcffib.xfixes",
"xcffib.xinerama",
"xcffib.xproto",
"xdg.IconTheme",
]
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES if mod_name not in sys.modules)
sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(0, os.path.abspath("."))
sys.path.insert(0, os.path.abspath("../"))

# -- Project information -----------------------------------------------------

project = 'qtile-extras'
copyright = '2021-2022, elParaguayo'
author = 'elParaguayo'
project = "qtile-extras"
copyright = "2021-2022, elParaguayo"
author = "elParaguayo"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand All @@ -91,33 +91,33 @@ def __dir__(self):
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.autosectionlabel',
'sphinx.ext.linkcode',
'sphinx_qtile_extras'
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.autosectionlabel",
"sphinx.ext.linkcode",
"sphinx_qtile_extras",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]


# A workaround for the responsive tables always having annoying scrollbars.
Expand All @@ -127,13 +127,13 @@ def setup(app):


def linkcode_resolve(domain, info):
if domain != 'py':
if domain != "py":
return None
if not info['module']:
if not info["module"]:
return None
if "." in info["fullname"]:
return None
filename = info['module'].replace('.', '/')
filename = info["module"].replace(".", "/")
if filename.endswith("widget"):
filename += f"/{widgets[info['fullname']]}"
return "https://github.com/elparaguayo/qtile-extras/tree/main/%s.py" % filename
16 changes: 8 additions & 8 deletions docs/sphinx_qtile_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,16 @@ def make_rst(self):
module = importlib.import_module(self.arguments[0])
exclude_base = "exclude-base" in self.options

BaseClass = None
base_class = None
if "baseclass" in self.options:
BaseClass = import_class(*self.options["baseclass"].rsplit(".", 1))
base_class = import_class(*self.options["baseclass"].rsplit(".", 1))

for item in dir(module):
obj = import_class(self.arguments[0], item)
if (
(not inspect.isclass(obj))
or (BaseClass and not issubclass(obj, BaseClass))
or (exclude_base and obj == BaseClass)
or (base_class and not issubclass(obj, base_class))
or (exclude_base and obj == base_class)
or (is_widget(obj) and item not in widgets)
):
continue
Expand Down Expand Up @@ -307,16 +307,16 @@ class ListObjects(SimpleDirectiveMixin, Directive):
def make_rst(self):
module = importlib.import_module(self.arguments[0])

BaseClass = None
base_class = None
if "baseclass" in self.options:
BaseClass = import_class(*self.options["baseclass"].rsplit(".", 1))
base_class = import_class(*self.options["baseclass"].rsplit(".", 1))
objects = []
for item in dir(module):
obj = import_class(self.arguments[0], item)
if (
(not inspect.isclass(obj))
or (BaseClass and not issubclass(obj, BaseClass))
or (obj == BaseClass)
or (base_class and not issubclass(obj, base_class))
or (obj == base_class)
or (is_widget(obj) and item not in widgets)
or getattr(obj, "_qte_compatibility", False)
):
Expand Down
2 changes: 1 addition & 1 deletion qtile_extras/popup/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def load_icon(self, icon):
filename = os.path.expanduser(self.menu_icon)

if not os.path.exists(filename):
logger.warning("Icon image does not exist: {}".format(filename))
logger.warning("Icon image does not exist: %s", filename)
return

img = Img.from_path(filename)
Expand Down
12 changes: 6 additions & 6 deletions qtile_extras/popup/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ def _set_updateable_controls(self):

if c.name in controls:
logger.warning(
f"There is an existing control named {c.name}. "
f"If you wish to update controls then they must have unique names."
"There is an existing control named %s. "
"If you wish to update controls then they must have unique names.",
c.name,
)
continue

Expand Down Expand Up @@ -316,7 +317,7 @@ def show(
y += scr.y + scr.height - self.popup.height

else:
logger.warning(f"Unexpected value for 'relative_to': {relative_to}.")
logger.warning("Unexpected value for 'relative_to': %s", relative_to)
x += scr.x
y += scr.y

Expand Down Expand Up @@ -717,8 +718,7 @@ def is_relative(val):
]
):
logger.warning(
"Control {} using non relative dimensions "
"in Relative layout".format(control)
"Control %s using non relative dimensions " "in Relative layout", control
)

control.offsetx = int(self._width * control.pos_x) + self.margin
Expand Down Expand Up @@ -940,7 +940,7 @@ def button_press(self, x, y, button):
(cmd.selectors, cmd.name, cmd.args, cmd.kwargs)
)
if status in (interface.ERROR, interface.EXCEPTION):
logger.error("KB command error %s: %s" % (cmd.name, val))
logger.error("KB command error %s: %s", cmd.name, val)
else:
cmd()

Expand Down
6 changes: 4 additions & 2 deletions qtile_extras/resources/dbusmenu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,13 @@ async def start(self):
self._interface = obj.get_interface(MENU_INTERFACE)
except InterfaceNotFoundError:
logger.warning(
f"Could not find {MENU_INTERFACE} interface at {self.service} and unable to use default spec."
"Could not find %s interface at %s and unable to use default spec.",
MENU_INTERFACE,
self.service,
)
return False
except (DBusError, InvalidIntrospectionError):
logger.warning(f"Path {self.path} does not present a valid dbusmenu object")
logger.warning("Path %s does not present a valid dbusmenu object", self.path)
return False

# Menus work by giving each menu item an ID and actions are
Expand Down
2 changes: 1 addition & 1 deletion qtile_extras/resources/global_menu/registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def _message_handler(self, message):
def RegisterWindow(self, windowId: "u", menuObjectPath: "o"): # type: ignore # noqa: F821, N802, N803
# This is silly, the spec says that apps should only provide
# windowId and menuObjectPath but we need to be able to return
# the the host service too but this isn't explicityly provided
# the host service too but this isn't explicityly provided
# and dbus-next's high-level service doesn't expose this part of
# the message. So... we expose the method here but don't do anything
# with it. We actually deal with the call in a low-level message
Expand Down
6 changes: 4 additions & 2 deletions qtile_extras/widget/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ def import_class(module_path, class_name, fallback=None):
return classdef

except ImportError as error:
logger.warning("Unmet dependencies for '%s.%s': %s", module_path, class_name, error)
logger.warning( # noqa: G200
"Unmet dependencies for '%s.%s': %s", module_path, class_name, error
)
if fallback:
logger.debug("%s", traceback.format_exc())
logger.debug("%s", traceback.format_exc()) # noqa: G200
return fallback(module_path, class_name)
raise

Expand Down
2 changes: 1 addition & 1 deletion qtile_extras/widget/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def loaded_images(self, task):
self.icons_loaded = task.result()

if not self.icons_loaded:
logger.error(f"Could not find volume icons at {self.theme_path}.")
logger.error("Could not find volume icons at %s.", self.theme_path)
return

self.bar.draw()
Expand Down
18 changes: 8 additions & 10 deletions qtile_extras/widget/brightnesscontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ async def _config_async(self):
def message(self, message):
self.update(*message.body)

def update(self, interface_name, changed_properties, invalidated_properties):
def update(self, _interface_name, changed_properties, _invalidated_properties):
if "OnBattery" not in changed_properties:
return

Expand All @@ -266,11 +266,9 @@ def update(self, interface_name, changed_properties, invalidated_properties):
percent = int(value[:-1])
self.set_brightness_percent(percent / 100)
except ValueError:
err = "Incorrectly formatted brightness: {}".format(value)
logger.error(err)
logger.error("Incorrectly formatted brightness: %s", value)
else:
err = "Unrecognised value for brightness: {}".format(value)
logger.warning(err)
logger.warning("Unrecognised value for brightness: %s", value)

self.onbattery = onbattery

Expand Down Expand Up @@ -394,13 +392,13 @@ def _read(self, path):
with open(path, "r") as b:
value = int(b.read())
except PermissionError:
logger.error("Unable to read {}.".format(path))
logger.error("Unable to read %s.", path)
value = False
except ValueError:
logger.error("Unexpected value when reading {}.".format(path))
logger.error("Unexpected value when reading %s.", path)
value = False
except Exception as e:
logger.error("Unexpected error when reading {}: {}.".format(path, e))
logger.error("Unexpected error when reading %s: %s.", path, e) # noqa: G200
value = False

return value
Expand Down Expand Up @@ -428,10 +426,10 @@ def _set_current(self, newval):
b.write(str(newval))
success = True
except PermissionError:
logger.error("No write access to {}.".format(self.bright_path))
logger.error("No write access to %s.", self.bright_path)
success = False
except Exception as e:
logger.error("Unexpected error when writing " "brightness value: {}.".format(e))
logger.error("Unexpected error when writing brightness value: %s.", e) # noqa: G200
success = False

return success
Expand Down
4 changes: 2 additions & 2 deletions qtile_extras/widget/decorations.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ def single_or_four(self, value, name: str):
elif len(value) == 4:
n, e, s, w = value
else:
logger.info(f"{name} should be a single number or a list of 1 or 4 values")
logger.info("%s should be a single number or a list of 1 or 4 values", name)
n = e = s = w = 0
else:
logger.info(f"{name} should be a single number or a list of 1 or 4 values")
logger.info("%s should be a single number or a list of 1 or 4 values", name)
n = e = s = w = 0

return [n, e, s, w]
Expand Down
2 changes: 1 addition & 1 deletion qtile_extras/widget/mixins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def __init__(self, **config):
"icon_theme": self.icon_theme,
}

self.menu: PopupMenu | None = None
self.menu = None

def set_menu_position(self, x: int, y: int) -> tuple[int, int]:
"""
Expand Down
4 changes: 2 additions & 2 deletions qtile_extras/widget/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def update(self):
else:
self.draw()

except Exception as e:
logger.warning(f"Couldn't get wifi info. {e}")
except Exception:
logger.exception("Couldn't get wifi info.")

def draw_wifi(self, percentage):
offset = self.padding_x
Expand Down
2 changes: 1 addition & 1 deletion qtile_extras/widget/scriptexit.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ def update(self):
subprocess.run(self.exit_script, check=True)
except subprocess.CalledProcessError:
raw = " ".join(self.exit_script)
logger.error("Exit script ({}) failed to run.".format(raw))
logger.error("Exit script (%s) failed to run.", raw)

QuickExit.update(self)
Loading

0 comments on commit 1c0b3e2

Please sign in to comment.