Skip to content

Commit

Permalink
Merge branch 'update-style'
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Feb 20, 2024
2 parents bb3d59a + 45c7fa4 commit ffb66ec
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 77 deletions.
20 changes: 11 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
10 changes: 6 additions & 4 deletions psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])})
Expand Down
15 changes: 9 additions & 6 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -2100,7 +2102,7 @@ def get_blocks(lines, current_block):
path
):
path = path[:-10]
ls.append((
item = (
decode(addr),
decode(perms),
path,
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions psutil/_pssunos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
12 changes: 7 additions & 5 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
12 changes: 7 additions & 5 deletions psutil/tests/test_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"???")
Expand Down
16 changes: 9 additions & 7 deletions psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
40 changes: 22 additions & 18 deletions psutil/tests/test_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 12 additions & 10 deletions scripts/top.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 11 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit ffb66ec

Please sign in to comment.