workhorsy / py-cpuinfo

A module for getting CPU info with pure Python
MIT License
314 stars 59 forks source link

Fix recognition of PowerPC in `cpuinfo.py` #217

Open barracuda156 opened 2 weeks ago

barracuda156 commented 2 weeks ago

In your bug report please include:

cpuinfo omits PPC/PPC_32 in the list which breaks dependents:

--->  Building py311-tables
Executing:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_python_py-tables/py311-tables/work/tables-3.9.2" && /opt/local/Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11 -m build --no-isolation --wheel --outdir /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_python_py-tables/py311-tables/work 
* Getting build dependencies for wheel...
cpuinfo failed, assuming no CPU features: py-cpuinfo currently only works on X86 and some ARM/PPC/S390X/MIPS/RISCV CPUs.
* Using Python 3.11.10 (main, Sep  7 2024, 10:26:54) [GCC 14.2.0]
* Found cython 3.0.11
* USE_PKGCONFIG: True
* Found HDF5 headers at ``/opt/local/include``, library at ``/opt/local/lib``.
.. WARNING:: Could not find the HDF5 runtime.
   The HDF5 shared library was *not* found in the default library
   paths. In case of runtime problems, please remember to install it.
* Found LZO 2 headers at ``/opt/local/include``, library at ``/opt/local/lib``.
.. WARNING:: Could not find the LZO 2 runtime.
   The LZO 2 shared library was *not* found in the default library
   paths. In case of runtime problems, please remember to install it.
* Skipping detection of LZO 1 since LZO 2 has already been found.
* Found bzip2 headers at ``/opt/local/include``, library at ``/opt/local/lib``.
* pkg-config library dirs for blosc: /opt/local/lib
* Found blosc headers at ``/opt/local/include``, library at ``/opt/local/lib``.
.. WARNING:: Could not find the blosc runtime.
   The blosc shared library was *not* found in the default library
   paths. In case of runtime problems, please remember to install it.
* pkg-config library dirs for blosc2: /opt/local/lib
* Run 'blosc2_find_directories_hook'
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
    main()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
    json_out["return_val"] = hook(**hook_input["kwargs"])
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyproject_hooks/_in_process/_in_process.py", line 143, in get_requires_for_build_wheel
    return hook(config_settings)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/setuptools/build_meta.py", line 333, in get_requires_for_build_wheel
    return self._get_build_requires(config_settings, requirements=[])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/setuptools/build_meta.py", line 303, in _get_build_requires
    self.run_setup()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/setuptools/build_meta.py", line 319, in run_setup
    exec(code, locals())
  File "<string>", line 817, in <module>
  File "<string>", line 455, in find_directories
  File "<string>", line 146, in blosc2_find_directories_hook
  File "<string>", line 101, in get_blosc2_directories
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/blosc2/__init__.py", line 15, in <module>
    import cpuinfo
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/cpuinfo/__init__.py", line 3, in <module>
    from cpuinfo.cpuinfo import *
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/cpuinfo/cpuinfo.py", line 2827, in <module>
    _check_arch()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/cpuinfo/cpuinfo.py", line 366, in _check_arch
    raise Exception("py-cpuinfo currently only works on X86 "
Exception: py-cpuinfo currently only works on X86 and some ARM/PPC/S390X/MIPS/RISCV CPUs.

ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel
Command failed:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_python_py-tables/py311-tables/work/tables-3.9.2" && /opt/local/Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11 -m build --no-isolation --wheel --outdir /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_python_py-tables/py311-tables/work 
Exit code: 1

In fact the arch is present just below in cpuinfo.py:

    # PPC
    elif re.match(r'^ppc32$|^prep$|^pmac$|^powermac$', arch_string_raw):
        arch = 'PPC_32'
        bits = 32

But it is broken by an earlier chunk:

# Make sure we are running on a supported system
def _check_arch():
    arch, bits = _parse_arch(DataSource.arch_string_raw)
    if not arch in ['X86_32', 'X86_64', 'ARM_7', 'ARM_8',
                   'PPC_64', 'S390X', 'MIPS_32', 'MIPS_64',
                   "RISCV_32", "RISCV_64"]:
        raise Exception("py-cpuinfo currently only works on X86 "
                        "and some ARM/PPC/S390X/MIPS/RISCV CPUs.")
barracuda156 commented 2 weeks ago

Not sure how to force it recognize the arch correctly upon parsing, but this hack works:

--- cpuinfo/cpuinfo.py  2022-10-26 03:07:15.000000000 +0800
+++ cpuinfo/cpuinfo.py  2024-11-08 17:01:28.000000000 +0800
@@ -361,7 +361,7 @@
 def _check_arch():
    arch, bits = _parse_arch(DataSource.arch_string_raw)
    if not arch in ['X86_32', 'X86_64', 'ARM_7', 'ARM_8',
-                  'PPC_64', 'S390X', 'MIPS_32', 'MIPS_64',
+                  'PPC_32', 'PPC_64', 'S390X', 'MIPS_32', 'MIPS_64',
                   "RISCV_32", "RISCV_64"]:
        raise Exception("py-cpuinfo currently only works on X86 "
                        "and some ARM/PPC/S390X/MIPS/RISCV CPUs.")
@@ -829,6 +829,9 @@
    elif re.match(r'^riscv64$|^riscv64be$', arch_string_raw):
        arch = 'RISCV_64'
        bits = 64
+   else:
+       arch = 'PPC_32'
+       bits = 32

    return (arch, bits)