Package: python-cpuinfo
Version: 9.0.0+git20221119-3
Tags: ftbfs patch
Usertags: alpha
Severity: important

python-cpuinfo is missing code to detect Alpha CPUs.  The attached
patch adds such code.

Could you apply the patch soon as dependent packages fail to build
from source without it, for example, pytables, see:
https://buildd.debian.org/status/fetch.php?pkg=pytables&arch=alpha&ver=3.11.0-2&stamp=1772245356&raw=0

Example failure:

ERROR: test00_description 
(tables.tests.test_tables.CompressBlosc2TablesTestCase.test00_description)
Checking table description and descriptive fields.
[snip irrelevant part of python backtrace]
  File 
"/build/reproducible-path/pytables-3.11.0/.pybuild/cpython3_3.14/build/tables/leaf.py",
 line 446, in _calc_chunkshape
    cpu_info = get_cpu_info()
  File 
"/build/reproducible-path/pytables-3.11.0/.pybuild/cpython3_3.14/build/tables/leaf.py",
 line 64, in get_cpu_info
    import cpuinfo
  File "/usr/lib/python3/dist-packages/cpuinfo/__init__.py", line 2, in <module>
    from cpuinfo.cpuinfo import *
  File "/usr/lib/python3/dist-packages/cpuinfo/cpuinfo.py", line 2848, in 
<module>
    _check_arch()
    ~~~~~~~~~~~^^
  File "/usr/lib/python3/dist-packages/cpuinfo/cpuinfo.py", line 371, in 
_check_arch
    raise Exception("py-cpuinfo currently only works on X86 "
                "and some ARM/HPPA/LoongArch/MIPS/PPC/RISCV/SPARC/S390X CPUs." )
Exception: py-cpuinfo currently only works on X86 and some 
ARM/HPPA/LoongArch/MIPS/PPC/RISCV/SPARC/S390X CPUs.

Regards
Michael.
--- a/cpuinfo/cpuinfo.py
+++ b/cpuinfo/cpuinfo.py
@@ -359,7 +359,8 @@
 # Make sure we are running on a supported system
 def _check_arch():
 	arch, bits = _parse_arch(DataSource.arch_string_raw)
-	if not arch in ['ARM_7', 'ARM_8',
+	if not arch in ['ALPHA',
+                        'ARM_7', 'ARM_8',
 	                'HPPA_32', 'HPPA_64',
 	                'LOONG_32', 'LOONG_64',
 	                'MIPS_32', 'MIPS_64',
@@ -369,7 +370,7 @@
 	                'S390X',
 	                'X86_32', 'X86_64']:
 		raise Exception("py-cpuinfo currently only works on X86 "
-				"and some ARM/HPPA/LoongArch/MIPS/PPC/RISCV/SPARC/S390X CPUs." )
+				"and some ALPHA/ARM/HPPA/LoongArch/MIPS/PPC/RISCV/SPARC/S390X CPUs." )
 
 def _obj_to_b64(thing):
 	import pickle
@@ -793,6 +794,10 @@
 	elif re.match(r'^x64$|^x86_64$|^x86_64t$|^i686-64$|^amd64$|^ia64$|^ia-64$', arch_string_raw):
 		arch = 'X86_64'
 		bits = 64
+        # ALPHA
+	elif re.match(r'^alpha$', arch_string_raw):
+		arch = 'ALPHA'
+		bits = 64
 	# ARM
 	elif re.match(r'^armv8-a|aarch64|arm64$', arch_string_raw):
 		arch = 'ARM_8'
@@ -1745,14 +1750,17 @@
 			g_trace.fail('Failed to run cat /proc/cpuinfo. Skipping ...')
 			return {}
 
+
 		# Various fields
 		vendor_id = _get_field(False, output, None, '', 'vendor_id', 'vendor id', 'vendor')
 		processor_brand = _get_field(True, output, None, None, 'model name', 'cpu', 'processor', 'uarch')
+		if processor_brand == "Alpha":
+			processor_brand = _get_field(True, output, None, None, 'cpu model')
 		cache_size = _get_field(False, output, None, '', 'cache size')
 		stepping = _get_field(False, output, int, -1, 'stepping')
 		model = _get_field(False, output, int, -1, 'model')
 		family = _get_field(False, output, int, -1, 'cpu family')
-		hardware = _get_field(False, output, None, '', 'Hardware')
+		hardware = _get_field(False, output, None, '', 'Hardware', 'platform string')
 
 		# Flags
 		flags = _get_field(False, output, None, None, 'flags', 'Features', 'ASEs implemented')
@@ -1775,10 +1783,17 @@
 			except Exception:
 				pass
 
-		# Convert from MHz string to Hz
-		hz_actual = _get_field(False, output, None, '', 'cpu MHz', 'cpu speed', 'clock', 'cpu MHz dynamic', 'cpu MHz static')
-		hz_actual = hz_actual.lower().rstrip('mhz').strip()
-		hz_actual = _to_decimal_string(hz_actual)
+		# Frequency in Hz
+		hz_actual = _get_field(False, output, None, None, 'cycle frequency [Hz]');
+		if hz_actual:
+			hz_actual = _to_decimal_string(hz_actual)
+			hz_scale = 0
+		else:
+			# Convert from MHz string to Hz
+			hz_actual = _get_field(False, output, None, '', 'cpu MHz', 'cpu speed', 'clock', 'cpu MHz dynamic', 'cpu MHz static')
+			hz_actual = hz_actual.lower().rstrip('mhz').strip()
+			hz_actual = _to_decimal_string(hz_actual)
+			hz_scale = 6;
 
 		# Convert from GHz/MHz string to Hz
 		hz_advertised, scale = (None, 0)
@@ -1802,7 +1817,7 @@
 		# Make the Hz the same for actual and advertised if missing any
 		if not hz_advertised or hz_advertised == '0.0':
 			hz_advertised = hz_actual
-			scale = 6
+			scale = hz_scale
 		elif not hz_actual or hz_actual == '0.0':
 			hz_actual = hz_advertised
 
@@ -1811,8 +1826,8 @@
 			info['hz_advertised_friendly'] = _hz_short_to_friendly(hz_advertised, scale)
 			info['hz_advertised'] = _hz_short_to_full(hz_advertised, scale)
 		if _hz_short_to_full(hz_actual, scale) > (0, 0):
-			info['hz_actual_friendly'] = _hz_short_to_friendly(hz_actual, 6)
-			info['hz_actual'] = _hz_short_to_full(hz_actual, 6)
+			info['hz_actual_friendly'] = _hz_short_to_friendly(hz_actual, hz_scale)
+			info['hz_actual'] = _hz_short_to_full(hz_actual, hz_scale)
 
 		info = _filter_dict_keys_with_empty_values(info, {'stepping':0, 'model':0, 'family':0})
 		g_trace.success()
--- a/tests/test_invalid_cpu.py
+++ b/tests/test_invalid_cpu.py
@@ -33,4 +33,4 @@
 			cpuinfo._check_arch()
 			self.fail('Failed to raise Exception')
 		except Exception as err:
-			self.assertEqual('py-cpuinfo currently only works on X86 and some ARM/HPPA/LoongArch/MIPS/PPC/RISCV/SPARC/S390X CPUs.', err.args[0])
+			self.assertEqual('py-cpuinfo currently only works on X86 and some ALPHA/ARM/HPPA/LoongArch/MIPS/PPC/RISCV/SPARC/S390X CPUs.', err.args[0])

Reply via email to