{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "f2py:buildtools:meson",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Much of this document is now obsoleted, one can run "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "f2py"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " with "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "--build-dir"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " to get a skeleton "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "meson"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " project with basic dependencies setup."
                }
              ]
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "versionchanged",
          "base_type": "neutral",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "versionchanged 1.26.x"
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "The default build system for "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "f2py"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " is now "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "meson"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", see "
                },
                {
                  "__type": "CrossRef",
                  "__tag": 4002,
                  "value": "distutils-status-migration",
                  "reference": {
                    "__type": "LocalRef",
                    "__tag": 4022,
                    "kind": "docs",
                    "path": "reference:distutils_status_migration"
                  },
                  "kind": "exists"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " for some more details.."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The key advantage gained by leveraging "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "meson"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " over the techniques described in "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "f2py-distutils",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "f2py:buildtools:distutils"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is that this feeds into existing systems and larger projects with ease. "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "meson"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " has a rather pythonic syntax which makes it more comfortable and amenable to extension for "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "python"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " users."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Using via "
        },
        {
          "__type": "InlineCode",
          "__tag": 4051,
          "value": "meson"
        }
      ],
      "level": 0,
      "target": "f2py-meson"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "We will need the generated "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "C"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " wrapper before we can use a general purpose build system like "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "meson"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". We will acquire this by:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "python -m numpy.f2py fib1.f -m fib2",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Now, consider the following "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "meson.build"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " file for the "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "fib"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "scalar"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " examples from "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "f2py-getting-started",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "f2py:f2py.getting-started"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " section:"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "At this point the build will complete, but the import will fail:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "meson setup builddir\nmeson compile -C builddir\ncd builddir\npython -c 'import fib2'\nTraceback (most recent call last):\nFile \"<string>\", line 1, in <module>\nImportError: fib2.cpython-39-x86_64-linux-gnu.so: undefined symbol: FIB_\n# Check this isn't a false positive\nnm -A fib2.cpython-39-x86_64-linux-gnu.so | grep FIB_\nfib2.cpython-39-x86_64-linux-gnu.so: U FIB_",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Recall that the original example, as reproduced below, was in SCREAMCASE:"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "With the standard approach, the subroutine exposed to "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "python"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "fib"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and not "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "FIB"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". This means we have a few options. One approach (where possible) is to lowercase the original Fortran file with say:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "tr \"[:upper:]\" \"[:lower:]\" < fib1.f > fib1.f\npython -m numpy.f2py fib1.f -m fib2\nmeson --wipe builddir\nmeson compile -C builddir\ncd builddir\npython -c 'import fib2'",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "However this requires the ability to modify the source which is not always possible. The easiest way to solve this is to let "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "f2py"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " deal with it:"
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "python -m numpy.f2py fib1.f -m fib2 --lower\nmeson --wipe builddir\nmeson compile -C builddir\ncd builddir\npython -c 'import fib2'",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Fibonacci walkthrough (F77)"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "A major pain point in the workflow defined above, is the manual tracking of inputs. Although it would require more effort to figure out the actual outputs for reasons discussed in "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "f2py-bldsys",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "f2py:buildtools:index"
              },
              "kind": "exists"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "From NumPy "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "1.22.4"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " onwards, "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "f2py"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " will deterministically generate wrapper files based on the input file Fortran standard (F77 or greater). "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "--skip-empty-wrappers"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " can be passed to "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "f2py"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " to restore the previous behaviour of only generating wrappers when needed by the input ."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "However, we can augment our workflow in a straightforward to take into account files for which the outputs are known when the build system is set up."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This can be compiled and run as before."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "rm -rf builddir\nmeson setup builddir\nmeson compile -C builddir\ncd builddir\npython -c \"import numpy as np; import fibby; a = np.zeros(9); fibby.fib(a); print (a)\"\n# [ 0.  1.  1.  2.  3.  5.  8. 13. 21.]",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Automating wrapper generation"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "It is worth keeping in mind the following:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "It is not possible to use SCREAMCASE in this context, so either the contents   of the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": ".f"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " file or the generated wrapper "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": ".c"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " needs to be lowered to   regular letters; which can be facilitated by the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "--lower"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " option of   "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "F2PY"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Salient points"
        }
      ],
      "level": 1,
      "target": null
    }
  ],
  "local_refs": []
}