MCPcopy Create free account
hub / github.com/boostorg/build / builtin_python_import_rule

Function builtin_python_import_rule

src/engine/builtins.cpp:1929–1999  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1927#ifdef HAVE_PYTHON
1928
1929LIST * builtin_python_import_rule( FRAME * frame, int flags )
1930{
1931 static int first_time = 1;
1932 char const * python_module = object_str( list_front( lol_get( frame->args,
1933 0 ) ) );
1934 char const * python_function = object_str( list_front( lol_get( frame->args,
1935 1 ) ) );
1936 OBJECT * jam_module = list_front( lol_get( frame->args, 2 ) );
1937 OBJECT * jam_rule = list_front( lol_get( frame->args, 3 ) );
1938
1939 PyObject * pName;
1940 PyObject * pModule;
1941 PyObject * pDict;
1942 PyObject * pFunc;
1943
1944 if ( first_time )
1945 {
1946 /* At the first invocation, we add the value of the global
1947 * EXTRA_PYTHONPATH to the sys.path Python variable.
1948 */
1949 LIST * extra = 0;
1950 module_t * outer_module = frame->module;
1951 LISTITER iter, end;
1952
1953 first_time = 0;
1954
1955 extra = var_get( root_module(), constant_extra_pythonpath );
1956
1957 iter = list_begin( extra ), end = list_end( extra );
1958 for ( ; iter != end; iter = list_next( iter ) )
1959 {
1960 string buf[ 1 ];
1961 string_new( buf );
1962 string_append( buf, "import sys\nsys.path.append(\"" );
1963 string_append( buf, object_str( list_item( iter ) ) );
1964 string_append( buf, "\")\n" );
1965 PyRun_SimpleString( buf->value );
1966 string_free( buf );
1967 }
1968 }
1969
1970 pName = PyString_FromString( python_module );
1971 pModule = PyImport_Import( pName );
1972 Py_DECREF( pName );
1973
1974 if ( pModule != NULL )
1975 {
1976 pDict = PyModule_GetDict( pModule );
1977 pFunc = PyDict_GetItemString( pDict, python_function );
1978
1979 if ( pFunc && PyCallable_Check( pFunc ) )
1980 {
1981 module_t * m = bindmodule( jam_module );
1982 new_rule_body( m, jam_rule, function_python( pFunc, 0 ), 0 );
1983 }
1984 else
1985 {
1986 if ( PyErr_Occurred() )

Callers

nothing calls this directly

Calls 13

object_strFunction · 0.85
lol_getFunction · 0.85
var_getFunction · 0.85
root_moduleFunction · 0.85
list_beginFunction · 0.85
list_endFunction · 0.85
string_newFunction · 0.85
string_appendFunction · 0.85
string_freeFunction · 0.85
bindmoduleFunction · 0.85
new_rule_bodyFunction · 0.85
function_pythonFunction · 0.85

Tested by

no test coverage detected