Skip to content

Commit

Permalink
fix(python): fix comparison to None
Browse files Browse the repository at this point in the history
from PEP8 (https://peps.python.org/pep-0008/#programming-recommendations):

> Comparisons to singletons like None should always be done with is or is not, never the equality operators.
  • Loading branch information
e-kwsm committed May 26, 2024
1 parent 9f7e69b commit d920ed0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions python_smi_tools/rocm_smi.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def getAllocatedMemoryPercent(device):
mem_use_pct = 0
if vram_used is None:
return allocated_memory_vram
if vram_used != None and vram_total != None and float(vram_total) != 0:
if vram_used is not None and vram_total is not None and float(vram_total) != 0:
# take floor of result (round down to nearest integer)
mem_use_pct = (100 * (float(vram_used) / float(vram_total))) // 1
allocated_memory_vram['value'] = mem_use_pct
Expand Down Expand Up @@ -503,7 +503,7 @@ def getProcessName(pid):
except subprocess.CalledProcessError as e:
pName = 'UNKNOWN'

if pName == None:
if pName is None:
pName = 'UNKNOWN'

# Remove the substrings surrounding from process name (b' and \n')
Expand Down Expand Up @@ -2378,7 +2378,7 @@ def getCoarseGrainUtil(device, typeName=None):
"""
timestamp = c_uint64(0)

if typeName != None:
if typeName is not None:

try:
i = utilization_counter_name.index(typeName)
Expand Down Expand Up @@ -3289,7 +3289,7 @@ def showWeightTopology(deviceList):
for gpu2 in deviceList:
if (gpu1 == gpu2):
printTableRow('%-12s', '0')
elif (gpu_links_weight[gpu1][gpu2] == None):
elif (gpu_links_weight[gpu1][gpu2] is None):
printTableRow('%-12s', 'N/A')
else:
printTableRow('%-12s', gpu_links_weight[gpu1][gpu2].value)
Expand Down Expand Up @@ -3335,7 +3335,7 @@ def showHopsTopology(deviceList):
for gpu2 in deviceList:
if (gpu1 == gpu2):
printTableRow('%-12s', '0')
elif (gpu_links_hops[gpu1][gpu2] == None):
elif (gpu_links_hops[gpu1][gpu2] is None):
printTableRow('%-12s', 'N/A')
else:
printTableRow('%-12s', gpu_links_hops[gpu1][gpu2].value)
Expand Down Expand Up @@ -4122,7 +4122,7 @@ def isConciseInfoRequested(args):
showPcieReplayCount(deviceList)
if args.showserial:
showSerialNumber(deviceList)
if args.showpids != None:
if args.showpids is not None:
showPids(args.showpids)
if args.showpidgpus or str(args.showpidgpus) == '[]':
showGpusByPid(args.showpidgpus)
Expand Down
2 changes: 1 addition & 1 deletion python_smi_tools/rsmiBindings.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initRsmiBindings(silent=False):
print(args)

rocm_smi_lib_path = os.getenv('ROCM_SMI_LIB_PATH')
if (rocm_smi_lib_path != None):
if (rocm_smi_lib_path is not None):
path_librocm = rocm_smi_lib_path
else:
path_librocm = os.path.dirname(os.path.realpath(__file__)) + '/../../@CMAKE_INSTALL_LIBDIR@/librocm_smi64.so.@VERSION_MAJOR@'
Expand Down
2 changes: 1 addition & 1 deletion python_smi_tools/rsmiBindingsInit.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initRsmiBindings(silent=False):
print(args)

rocm_smi_lib_path = os.getenv('ROCM_SMI_LIB_PATH')
if (rocm_smi_lib_path != None):
if (rocm_smi_lib_path is not None):
path_librocm = rocm_smi_lib_path
else:
path_librocm = os.path.dirname(os.path.realpath(__file__)) + '/../../@CMAKE_INSTALL_LIBDIR@/librocm_smi64.so.@VERSION_MAJOR@'
Expand Down

0 comments on commit d920ed0

Please sign in to comment.