From 45c7fa4d74b624f5ff630684bfc3bab48bfcefe4 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Sun, 18 Feb 2024 20:45:51 +0100 Subject: [PATCH] update style to latest black ver --- docs/conf.py | 20 ++++++++++-------- psutil/_common.py | 10 +++++---- psutil/_pslinux.py | 15 ++++++++------ psutil/_pssunos.py | 10 +++++---- psutil/tests/__init__.py | 12 ++++++----- psutil/tests/test_linux.py | 12 ++++++----- psutil/tests/test_process.py | 16 ++++++++------- psutil/tests/test_windows.py | 40 ++++++++++++++++++++---------------- scripts/top.py | 22 +++++++++++--------- setup.py | 20 ++++++++++-------- 10 files changed, 100 insertions(+), 77 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 3ebc64178..d94b93c65 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -344,15 +344,17 @@ def get_version(): # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) -texinfo_documents = [( - master_doc, - 'psutil', - 'psutil Documentation', - author, - 'psutil', - 'One line description of project.', - 'Miscellaneous', -)] +texinfo_documents = [ + ( + master_doc, + 'psutil', + 'psutil Documentation', + author, + 'psutil', + 'One line description of project.', + 'Miscellaneous', + ) +] # Documents to append as an appendix to all manuals. # diff --git a/psutil/_common.py b/psutil/_common.py index 6989feafd..7a53cc13b 100644 --- a/psutil/_common.py +++ b/psutil/_common.py @@ -269,10 +269,12 @@ class BatteryTime(enum.IntEnum): } if AF_INET6 is not None: - conn_tmap.update({ - "tcp6": ([AF_INET6], [SOCK_STREAM]), - "udp6": ([AF_INET6], [SOCK_DGRAM]), - }) + conn_tmap.update( + { + "tcp6": ([AF_INET6], [SOCK_STREAM]), + "udp6": ([AF_INET6], [SOCK_DGRAM]), + } + ) if AF_UNIX is not None: conn_tmap.update({"unix": ([AF_UNIX], [SOCK_STREAM, SOCK_DGRAM])}) diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 5d0deb403..41ecf0c90 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -1454,10 +1454,12 @@ def sensors_temperatures(): continue trip_paths = glob.glob(base + '/trip_point*') - trip_points = set([ - '_'.join(os.path.basename(p).split('_')[0:3]) - for p in trip_paths - ]) + trip_points = set( + [ + '_'.join(os.path.basename(p).split('_')[0:3]) + for p in trip_paths + ] + ) critical = None high = None for trip_point in trip_points: @@ -2100,7 +2102,7 @@ def get_blocks(lines, current_block): path ): path = path[:-10] - ls.append(( + item = ( decode(addr), decode(perms), path, @@ -2114,7 +2116,8 @@ def get_blocks(lines, current_block): data.get(b'Referenced:', 0), data.get(b'Anonymous:', 0), data.get(b'Swap:', 0), - )) + ) + ls.append(item) return ls @wrap_exceptions diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py index dddbece1f..3e72967a3 100644 --- a/psutil/_pssunos.py +++ b/psutil/_pssunos.py @@ -682,10 +682,12 @@ def connections(self, kind='inet'): # UNIX sockets if kind in ('all', 'unix'): - ret.extend([ - _common.pconn(*conn) - for conn in self._get_unix_sockets(self.pid) - ]) + ret.extend( + [ + _common.pconn(*conn) + for conn in self._get_unix_sockets(self.pid) + ] + ) return ret nt_mmap_grouped = namedtuple('mmap', 'path rss anon locked') diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index dd5a6c856..10f71cd39 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -1286,11 +1286,13 @@ def print_sysinfo(): info['kernel'] = platform.uname()[2] # python - info['python'] = ', '.join([ - platform.python_implementation(), - platform.python_version(), - platform.python_compiler(), - ]) + info['python'] = ', '.join( + [ + platform.python_implementation(), + platform.python_version(), + platform.python_compiler(), + ] + ) info['pip'] = getattr(pip, '__version__', 'not installed') if wheel is not None: info['pip'] += " (wheel=%s)" % wheel.__version__ diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py index 0583e619d..d133cd06f 100755 --- a/psutil/tests/test_linux.py +++ b/psutil/tests/test_linux.py @@ -120,7 +120,7 @@ def get_ipv4_broadcast(ifname): def get_ipv6_addresses(ifname): with open("/proc/net/if_inet6") as f: all_fields = [] - for line in f.readlines(): + for line in f: fields = line.split() if fields[-1] == ifname: all_fields.append(fields) @@ -1698,10 +1698,12 @@ def test_emulate_power_undetermined(self): # Pretend we can't know whether the AC power cable not # connected (assert fallback to False). def open_mock(name, *args, **kwargs): - if name.startswith(( - '/sys/class/power_supply/AC0/online', - '/sys/class/power_supply/AC/online', - )): + if name.startswith( + ( + '/sys/class/power_supply/AC0/online', + '/sys/class/power_supply/AC/online', + ) + ): raise IOError(errno.ENOENT, "") elif name.startswith("/sys/class/power_supply/BAT0/status"): return io.BytesIO(b"???") diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 35beb41e0..4e20f0e6b 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -1436,13 +1436,15 @@ def clean_dict(d): d.pop("__CF_USER_TEXT_ENCODING", None) d.pop("VERSIONER_PYTHON_PREFER_32_BIT", None) d.pop("VERSIONER_PYTHON_VERSION", None) - return dict([ - ( - k.replace("\r", "").replace("\n", ""), - v.replace("\r", "").replace("\n", ""), - ) - for k, v in d.items() - ]) + return dict( + [ + ( + k.replace("\r", "").replace("\n", ""), + v.replace("\r", "").replace("\n", ""), + ) + for k, v in d.items() + ] + ) self.maxDiff = None p = psutil.Process() diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py index 5983af70a..502d92638 100755 --- a/psutil/tests/test_windows.py +++ b/psutil/tests/test_windows.py @@ -869,25 +869,29 @@ def test_environ_64(self): @unittest.skipIf(not WINDOWS, "WINDOWS only") class TestServices(PsutilTestCase): def test_win_service_iter(self): - valid_statuses = set([ - "running", - "paused", - "start", - "pause", - "continue", - "stop", - "stopped", - ]) + valid_statuses = set( + [ + "running", + "paused", + "start", + "pause", + "continue", + "stop", + "stopped", + ] + ) valid_start_types = set(["automatic", "manual", "disabled"]) - valid_statuses = set([ - "running", - "paused", - "start_pending", - "pause_pending", - "continue_pending", - "stop_pending", - "stopped", - ]) + valid_statuses = set( + [ + "running", + "paused", + "start_pending", + "pause_pending", + "continue_pending", + "stop_pending", + "stopped", + ] + ) for serv in psutil.win_service_iter(): data = serv.as_dict() self.assertIsInstance(data['name'], str) diff --git a/scripts/top.py b/scripts/top.py index c0687ae1f..1caf9804d 100755 --- a/scripts/top.py +++ b/scripts/top.py @@ -82,16 +82,18 @@ def poll(interval): procs_status = {} for p in psutil.process_iter(): try: - p.dict = p.as_dict([ - 'username', - 'nice', - 'memory_info', - 'memory_percent', - 'cpu_percent', - 'cpu_times', - 'name', - 'status', - ]) + p.dict = p.as_dict( + [ + 'username', + 'nice', + 'memory_info', + 'memory_percent', + 'cpu_percent', + 'cpu_times', + 'name', + 'status', + ] + ) try: procs_status[p.dict['status']] += 1 except KeyError: diff --git a/setup.py b/setup.py index 7c59f5645..dac0a973a 100755 --- a/setup.py +++ b/setup.py @@ -213,15 +213,17 @@ def get_winver(): raise RuntimeError(msg) macros.append(("PSUTIL_WINDOWS", 1)) - macros.extend([ - # be nice to mingw, see: - # http://www.mingw.org/wiki/Use_more_recent_defined_functions - ('_WIN32_WINNT', get_winver()), - ('_AVAIL_WINVER_', get_winver()), - ('_CRT_SECURE_NO_WARNINGS', None), - # see: https://github.com/giampaolo/psutil/issues/348 - ('PSAPI_VERSION', 1), - ]) + macros.extend( + [ + # be nice to mingw, see: + # http://www.mingw.org/wiki/Use_more_recent_defined_functions + ('_WIN32_WINNT', get_winver()), + ('_AVAIL_WINVER_', get_winver()), + ('_CRT_SECURE_NO_WARNINGS', None), + # see: https://github.com/giampaolo/psutil/issues/348 + ('PSAPI_VERSION', 1), + ] + ) ext = Extension( 'psutil._psutil_windows',