Skip to content

Commit

Permalink
[#414] Removed all the # noqa: SC100 comments as it is better to ad…
Browse files Browse the repository at this point in the history
…just linting settings to ignore spell check.
  • Loading branch information
eoyilmaz committed Oct 24, 2024
1 parent 561e825 commit eabc81b
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 168 deletions.
20 changes: 10 additions & 10 deletions DisplayCAL/RealDisplaySizeMM.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def get_display(display_no=0):
if _displays is None:
return None

# Translate from Argyll display index to enumerated display index using the # noqa: SC100
# Translate from Argyll display index to enumerated display index using the
# coordinates and dimensions
from DisplayCAL.config import getcfg, is_virtual_display

Expand Down Expand Up @@ -286,14 +286,14 @@ def get_wayland_display(x, y, w, h):
Given x, y, width and height of display geometry, find matching Wayland display.
"""
# Note that we apparently CANNOT use width and height because the reported
# values from Argyll code and Mutter can be slightly different, # noqa: SC100
# e.g. 3660x1941 from Mutter vs 3656x1941 from Argyll when HiDPI is enabled. # noqa: SC100
# The xrandr output is also interesting in that case: # noqa: SC100
# $ xrandr # noqa: SC100
# values from Argyll code and Mutter can be slightly different,
# e.g. 3660x1941 from Mutter vs 3656x1941 from Argyll when HiDPI is enabled.
# The xrandr output is also interesting in that case:
# $ xrandr
# Screen 0: minimum 320 x 200, current 3660 x 1941, maximum 8192 x 8192
# XWAYLAND0 connected 3656x1941+0+0 (normal left inverted right x axis y axis) 0mm x 0mm # noqa: SC100,B950
# 3656x1941 59.96*+ # noqa: SC100
# Note the apparent mismatch between first and 2nd/3rd line. # noqa: SC100
# XWAYLAND0 connected 3656x1941+0+0 (normal left inverted right x axis y axis) 0mm x 0mm,B950
# 3656x1941 59.96*+
# Note the apparent mismatch between first and 2nd/3rd line.
# Look for active display at x, y instead.
# Currently, only support for GNOME 3 / Mutter
try:
Expand All @@ -318,10 +318,10 @@ def get_wayland_display(x, y, w, h):
def find_matching_output(res, x, y):
"""Find the matching output in the resources."""
crtcs = res[1]
# Look for matching CRTC # noqa: SC100
# Look for matching CRTC
for crtc in crtcs:
if crtc[2:4] == (x, y) and crtc[6] != -1:
# Found our CRTC # noqa: SC100
# Found our CRTC
crtc_id = crtc[0]
# Look for matching output
outputs = res[2]
Expand Down
120 changes: 60 additions & 60 deletions DisplayCAL/config.py

Large diffs are not rendered by default.

32 changes: 17 additions & 15 deletions DisplayCAL/dev/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,36 @@

import contextlib
from types import ModuleType
from typing import Any, Dict, Generator, List, Tuple, Type, overload
from typing import Any, Callable, Dict, Generator, List, Tuple, Type, overload

from _pytest.monkeypatch import MonkeyPatch
from mypy_extensions import KwArg, VarArg

Call = Tuple[Tuple[Any, ...], Dict[str, Any]]
CallList = List[Call]


@overload
@contextlib.contextmanager
def _mp_call( # noqa: E704
def _mp_call(
monkeypatch: MonkeyPatch,
mock_class: Type[Any] | ModuleType,
method: str,
return_value: Any,
as_property: bool,
) -> Generator[CallList, None, None]: ...
) -> Generator[CallList, None, None]:
...


@overload
@contextlib.contextmanager
def _mp_call( # noqa: E704
def _mp_call(
monkeypatch: MonkeyPatch,
mock_class: str,
method: Any, # return value in this case
return_value: bool, # as_property in this case
) -> Generator[CallList, None, None]: ...
) -> Generator[CallList, None, None]:
...


@contextlib.contextmanager
Expand All @@ -46,8 +49,7 @@ def _mp_call(
return_value: Any,
as_property: bool = False,
) -> Generator[CallList, None, None]:
"""
Mock a method in a class and record the calls to it.
"""Mock a method in a class and record the calls to it.
If the given return_value is an Exception, it will be raised.
If not, the value will be returned from the mocked function/method.
Expand All @@ -58,8 +60,8 @@ def func_call(*a: Any, **k: Any) -> Any:
"""Mock the function call."""
calls.append((a, k))
if isinstance(return_value, Exception):
# bug in pylint https://www.logilab.org/ticket/3207 # noqa: SC100
raise return_value # pylint: disable-msg=raising-bad-type # noqa: SC100
# bug in pylint https://www.logilab.org/ticket/3207
raise return_value # pylint: disable-msg=raising-bad-type
if callable(return_value):
# Handle the case that a function was passed
return return_value(*a, **k)
Expand All @@ -83,7 +85,7 @@ def func_call(*a: Any, **k: Any) -> Any:


@contextlib.contextmanager
def check_call( # pylint: disable=too-many-arguments # noqa: SC100
def check_call( # pylint: disable=too-many-arguments
mock_class: Type[Any] | ModuleType,
method: str,
return_value: Any = None,
Expand All @@ -110,9 +112,9 @@ def check_call( # pylint: disable=too-many-arguments
"call_args and call_kwargs must be None or have a value " "(list/dict if empty)"
)
monkeypatch = MonkeyPatch()
with _mp_call(monkeypatch, mock_class, method, return_value, as_property) as calls:
calls = _mp_call(monkeypatch, mock_class, method, return_value, as_property)
try:
yield calls
yield calls
finally:
m_name = f"{mock_class.__name__}.{method}"
monkeypatch.undo()
Expand All @@ -122,7 +124,7 @@ def check_call( # pylint: disable=too-many-arguments
# Duplicate the code because overloading is a mess due to this bug:
# https://github.com/python/mypy/issues/11373
@contextlib.contextmanager
def check_call_str( # pylint: disable=too-many-arguments # noqa: SC100
def check_call_str( # pylint: disable=too-many-arguments
mock_class: str,
return_value: Any = None,
call_args_list: List[Tuple[Any, ...]] | None = None,
Expand All @@ -141,8 +143,8 @@ def check_call_str( # pylint: disable=too-many-arguments
"call_args and call_kwargs must be None or have a value " "(list/dict if empty)"
)
monkeypatch = MonkeyPatch()
with _mp_call(monkeypatch, mock_class, return_value, as_property) as calls:
yield calls
calls = _mp_call(monkeypatch, mock_class, return_value, as_property)
yield calls
m_name = mock_class
monkeypatch.undo()
assert_calls(call_count, call_args_list, call_kwargs_list, calls, m_name)
Expand Down
14 changes: 7 additions & 7 deletions DisplayCAL/display_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import urllib.error
import urllib.parse
import urllib.request
import webbrowser # Import the webbrowser module for platform-independent results # noqa: SC100
import webbrowser # Import the webbrowser module for platform-independent results
import zipfile
from decimal import Decimal
from hashlib import md5
Expand Down Expand Up @@ -252,7 +252,7 @@

from send2trash import send2trash

# wxPython # noqa: SC100
# wxPython
from wx import xrc
from wx.lib import delayedresult, platebtn
from wx.lib.art import flagart
Expand Down Expand Up @@ -288,15 +288,15 @@
except ImportError:
ProfileInfoFrame = None

# wxPython # noqa: SC100
# wxPython
try:
# Only wx.lib.aui.AuiNotebook looks reasonable across _all_ platforms. # noqa: SC100
# Other tabbed book controls like wx.Notebook or wx.aui.AuiNotebook are # noqa: SC100
# impossible to get to look right under GTK because there's no way to set # noqa: SC100
# Only wx.lib.aui.AuiNotebook looks reasonable across _all_ platforms.
# Other tabbed book controls like wx.Notebook or wx.aui.AuiNotebook are
# impossible to get to look right under GTK because there's no way to set
# the correct background color for the pages.
from wx.lib.agw import aui
except ImportError:
# Fall back to wx.aui under ancient wxPython versions # noqa: SC100
# Fall back to wx.aui under ancient wxPython versions
from wx import aui

# Set no delay time to open the web page
Expand Down
24 changes: 12 additions & 12 deletions DisplayCAL/edid.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@
import pythoncom
import threading

# Use registry as fallback for Win2k/XP/2003 # noqa: SC100
# Use registry as fallback for Win2k/XP/2003
import winreg

wmi = None
if sys.getwindowsversion() >= (6,):
# Use WMI for Vista/Win7 # noqa: SC100
# Use WMI for Vista/Win7
try:
import wmi
except Exception:
Expand Down Expand Up @@ -232,7 +232,7 @@ def get_edid_windows(display_no, device):
edid = None

if not device:
# The ordering will work as long as Argyll continues using EnumDisplayMonitors # noqa: SC100
# The ordering will work as long as Argyll continues using EnumDisplayMonitors
monitors = util_win.get_real_display_devices_info()
moninfo = monitors[display_no]
device = util_win.get_active_display_device(moninfo["Device"])
Expand Down Expand Up @@ -288,7 +288,7 @@ def get_edid_windows_wmi(id, wmi_connection, not_main_thread):
try:
edid = msmonitor.WmiGetMonitorRawEEdidV1Block(0)
except Exception:
# No EDID entry # noqa: SC100
# No EDID entry
pass
else:
edid = "".join(chr(i) for i in edid[0])
Expand Down Expand Up @@ -366,7 +366,7 @@ def get_edid_windows_registry(id, device):
try:
edid = winreg.QueryValueEx(devparms, "EDID")[0]
except WindowsError:
# No EDID entry # noqa: SC100
# No EDID entry
pass
else:
return edid
Expand Down Expand Up @@ -584,9 +584,9 @@ def get_pnpid_paths():
list: List of possible paths.
"""
paths = [
"/usr/lib/udev/hwdb.d/20-acpi-vendor.hwdb", # systemd # noqa: SC100
"/usr/share/hwdata/pnp.ids", # hwdata, e.g. Red Hat # noqa: SC100
"/usr/share/misc/pnp.ids", # pnputils, e.g. Debian # noqa: SC100
"/usr/lib/udev/hwdb.d/20-acpi-vendor.hwdb", # systemd
"/usr/share/hwdata/pnp.ids", # hwdata, e.g. Red Hat
"/usr/share/misc/pnp.ids", # pnputils, e.g. Debian
"/usr/share/libgnome-desktop/pnp.ids",
] # fallback gnome-desktop
if sys.platform in ("darwin", "win32"):
Expand Down Expand Up @@ -709,7 +709,7 @@ def edid_parse_string(desc):
Returns:
bytes: The parsed string.
"""
# Return value should match colord's cd_edid_parse_string in cd-edid.c # noqa: SC100
# Return value should match colord's cd_edid_parse_string in cd-edid.c
# Remember: In C, NULL terminates a string, so do the same here
# Replace newline with NULL
desc = desc[:13].replace(b"\n", b"\x00").replace(b"\r", b"\x00")
Expand Down Expand Up @@ -774,7 +774,7 @@ def fix_edid_encoding(edid):
"""
# this is probably encoded/decoded in a wrong way and contains 2-bytes characters
#
# b"\xc2" and b"\xc3" are codepoints # noqa: SC100
# b"\xc2" and b"\xc3" are codepoints
# they can only appear if the byte data is decoded with latin-1 and encoded
# back with utf-8.
# This apparently is a wrong conversion.
Expand Down Expand Up @@ -935,8 +935,8 @@ def parse_color_point_data(block):
"""
result = {}
for i in (5, 10):
# 2nd white point index in range 1...255 # noqa: SC100
# 3rd white point index in range 2...255 # noqa: SC100
# 2nd white point index in range 1...255
# 3rd white point index in range 2...255
# 0 = do not use
if block[i] > i / 5:
white_x = edid_decode_fraction(
Expand Down
4 changes: 2 additions & 2 deletions DisplayCAL/lib/agw/pygauge.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# ---------------------------------------------------------------------------- #
# PYGAUGE wxPython IMPLEMENTATION # noqa: SC100
# PYGAUGE wxPython IMPLEMENTATION
#
# Mark Reed, @ 28 Jul 2010
# Latest Revision: 27 Dec 2012, 21.00 GMT
#
# TODO List
#
# 1. Indeterminate mode (see wx.Gauge) # noqa: SC100
# 1. Indeterminate mode (see wx.Gauge)
# 2. Vertical bar
# 3. Bitmap support (bar, background)
# 4. UpdateFunction - Pass a function to PyGauge which will be called every X
Expand Down
36 changes: 18 additions & 18 deletions DisplayCAL/util_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def listdir(path, *args, **kwargs):
"""
paths = _listdir(path, *args, **kwargs)
if isinstance(path, str):
# Undecodable filenames will still be string objects. # noqa: SC100
# Undecodable filenames will still be string objects.
# Ignore them.
paths = [path for path in paths if isinstance(path, str)]
return paths
Expand Down Expand Up @@ -247,24 +247,24 @@ def find_library(pattern, arch=None):
except Exception:
pass
else:
# /usr/bin/python3.7: ELF 64-bit LSB shared object, x86-64, # noqa: SC100
# version 1 (SYSV), dynamically linked, interpreter # noqa: SC100
# /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, # noqa: SC100
# BuildID[sha1]=41a1f0d4da3afee8f22d1947cc13a9f33f59f2b8, # noqa: SC100
# /usr/bin/python3.7: ELF 64-bit LSB shared object, x86-64,
# version 1 (SYSV), dynamically linked, interpreter
# /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0,
# BuildID[sha1]=41a1f0d4da3afee8f22d1947cc13a9f33f59f2b8,
# stripped
parts = file_stdout.split(",")
if len(parts) > 1:
arch = parts[1].strip()

for line in stdout.decode().splitlines():
# libxyz.so (libc6,x86_64) => /lib64/libxyz.so.1 # noqa: SC100
# libxyz.so (libc6,x86_64) => /lib64/libxyz.so.1
parts = line.split("=>", 1)
candidate = parts[0].split(None, 1)
if len(parts) < 2 or len(candidate) < 2:
continue
info = candidate[1].strip("( )").split(",")
if arch and len(info) > 1 and info[1].strip() != arch:
# Skip libs for wrong arch # noqa: SC100
# Skip libs for wrong arch
continue
filename = candidate[0]
if fnmatch.fnmatch(filename, pattern):
Expand Down Expand Up @@ -588,8 +588,8 @@ def launch_file(filepath):
if sys.platform == "darwin":
retcode = sp.call(["open", filepath], **kwargs)
elif sys.platform == "win32":
# for win32, we could use os.startfile, # noqa: SC100
# but then we'd not be able to return exitcode (does it matter?) # noqa: SC100
# for win32, we could use os.startfile,
# but then we'd not be able to return exitcode (does it matter?)
retcode = sp.call(f'start "" "{filepath}"', **kwargs)
elif which("xdg-open"):
retcode = sp.call(["xdg-open", filepath], **kwargs)
Expand Down Expand Up @@ -843,7 +843,7 @@ def readlink(path):

# This wouldn't return true if the file didn't exist
if not islink(path):
# Mimic POSIX error # noqa: SC100
# Mimic POSIX error
raise OSError(22, "Invalid argument", path)

# Open the file correctly depending on the string type.
Expand All @@ -852,11 +852,11 @@ def readlink(path):
else:
createfilefn = win32file.CreateFile

# Create a PySECURITY_ATTRIBUTES object # noqa: SC100
# Create a PySECURITY_ATTRIBUTES object
security_attributes = win32security.SECURITY_ATTRIBUTES()

# FILE_FLAG_OPEN_REPARSE_POINT alone is not enough if 'path' is a symbolic # noqa: SC100
# link to a directory or a NTFS junction. # noqa: SC100
# FILE_FLAG_OPEN_REPARSE_POINT alone is not enough if 'path' is a symbolic
# link to a directory or a NTFS junction.
# We need to set FILE_FLAG_BACKUP_SEMANTICS as well. See
# https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-createfilea
# Now use this security_attributes object in the CreateFileW call
Expand All @@ -878,7 +878,7 @@ def readlink(path):
else:
handle = int(str(handle))

# MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16384 = (16 * 1024) # noqa: SC100
# MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16384 = (16 * 1024)
buf = win32file.DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, None, 16 * 1024)
# Above will return an ugly string (byte array), so we'll need to parse it.

Expand Down Expand Up @@ -977,9 +977,9 @@ def safe_iglob(pathname):
for name in safe_glob1(os.curdir, basename):
yield name
return
# `os.path.split()` returns the argument itself as a dirname if it is a # noqa: SC100
# drive or UNC path. # noqa: SC100
# Prevent an infinite recursion if a drive or UNC path contains magic # noqa: SC100
# `os.path.split()` returns the argument itself as a dirname if it is a
# drive or UNC path.
# Prevent an infinite recursion if a drive or UNC path contains magic
# characters (i.e. r'\\?\C:').
if dirname != pathname and glob.has_magic(dirname):
dirs = safe_iglob(dirname)
Expand Down Expand Up @@ -1047,7 +1047,7 @@ def safe_shell_filter(names, pat):
_cache[pat] = re_pat = re.compile(res)
match = re_pat.match
if os.path is posixpath:
# normcase on posix is NOP. Optimize it away from the loop. # noqa: SC100
# normcase on posix is NOP. Optimize it away from the loop.
for name in names:
if match(name):
result.append(name)
Expand Down
Loading

0 comments on commit eabc81b

Please sign in to comment.