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

Function builtin_python_import_rule

v2/engine/builtins.c:1930–2000  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

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