8000 Allow setting of the python module file by bmello4688 · Pull Request #2044 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Allow setting of the python module file #2044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allo the setting of the python module file in order to create a virtu…
…al package structure
  • Loading branch information
bmello4688 authored and filmor committed Oct 16, 2023
commit ca79ae9913d1aa7b3e9049a1972c4033e1ae983f
10 changes: 8 additions & 2 deletions src/runtime/PythonTypes/PyModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ public PyModule Reload()
return new PyModule(op.StealOrThrow());
}

public static PyModule FromString(string name, string code)
public static PyModule FromString(string name, string code, string file = "")
{
using NewReference c = Runtime.Py_CompileString(code, "none", (int)RunFlagType.File);
//force valid value
if(string.IsNullOrWhiteSpace(file))
{
file = "none";
}

using NewReference c = Runtime.Py_CompileString(code, file, (int)RunFlagType.File);
NewReference m = Runtime.PyImport_ExecCodeModule(name, c.BorrowOrThrow());
return new PyModule(m.StealOrThrow());
}
Expand Down
0