Skip to content

Modernize import hook #1369

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 21 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a321daa
(WIP) modernize the import hook
BadSingleton Jan 15, 2021
279b535
Add the loaded namespaces tracking
BadSingleton Jan 15, 2021
f92e95b
cleanup and changelog entry
BadSingleton Jan 15, 2021
afffc18
Fix a bug where clr wasn't in sys.modules after reload
BadSingleton Jan 18, 2021
d821c0f
Further refinements to setattr logic on ModuleObjects
BadSingleton Jan 19, 2021
e469a8a
fixups, add docs
BadSingleton Jan 20, 2021
685b972
merge fixup
BadSingleton Mar 4, 2021
be81364
(WIP) import hook in the pytohn module
BadSingleton Mar 10, 2021
73958ed
Revert "(WIP) import hook in the pytohn module"
BadSingleton Apr 12, 2021
e71a0ef
Import hook as a module, take 2
BadSingleton Apr 12, 2021
2af066d
fixup! Merge remote-tracking branch 'origin/master' into modernize-im…
BadSingleton Apr 12, 2021
bb490bf
fixup! fixup! Merge remote-tracking branch 'origin/master' into moder…
BadSingleton Apr 12, 2021
31ea876
Create a clr.loader module
BadSingleton Jun 1, 2021
c02d5c6
Test to test if the test passes
BadSingleton Jun 2, 2021
970a189
fix new exception usage
BadSingleton Jun 2, 2021
059605b
kick the build because I can't repro
BadSingleton Jun 2, 2021
ff170e9
Add Namespaces to the import hook only through AddReference
BadSingleton Jun 2, 2021
63de923
Review changes, update API usage
BadSingleton Jun 8, 2021
624f7e3
Merge remote-tracking branch 'upstream/master' into modernize-import-…
BadSingleton Jun 14, 2021
bd7e745
make PyModule_AddObject in line with CPython
BadSingleton Jun 14, 2021
46a85fe
take care of stragglers
BadSingleton Jun 15, 2021
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
(WIP) modernize the import hook
Implement a meta path loader instead
  • Loading branch information
BadSingleton committed Jun 2, 2021
commit a321daa0147a49984a1df027df9d3f6104e77950
23 changes: 23 additions & 0 deletions src/runtime/assemblymanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ internal class AssemblyManager
// modified from event handlers below, potentially triggered from different .NET threads
private static ConcurrentQueue<Assembly> assemblies;
internal static List<string> pypath;

// Triggered when a new namespace is added to the namespaces dictionary
public static event Action<string> namespaceAdded;

private AssemblyManager()
{
Expand Down Expand Up @@ -284,6 +287,17 @@ internal static void ScanAssembly(Assembly assembly)
if (ns != null)
{
namespaces[ns].TryAdd(assembly, string.Empty);
try
{
namespaceAdded?.Invoke(ns);
}
catch (Exception e)
{
// For some reason, exceptions happening here does... nothing.
// Even System.AccessViolationExceptions gets ignored.
Console.WriteLine($"Namespace added callback failed with: {e}");
throw;
}
}

if (ns != null && t.IsGenericTypeDefinition)
Expand Down Expand Up @@ -312,6 +326,15 @@ public static bool IsValidNamespace(string name)
return !string.IsNullOrEmpty(name) && namespaces.ContainsKey(name);
}

/// <summary>
/// Returns an IEnumerable<string> containing the namepsaces exported
/// by loaded assemblies in the current app domain.
/// </summary>
public static IEnumerable<string> GetNamespaces ()
{
return namespaces.Keys;
}

/// <summary>
/// Returns list of assemblies that declare types in a given namespace
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/extensiontype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static int tp_setattro(IntPtr ob, IntPtr key, IntPtr val)
{
message = "readonly attribute";
}
Exceptions.SetError(Exceptions.TypeError, message);
Exceptions.SetError(Exceptions.AttributeError, message);
return -1;
}

Expand Down
Loading