py-cpuinfo
py-cpuinfo copied to clipboard
Stepping value of 0 is ignored in _copy_new_fields and _filter_dict_keys_with_empty_values
Working with py-cpuinfo:7.0.0 on a gitlab runner & they have cpu stepping value of zero.
A value of zero can be incorrectly ignored in a few places of the code path.
To reproduce this I removed all copy_new_fields lines except for 1 pointing to lscpu. Update DataSource lscpu to point at cat lscpu2 and assign 0 to stepping there:
DataSource.lscpu
@staticmethod def lscpu(): return _run_and_get_stdout(['cat', '/path/to/lscpu2'])
lscpu2
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 2 Core(s) per socket: 2 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 142 Model name: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz Stepping: 0 CPU MHz: 701.180 CPU max MHz: 3100.0000 CPU min MHz: 400.0000 BogoMIPS: 5399.81 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 3072K NUMA node0 CPU(s): 0-3 Flags: fpu vme de
For copy_new_fields my stripped down example is as follows:
testdict = {} new_dict = {'stepping':0} if new_dict.get('stepping', None): print("worked") testdict['stepping'] = new_dict['stepping'] else: print('not work') print(testdict)
Yields:
not work {}
Looks like I introduced this in #143 when trying to remove empty fields. I'll see if I can fix this.
Thanks
Sorry that took so long.
It should work correctly now. I updated the filter so it will be able to not filter out specific values such as:
_filter_dict_keys_with_empty_values(info, {'stepping':0, 'model':0, 'family':0})
Thanks for your help.