X Tutup
Skip to content

Commit 4349134

Browse files
committed
Allo the setting of the python module file in order to create a virtual package structure
1 parent ce76dae commit 4349134

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/runtime/PythonTypes/PyModule.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,15 @@ public PyModule Reload()
8080
return new PyModule(op.StealOrThrow());
8181
}
8282

83-
public static PyModule FromString(string name, string code)
83+
public static PyModule FromString(string name, string code, string file = "")
8484
{
85-
using NewReference c = Runtime.Py_CompileString(code, "none", (int)RunFlagType.File);
85+
//force valid value
86+
if(string.IsNullOrWhiteSpace(file))
87+
{
88+
file = "none";
89+
}
90+
91+
using NewReference c = Runtime.Py_CompileString(code, file, (int)RunFlagType.File);
8692
NewReference m = Runtime.PyImport_ExecCodeModule(name, c.BorrowOrThrow());
8793
return new PyModule(m.StealOrThrow());
8894
}

0 commit comments

Comments
 (0)
X Tutup