Skip to content

Commit

Permalink
Satisfied new lint constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidy22 committed Sep 21, 2021
1 parent 362d67a commit 2cfc9b3
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 96 deletions.
12 changes: 3 additions & 9 deletions guake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ def vte_version():

from gi.repository import Vte

s = "{}.{}.{}".format(
Vte.MAJOR_VERSION,
Vte.MINOR_VERSION,
Vte.MICRO_VERSION,
)
s = f"{Vte.MAJOR_VERSION}.{Vte.MINOR_VERSION}.{Vte.MICRO_VERSION}"
return s


Expand All @@ -54,9 +50,7 @@ def vte_runtime_version():

from gi.repository import Vte

return "{}.{}.{}".format(
Vte.get_major_version(), Vte.get_minor_version(), Vte.get_micro_version()
)
return f"{Vte.get_major_version()}.{Vte.get_minor_version()}.{Vte.get_micro_version()}"


def gtk_version():
Expand All @@ -65,4 +59,4 @@ def gtk_version():
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

return "{}.{}.{}".format(Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION, Gtk.MICRO_VERSION)
return f"{Gtk.MAJOR_VERSION}.{Gtk.MINOR_VERSION}.{Gtk.MICRO_VERSION}"
2 changes: 1 addition & 1 deletion guake/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def on_search_on_web(self, *args):
query = clipboard.wait_for_text()
query = quote_plus(query)
if query:
search_url = "https://www.google.com/search?q={!s}&safe=off".format(query)
search_url = f"https://www.google.com/search?q={query}&safe=off"
Gtk.show_uri(self.window.get_screen(), search_url, get_server_time(self.window))

def on_quick_open(self, *args):
Expand Down
10 changes: 5 additions & 5 deletions guake/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def ShowableError(parent, title, msg, exit_code=1):
Gtk.MessageType.WARNING,
Gtk.ButtonsType.CLOSE,
)
d.set_markup("<b><big>%s</big></b>" % title)
d.set_markup(f"<b><big>{title}</big></b>")
d.format_secondary_markup(msg)
d.run()
d.destroy()
Expand All @@ -57,22 +57,22 @@ def ShowableError(parent, title, msg, exit_code=1):
def pixmapfile(x):
f = os.path.join(IMAGE_DIR, x)
if not os.path.exists(f):
raise IOError("No such file or directory: %s" % f)
raise IOError(f"No such file or directory: {f}")
return os.path.abspath(f)


def gladefile(x):
f = os.path.join(GLADE_DIR, x)
if not os.path.exists(f):
raise IOError("No such file or directory: %s" % f)
raise IOError(f"No such file or directory: {f}")
return os.path.abspath(f)


def hexify_color(c):
def h(x):
return hex(x).replace("0x", "").zfill(4)

return "#%s%s%s" % (h(c.red), h(c.green), h(c.blue))
return f"#{h(c.red)}{h(c.green)}{h(c.blue)}"


def get_binaries_from_path(compiled_re):
Expand All @@ -87,7 +87,7 @@ def get_binaries_from_path(compiled_re):

def shell_quote(text):
"""quote text (filename) for inserting into a shell"""
return r"\'".join("'%s'" % p for p in text.split("'"))
return r"\'".join(f"'{p}'" for p in text.split("'"))


def clamp(value, lower, upper):
Expand Down
2 changes: 1 addition & 1 deletion guake/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, parent, procs, tabs, notebooks):
proc_str = _("There are {0} processes still running").format(procs)

self.set_markup(primary_msg)
self.format_secondary_markup("<b>{0}{1}{2}.</b>".format(proc_str, tab_str, notebooks_str))
self.format_secondary_markup(f"<b>{proc_str}{tab_str}{notebooks_str}.</b>")

def quit(self):
"""Run the "are you sure" dialog for quitting Guake"""
Expand Down
2 changes: 1 addition & 1 deletion guake/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def bindtextdomain(app_name, locale_dir=None):

def is_run_from_git_workdir():
self_path = os.path.abspath(inspect.getfile(inspect.currentframe()))
return os.path.exists("%s.in" % self_path)
return os.path.exists(f"{self_path}.in")


NAME = "guake"
Expand Down
22 changes: 11 additions & 11 deletions guake/guake_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def set_bgcolor(self, bgcolor, current_terminal_only=False):
c.parse("#" + bgcolor)
bgcolor = c
if not isinstance(bgcolor, Gdk.RGBA):
raise TypeError("color should be Gdk.RGBA, is: {!r}".format(bgcolor))
raise TypeError(f"color should be Gdk.RGBA, is: {bgcolor}")
bgcolor = self._apply_transparency_to_color(bgcolor)
log.debug("setting background color to: %r", bgcolor)

Expand All @@ -433,7 +433,7 @@ def set_fgcolor(self, fgcolor, current_terminal_only=False):
c.parse("#" + fgcolor)
fgcolor = c
if not isinstance(fgcolor, Gdk.RGBA):
raise TypeError("color should be Gdk.RGBA, is: {!r}".format(fgcolor))
raise TypeError(f"color should be Gdk.RGBA, is: {fgcolor}")
log.debug("setting background color to: %r", fgcolor)

if current_terminal_only:
Expand Down Expand Up @@ -1266,9 +1266,7 @@ def search_on_web(self, *args):
if search_query:
# TODO search provider should be selectable (someone might
# prefer bing.com, the internet is a strange place ¯\_(ツ)_/¯ )
search_url = "https://www.google.com/search?q={!s}&safe=off".format(
search_query,
)
search_url = f"https://www.google.com/search?q={search_query}&safe=off"
Gtk.show_uri(self.window.get_screen(), search_url, get_server_time(self.window))
return True

Expand All @@ -1280,7 +1278,7 @@ def set_tab_position(self, *args):

def execute_hook(self, event_name):
"""Execute shell commands related to current event_name"""
hook = self.settings.hooks.get_string("{!s}".format(event_name))
hook = self.settings.hooks.get_string(f"{event_name}")
if hook is not None and hook != "":
hook = hook.split()
try:
Expand Down Expand Up @@ -1342,7 +1340,7 @@ def save_tabs(self, filename="session.json"):
if not self.get_xdg_config_directory().exists():
self.get_xdg_config_directory().mkdir(parents=True)
session_file = self.get_xdg_config_directory() / filename
with session_file.open("w") as f:
with session_file.open("w", encoding="utf-8") as f:
json.dump(config, f, ensure_ascii=False, indent=4)
log.info("Guake tabs saved to %s", session_file)

Expand All @@ -1351,14 +1349,14 @@ def restore_tabs(self, filename="session.json", suppress_notify=False):
if not session_file.exists():
log.info("Cannot find session.json file")
return
with session_file.open() as f:
with session_file.open(encoding="utf-8") as f:
try:
config = json.load(f)
except Exception:
log.warning("%s is broken", session_file)
shutil.copy(
session_file,
self.get_xdg_config_directory() / "{0}.bak".format(filename),
self.get_xdg_config_directory() / f"{filename}.bak",
)
img_filename = pixmapfile("guake-notification.png")
notifier.showMessage(
Expand Down Expand Up @@ -1436,9 +1434,11 @@ def restore_tabs(self, filename="session.json", suppress_notify=False):
log.warning("%s schema is broken", session_file)
shutil.copy(
session_file,
self.get_xdg_config_directory() / "{}.bak".format(filename),
self.get_xdg_config_directory() / f"{filename}.bak",
)
with (self.get_xdg_config_directory() / "{}.log.err".format(filename)).open("w") as f:
with (self.get_xdg_config_directory() / f"{filename}.log.err").open(
"w", encoding="utf-8"
) as f:
traceback.print_exc(file=f)
img_filename = pixmapfile("guake-notification.png")
notifier.showMessage(
Expand Down
18 changes: 9 additions & 9 deletions guake/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,10 @@ def main():
from guake import vte_version
from guake import vte_runtime_version

print("Guake Terminal: {}".format(guake_version()))
print("VTE: {}".format(vte_version()))
print("VTE runtime: {}".format(vte_runtime_version()))
print("Gtk: {}".format(gtk_version()))
print(f"Guake Terminal: {guake_version()}")
print(f"VTE: {vte_version()}")
print(f"VTE runtime: {vte_runtime_version()}")
print(f"Gtk: {gtk_version()}")
sys.exit(0)

if options.save_preferences and options.restore_preferences:
Expand Down Expand Up @@ -496,17 +496,17 @@ def main():
if 0 <= selected < tab_count:
remote_object.select_tab(selected)
else:
sys.stderr.write("invalid index: %d\n" % selected)
sys.stderr.write(f"invalid index: {selected}\n")
only_show_hide = options.show

if options.selected_tab:
selected = remote_object.get_selected_tab()
sys.stdout.write("%d\n" % selected)
sys.stdout.write(f"{selected}\n")
only_show_hide = options.show

if options.selected_tablabel:
selectedlabel = remote_object.get_selected_tablabel()
sys.stdout.write("%s\n" % selectedlabel)
sys.stdout.write(f"{selectedlabel}\n")
only_show_hide = options.show

if options.split_vertical:
Expand All @@ -519,7 +519,7 @@ def main():

if options.selected_terminal:
selected = remote_object.get_selected_terminal()
sys.stdout.write("%d\n" % selected)
sys.stdout.write(f"{selected}\n")
only_show_hide = options.show

if options.select_terminal:
Expand All @@ -528,7 +528,7 @@ def main():
if 0 <= selected < term_count:
remote_object.select_terminal(selected)
else:
sys.stderr.write("invalid index: %d\n" % selected)
sys.stderr.write(f"invalid index: {selected}\n")
only_show_hide = options.show

if options.command:
Expand Down
2 changes: 1 addition & 1 deletion guake/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def get_current_notebook(self):
return self.get_notebook(self.current_notebook)

def has_notebook_for_workspace(self, workspace_index):
return workspace_index in self.notebooks.keys()
return workspace_index in self.notebooks

def set_workspace(self, index: int):
self.notebook_parent.remove(self.get_current_notebook())
Expand Down
8 changes: 4 additions & 4 deletions guake/prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def on_palette_color_set(self, btn):

palette = []
for i in range(18):
palette.append(hexify_color(self.get_widget("palette_%d" % i).get_color()))
palette.append(hexify_color(self.get_widget(f"palette_{i}").get_color()))
palette = ":".join(palette)
self.settings.styleFont.set_string("palette", palette)
self.settings.styleFont.set_string("palette-name", _("Custom"))
Expand Down Expand Up @@ -901,7 +901,7 @@ def set_palette_colors(self, palette):
palette = palette.split(":")
for i, pal in enumerate(palette):
x, color = Gdk.Color.parse(pal)
self.get_widget("palette_%d" % i).set_color(color)
self.get_widget(f"palette_{i}").set_color(color)

def reload_erase_combos(self, btn=None):
"""Read from dconf the value of compat_{backspace,delete} vars
Expand Down Expand Up @@ -1119,7 +1119,7 @@ def load_configs(self):
text = Gtk.TextBuffer()
text = self.get_widget("quick_open_supported_patterns").get_buffer()
for title, matcher, _useless in QUICK_OPEN_MATCHERS:
text.insert_at_cursor("%s: %s\n" % (title, matcher))
text.insert_at_cursor(f"{title}: {matcher}\n")
self.get_widget("quick_open_supported_patterns").set_buffer(text)

value = self.settings.general.get_string("quick-open-command-line")
Expand Down Expand Up @@ -1400,7 +1400,7 @@ def __init__(self, keycode, mask):
self.mask = mask

def __repr__(self):
return "KeyEntry(%d, %d)" % (self.keycode, self.mask)
return f"KeyEntry({self.keycode}, {self.mask})"

def __eq__(self, rval):
return self.keycode == rval.keycode and self.mask == rval.mask
Expand Down
8 changes: 3 additions & 5 deletions guake/simplegladeapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ def __repr__(self):
class_name = self.__class__.__name__
if self.main_widget:
root = Gtk.Widget.get_name(self.main_widget)
repr = '%s(path="%s", root="%s")' % (class_name, self.glade_path, root)
else:
repr = '%s(path="%s")' % (class_name, self.glade_path)
return repr
return f'{class_name}(path="{self.glade_path}", root="{root}")'
return f'{class_name}(path="{self.glade_path}")'

def add_callbacks(self, callbacks_proxy):
"""
Expand Down Expand Up @@ -118,7 +116,7 @@ def normalize_names(self):
widget_name = Gtk.Buildable.set_name(widget, widget_api_name)
if hasattr(self, widget_api_name):
raise AttributeError(
"instance %s already has an attribute %s" % (self, widget_api_name)
f"instance {self} already has an attribute {widget_api_name}"
)
setattr(self, widget_api_name, widget)
if prefixes:
Expand Down
50 changes: 19 additions & 31 deletions guake/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,75 +20,63 @@ def horizonal_line():

def populate_display(display):
screen = display.get_default_screen()
print("Display: {}".format(display.get_name()))
print(f"Display: {display.get_name()}")
print()
# pylint: disable=R1719
print("RGBA visual: {}".format(True if screen.get_rgba_visual() else False))
print(f"RGBA visual: {True if screen.get_rgba_visual() else False}")
print()
print("Composited: {}".format(screen.is_composited()))
print(f"Composited: {screen.is_composited()}")
print()

n_monitors = display.get_n_monitors()
for i in range(n_monitors):
monitor = display.get_monitor(i)
manufacturer = monitor.get_manufacturer()
model = monitor.get_model()
v = "%s%s%s" % (
manufacturer if manufacturer else "",
" " if manufacturer or model else "",
model if model else "",
)
print("* Monitor: {} - {}".format(i, v))
v = " ".join(j for j in (monitor.get_manufacturer(), monitor.get_model()) if j)
print(f"* Monitor: {i} - {v}")

# Geometry
rect = monitor.get_geometry()
scale = monitor.get_scale_factor()
v = "%d x %d%s at %d, %d" % (
rect.width,
rect.height,
" % 2" if scale == 2 else "",
rect.x,
rect.y,
)
print(" * Geometry:\t\t{}".format(v))
v = f"{rect.width} x {rect.height}{' % 2' if scale == 2 else ''} at {rect.x}, {rect.y}"
print(f" * Geometry:\t\t{v}")

# Size
v = "%d x %d mm²" % (monitor.get_width_mm(), monitor.get_height_mm())
print(" * Size:\t\t{}".format(v))
v = f"{monitor.get_width_mm()} x {monitor.get_height_mm()} mm²"
print(f" * Size:\t\t{v}")

# Primary
print(" * Primary:\t\t{}".format(monitor.is_primary()))
print(f" * Primary:\t\t{monitor.is_primary()}")

# Refresh rate
if monitor.get_refresh_rate():
v = "%.2f Hz" % (0.001 * monitor.get_refresh_rate())
v = f"{0.001 * monitor.get_refresh_rate()} Hz"
else:
v = "unknown"
print(" * Refresh rate:\t{}".format(v))
print(f" * Refresh rate:\t{v}")

# Subpixel layout
print(" * Subpixel layout:\t{}".format(monitor.get_subpixel_layout().value_nick))
print(f" * Subpixel layout:\t{monitor.get_subpixel_layout().value_nick}")


def get_version():
display = Gdk.Display.get_default()

print("Guake Version:\t\t{}".format(guake_version()))
print(f"Guake Version:\t\t{guake_version()}")
print()
print("Vte Version:\t\t{}".format(vte_version()))
print(f"Vte Version:\t\t{vte_version()}")
print()
print("Vte Runtime Version:\t{}".format(vte_runtime_version()))
print(f"Vte Runtime Version:\t{vte_runtime_version()}")
print()
horizonal_line()
print("GTK+ Version:\t\t{}".format(gtk_version()))
print(f"GTK+ Version:\t\t{gtk_version()}")
print()
print("GDK Backend:\t\t{}".format(str(display).split(" ", maxsplit=1)[0]))
print(f"GDK Backend:\t\t{str(display).split(' ', maxsplit=1)[0]}")
print()
horizonal_line()


def get_desktop_session():
print("Desktop Session: {}".format(os.environ.get("DESKTOP_SESSION")))
print(f"Desktop Session: {os.environ.get('DESKTOP_SESSION')}")
print()
horizonal_line()

Expand Down
Loading

0 comments on commit 2cfc9b3

Please sign in to comment.