[PATCH v1 1/2] usertools/cpu_layout: update coding style
Burakov, Anatoly
anatoly.burakov at intel.com
Mon Aug 19 11:36:44 CEST 2024
On 8/19/2024 11:26 AM, Robin Jarry wrote:
> Anatoly Burakov, Aug 14, 2024 at 13:19:
>> Update coding style:
>>
>> - make it PEP-484 compliant
>> - address all flake8, mypy etc. warnings
>> - use f-strings in place of old-style string interpolation
>> - refactor printing to make the code more readable
>>
>> Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
>> ---
>
> Hi Anatoly,
>
> thanks for the patch. Did you format the code using black/ruff? I'd like
> to start keeping python code formatting consistent across user tools.
I don't think I did any formatting with a specific tool. Rather, my IDE
had flake8 set up to give me warnings if there are issues with
formatting, and it also does formatting, so this would effectively be
the same thing.
Judging by description of Ruff, it sounds like something I should try
out, so thanks for the suggestion.
>
>> usertools/cpu_layout.py | 162 ++++++++++++++++++++++++++--------------
>> 1 file changed, 104 insertions(+), 58 deletions(-)
>>
>> diff --git a/usertools/cpu_layout.py b/usertools/cpu_layout.py
>> index 891b9238fa..843b29a134 100755
>> --- a/usertools/cpu_layout.py
>> +++ b/usertools/cpu_layout.py
>> @@ -3,62 +3,108 @@
>> # Copyright(c) 2010-2014 Intel Corporation
>> # Copyright(c) 2017 Cavium, Inc. All rights reserved.
>>
>> -output = " ".ljust(max_core_id_len + len('Core '))
>> -for s in sockets:
>> - output += " --------".ljust(max_core_map_len)
>> - output += " "
>> -print(output)
>> -
>> -for c in cores:
>> - output = "Core %s" % str(c).ljust(max_core_id_len)
>> - for s in sockets:
>> - if (s, c) in core_map:
>> - output += " " + str(core_map[(s,
>> c)]).ljust(max_core_map_len)
>> +from typing import List, Set, Dict, Tuple
>> +
>> +
>> +def _range_expand(rstr: str) -> List[int]:
>
> I don't see any reason to prefix the symbols with an underscore in this
> script. It will not be used as an importable library.
In the general case I prefer not to make such assumptions, but in this
particular case I think it's a safe assumption to make.
--
Thanks,
Anatoly
More information about the dev
mailing list