Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe8154f

Browse files
author
dse
committed
Merge
2 parents866de1a +e2efdda commitbe8154f

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
88
##[unreleased][]
99

1010
###Added
11+
- Optimized implicit assembly loading on module import, PythonEngine.ImplicitAssemblyLoading event added.
1112
- Added support for embedding python into dotnet core 2.0 (NetCoreApp2.0)
1213
- Added new build system (pythonnet.15.sln) based on dotnetcore-sdk/xplat(crossplatform msbuild).
1314
Currently there two side-by-side build systems that produces the same output (net40) from the same sources.

‎src/runtime/assemblymanager.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ public static Assembly LoadAssembly(string name)
196196
Assemblyassembly=null;
197197
try
198198
{
199+
varimportEvent=newImplicitAssemblyLoadingEventArgs(name);
200+
if(importEvent.SkipAssemblyLoad)
201+
{
202+
returnnull;
203+
}
204+
205+
PythonEngine.RaiseAssemblyAsModuleImportingEvent(importEvent);
206+
199207
assembly=Assembly.Load(name);
200208
}
201209
catch(Exception)
@@ -419,12 +427,15 @@ public static List<string> GetNames(string nsname)
419427
{
420428
foreach(Assemblyainnamespaces[nsname].Keys)
421429
{
422-
Type[]types=a.GetTypes();
430+
Type[]types=a.IsDynamic?a.GetTypes():a.GetExportedTypes();
423431
foreach(Typetintypes)
424432
{
425433
if((t.Namespace??"")==nsname)
426434
{
427-
names.Add(t.Name);
435+
if(!t.IsNested)
436+
{
437+
names.Add(t.Name);
438+
}
428439
}
429440
}
430441
}

‎src/runtime/pythonengine.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ public static string Compiler
136136

137137
internalstaticPyReferenceDecrementerCurrentRefDecrementer{get;privateset;}
138138

139+
/// <summary>
140+
/// Fires when python engines importing module and probably tries to load an assembly.
141+
/// </summary>
142+
publicstaticeventEventHandler<ImplicitAssemblyLoadingEventArgs>ImplicitAssemblyLoading;
143+
139144
publicstaticintRunSimpleString(stringcode)
140145
{
141146
returnRuntime.PyRun_SimpleString(code);
@@ -549,6 +554,29 @@ internal static PyObject RunString(string code, IntPtr? globals, IntPtr? locals,
549554
}
550555
}
551556
}
557+
558+
internalstaticvoidRaiseAssemblyAsModuleImportingEvent(ImplicitAssemblyLoadingEventArgse)
559+
{
560+
ImplicitAssemblyLoading?.Invoke(null,e);
561+
}
562+
}
563+
564+
publicclassImplicitAssemblyLoadingEventArgs:EventArgs
565+
{
566+
publicImplicitAssemblyLoadingEventArgs(stringmoduleName)
567+
{
568+
ModuleName=moduleName;
569+
}
570+
571+
/// <summary>
572+
/// The name of the module to import that is probably assembly name.
573+
/// </summary>
574+
publicstringModuleName{get;}
575+
576+
/// <summary>
577+
/// Set it to true, if you know that <see cref="ModuleName"/> is not an assembly to import.
578+
/// </summary>
579+
publicboolSkipAssemblyLoad{get;set;}
552580
}
553581

554582
publicenumRunFlagType

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp