Bug 2050143

Summary: kicad fails to build with Python 3.11: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_code'
Product: [Fedora] Fedora Reporter: Tomáš Hrnčiar <thrnciar>
Component: kicadAssignee: Steven A. Falco <stevenfalco>
Status: CLOSED WORKSFORME QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 36CC: aimylios, alain.vigne.14, gmarr, kiarakovalevsky, mhroncok, stevenfalco, thibault, thrnciar
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-06-21 21:02:31 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2016048, 2045102, 2045109    

Description Tomáš Hrnčiar 2022-02-03 10:54:15 UTC
kicad fails to build with Python 3.11.0a4.

/builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/detail/type_caster_base.h: In function 'std::string pybind11::detail::error_string()':
/builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/detail/type_caster_base.h:448:38: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_code'
  448 |                 "  " + handle(frame->f_code->co_filename).cast<std::string>() +
      |                                      ^~~~~~
/builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/detail/type_caster_base.h:448:75: error: expected primary-expression before '>' token
  448 |                 "  " + handle(frame->f_code->co_filename).cast<std::string>() +
      |                                                                           ^
/builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/detail/type_caster_base.h:448:77: error: expected primary-expression before ')' token
  448 |                 "  " + handle(frame->f_code->co_filename).cast<std::string>() +
      |                                                                             ^
/builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/detail/type_caster_base.h:450:31: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_code'
  450 |                 handle(frame->f_code->co_name).cast<std::string>() + "\n";
      |                               ^~~~~~
/builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/detail/type_caster_base.h:450:64: error: expected primary-expression before '>' token
  450 |                 handle(frame->f_code->co_name).cast<std::string>() + "\n";
      |                                                                ^
/builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/detail/type_caster_base.h:450:66: error: expected primary-expression before ')' token
  450 |                 handle(frame->f_code->co_name).cast<std::string>() + "\n";
      |                                                                  ^
/builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/pybind11.h: In function 'pybind11::function pybind11::detail::get_type_override(const void*, const type_info*, const char*)':
/builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/pybind11.h:2163:49: error: 'PyThreadState' {aka 'struct _ts'} has no member named 'frame'; did you mean 'cframe'?
 2163 |     PyFrameObject *frame = PyThreadState_Get()->frame;
      |                                                 ^~~~~
      |                                                 cframe
/builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/pybind11.h:2164:54: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_code'
 2164 |     if (frame != nullptr && (std::string) str(frame->f_code->co_name) == name
      |                                                      ^~~~~~
/builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/pybind11.h:2165:19: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_code'
 2165 |         && frame->f_code->co_argcount > 0) {
      |                   ^~~~~~
/builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/pybind11.h:2168:20: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_locals'
 2168 |             frame->f_locals, PyTuple_GET_ITEM(frame->f_code->co_varnames, 0));
      |                    ^~~~~~~~
In file included from /usr/include/python3.11/tupleobject.h:39,
                 from /usr/include/python3.11/Python.h:57,
                 from /builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/detail/common.h:147,
                 from /builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/pytypes.h:12,
                 from /builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/cast.h:13:
/builddir/build/BUILD/kicad-6.0.1/thirdparty/pybind11/include/pybind11/pybind11.h:2168:30: error: 'PyFrameObject' {aka 'struct _frame'} has no member named 'f_code'
 2168 |             frame->f_locals, PyTuple_GET_ITEM(frame->f_code->co_varnames, 0));
      |                              ^~~~~~~~~~~~~~~~

Changes of the private PyFrameObject structure members.

While the documentation notes that the fields of PyFrameObject are subject to change at any time, they have been stable for a long time and were used in several popular extensions. In Python 3.11, the frame struct was reorganized to allow performance optimizations. Rather than reading the fields directly, extensions should use functions:
    f_code: removed, use PyFrame_GetCode() instead. Warning: the function returns a strong reference, need to call Py_DECREF().
    f_back: changed (see below), use PyFrame_GetBack().
    f_builtins: removed, use PyObject_GetAttrString(frame, "f_builtins").
    f_globals: removed, use PyObject_GetAttrString(frame, "f_globals").
    f_locals: removed, use PyObject_GetAttrString(frame, "f_locals").
    f_lasti: removed, use PyObject_GetAttrString(frame, "f_lasti").

The following fields were removed entirely, as they were details of the old implementation:
    f_valuesstack
    f_stackdepth
    f_gen
    f_iblock
    f_state
    f_blockstack
    f_localsplus

The Python frame object is now created lazily. A side effect is that the f_back member must not be accessed directly, since its value is now also computed lazily. The PyFrame_GetBack() function must be called instead.

https://docs.python.org/3.11/whatsnew/3.11.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.11/fedora-rawhide-x86_64/03287903-kicad/

For all our attempts to build kicad with Python 3.11, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/package/kicad/

Testing and mass rebuild of packages is happening in copr. You can follow these instructions to test locally in mock if your package builds with Python 3.11:
https://copr.fedorainfracloud.org/coprs/g/python/python3.11/

Let us know here if you have any questions.

Python 3.11 is planned to be included in Fedora 37. To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.11.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires), so if this package is required a lot, it's important for us to get it fixed soon.
We'd appreciate help from the people who know this package best, but if you don't want to work on this now, let us know so we can try to work around it on our side.

Comment 1 Steven A. Falco 2022-02-03 18:29:41 UTC
KiCad uses pybind11, and the pybind11 team are aware of the underlying issue, as mentioned in https://github.com/pybind/pybind11/issues/3530

I have also created an issue with the KiCad team in https://gitlab.com/kicad/code/kicad/-/issues/10729 so they are aware of the problem.

It sounds like the pybind11 team will wait, perhaps until the 3.11 beta, before coming up with a solution.  At that time, the KiCad team will integrate the pybind11 solution.

Comment 2 Ben Cotton 2022-02-08 20:17:07 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 36 development cycle.
Changing version to 36.

Comment 3 Miro Hrončok 2022-06-20 10:14:58 UTC
*** Bug 2098731 has been marked as a duplicate of this bug. ***

Comment 4 Miro Hrončok 2022-06-21 21:02:31 UTC
Hello,

Please note that this comment was generated automatically. If you feel that this output has mistakes, please contact me via email (mhroncok).

All subpackages of a package against which this bug was filled are now installable or removed from Fedora 37.

Thanks for taking care of it!