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

Addresses issue #261 with providing more detail information missing d…#298

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes fromall commits
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
32 changes: 32 additions & 0 deletionssrc/runtime/assemblymanager.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -338,6 +338,38 @@ public static bool LoadImplicit(string name, bool warn = true)
return loaded;
}

//===================================================================
// Return the Assembly for a given name
//===================================================================
internal static Assembly GetAssembly(string name)
{
string[] names = name.Split('.');
string s = "";
HashSet<Assembly> assembliesSet = null;
for (int i = 0; i < names.Length; i++)
{
s = (i == 0) ? names[0] : s + "." + names[i];
if (assembliesSet == null)
{
assembliesSet = new HashSet<Assembly>(AppDomain.CurrentDomain.GetAssemblies());
}
Assembly a = FindLoadedAssembly(s);
if (a == null)
{
a = LoadAssemblyPath(s);
}
if (a == null)
{
a = LoadAssembly(s);
}
if (a != null && assembliesSet.Contains(a))
{
return a;
}
}
return null;
}


//===================================================================
// Scans an assembly for exported namespaces, adding them to the
Expand Down
30 changes: 29 additions & 1 deletionsrc/runtime/importhook.cs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -278,7 +278,35 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
{
// May be called when a module being imported imports a module.
// In particular, I've seen decimal import copy import org.python.core
return Runtime.PyObject_Call(py_import, args, kw);
var res = Runtime.PyObject_Call(py_import, args, kw);

// Check if there is an ImportError Exception if so
// determine which dependencies are missing
if(Exceptions.ExceptionMatches(Exceptions.ImportError))
{
var target_assembly = AssemblyManager.GetAssembly(realname);
if (target_assembly != null)
{
System.Collections.Generic.List<string> missing_dependencies =
new System.Collections.Generic.List<string>();
foreach (var assembly in target_assembly.GetReferencedAssemblies())
{
var depedentAssembly = AssemblyManager.LoadAssembly(assembly.Name);
if (depedentAssembly == null)
missing_dependencies.Add(assembly.Name);
}

if (missing_dependencies.Count > 0)
{
// We found missing dependencies
string error = String.Format("No module named {0} missing dependencies {1}",
realname, String.Join(", ", missing_dependencies));
Exceptions.SetError(Exceptions.ImportError, error);
}
}
}
return res;

}
}

Expand Down
View file
Open in desktop
Binary file not shown.
5 changes: 5 additions & 0 deletionssrc/tests/test_suite/_missing_import_dependency.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
import os
import clr
path_to_dll = os.path.join(os.path.dirname(__file__), "TestDependencyAssembly.dll")
clr.AddReference(path_to_dll)
from TestDependencyAssembly import TestDependency
6 changes: 6 additions & 0 deletionssrc/tests/test_suite/test_import.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,12 @@ def testRealtiveMissingImport(self):
from . import _missing_import
except ImportError:
pass

def testMissingImportDepencency(self):
missing_dependency_name = "MissingDependencyAssembly"
with self.assertRaisesRegexp(ImportError, missing_dependency_name):
from . import _missing_import_dependency



def test_suite():
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp