
Find the names each Python script defines at top level
Source:R/reproducibility_check_python.R
dot-repro_py_defined_vars.RdThe Python sibling of repro_defined_vars(), used by the module's report
to name the file that defines a missing name (a NameError –
error_type == "undefined_variable", see repro_run_scripts_py()'s
classification – usually means the script expects a name another script
in the same repository defines, rather than being a standalone program).
Unlike R, there is no re-run in a corrected order: every Python script runs
in its own python process, so a name another script defines is never
available to it, whatever the order. Scans each file for top-level variable
assignments (x = ..., not ==) and top-level def/class statements, so
a missing name can be matched to the file that would supply it. Only a
statement at the start of a (comment-free) line is taken, which
approximates "top level": an assignment/def indented inside a function body
or control-flow block is not a module-level name the next script would see
if it only imports or runs this one, and taking it would create false
ordering edges. Unlike repro_defined_vars(), there is no assign("x", ...)-style function-call form to also match – Python has no equivalent
builtin that creates a module-level name by string.