Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
Cross compiled for NetStandard 1.5 and Net 4.6, + empty projects added.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriyse committed Dec 28, 2016
1 parent 38adb2e commit 65d1eda
Show file tree
Hide file tree
Showing 39 changed files with 367 additions and 112 deletions.
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects": ["src"],
"sdk": {
"version": "1.0.0-preview2-1-003177"
}
}
16 changes: 16 additions & 0 deletions pythonnet.CoreCLR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Python.Runtime", "src\Pytho
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "embed_tests", "src\embed_tests\embed_tests.xproj", "{9F91A9DC-D7B3-45A9-96FF-57AACC1B959A}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Python.Runtime.Contracts", "src\Python.Runtime.Contracts\Python.Runtime.Contracts.xproj", "{3A75B887-30F2-4F42-B384-47F8D1E1DB65}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Python.Net", "src\Python.Net\Python.Net.xproj", "{F4E01C59-8951-451F-86F5-EF61CAAA786F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -34,6 +38,18 @@ Global
{9F91A9DC-D7B3-45A9-96FF-57AACC1B959A}.Py35-UCS2-Win-Debug|Any CPU.Build.0 = Debug|Any CPU
{9F91A9DC-D7B3-45A9-96FF-57AACC1B959A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F91A9DC-D7B3-45A9-96FF-57AACC1B959A}.Release|Any CPU.Build.0 = Release|Any CPU
{3A75B887-30F2-4F42-B384-47F8D1E1DB65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A75B887-30F2-4F42-B384-47F8D1E1DB65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3A75B887-30F2-4F42-B384-47F8D1E1DB65}.Py35-UCS2-Win-Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3A75B887-30F2-4F42-B384-47F8D1E1DB65}.Py35-UCS2-Win-Debug|Any CPU.Build.0 = Debug|Any CPU
{3A75B887-30F2-4F42-B384-47F8D1E1DB65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3A75B887-30F2-4F42-B384-47F8D1E1DB65}.Release|Any CPU.Build.0 = Release|Any CPU
{F4E01C59-8951-451F-86F5-EF61CAAA786F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4E01C59-8951-451F-86F5-EF61CAAA786F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4E01C59-8951-451F-86F5-EF61CAAA786F}.Py35-UCS2-Win-Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4E01C59-8951-451F-86F5-EF61CAAA786F}.Py35-UCS2-Win-Debug|Any CPU.Build.0 = Debug|Any CPU
{F4E01C59-8951-451F-86F5-EF61CAAA786F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4E01C59-8951-451F-86F5-EF61CAAA786F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
19 changes: 19 additions & 0 deletions src/Python.Net/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Python.Net")]
[assembly: AssemblyTrademark("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f4e01c59-8951-451f-86f5-ef61caaa786f")]
21 changes: 21 additions & 0 deletions src/Python.Net/Python.Net.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>f4e01c59-8951-451f-86f5-ef61caaa786f</ProjectGuid>
<RootNamespace>Python.Net</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
21 changes: 21 additions & 0 deletions src/Python.Net/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "2.2.0-*",

"dependencies": {
"NETStandard.Library": "1.6.0",
"Python.Runtime.Contracts": "2.2.0-*"
},

"frameworks": {
"netstandard1.5": {
"imports": "dnxcore50"
},
"net46": {

}
},
"configurations": {
"Py35-UCS2-Win-Debug": {
}
}
}
19 changes: 19 additions & 0 deletions src/Python.Runtime.Contracts/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Python.Contracts")]
[assembly: AssemblyTrademark("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3a75b887-30f2-4f42-b384-47f8d1e1db65")]
21 changes: 21 additions & 0 deletions src/Python.Runtime.Contracts/Python.Runtime.Contracts.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>3a75b887-30f2-4f42-b384-47f8d1e1db65</ProjectGuid>
<RootNamespace>Python.Contracts</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
20 changes: 20 additions & 0 deletions src/Python.Runtime.Contracts/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "2.2.0-*",

"dependencies": {
"NETStandard.Library": "1.6.0"
},

"frameworks": {
"netstandard1.5": {
"imports": "dnxcore50"
},
"net46": {

}
},
"configurations": {
"Py35-UCS2-Win-Debug": {
}
}
}
30 changes: 30 additions & 0 deletions src/Python.Runtime/DelegateShim.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace Python.Runtime
{
using System;
using System.Linq;
using System.Reflection;

public static class DelegateShim
{
public static Delegate CreateDelegate(Type dtype, object obj, string methodName)
{
if (obj == null)
{
throw new ArgumentNullException(nameof(obj));
}

var methods = obj.GetType().GetTypeInfo().GetMember(methodName, BindingFlags.Default);
if (!methods.Any())
{
throw new InvalidOperationException("Method does not exist");
}

return CreateDelegate(dtype, (MethodInfo)methods[0]);
}

internal static Delegate CreateDelegate(Type dtype, MethodInfo method)
{
return method.CreateDelegate(dtype);
}
}
}
2 changes: 1 addition & 1 deletion src/Python.Runtime/arrayobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v)
int index = 0;
object value;

if (items.IsReadOnly)
if (((IList)items).IsReadOnly)
{
Exceptions.RaiseTypeError("array is read-only");
return -1;
Expand Down
33 changes: 27 additions & 6 deletions src/Python.Runtime/assemblymanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
using System.Diagnostics;
using System.Reflection;
using System.Threading;
using ReflectionBridge.Extensions;
#if !NET46
using System.Runtime.Loader;
#endif

namespace Python.Runtime
{

/// <summary>
/// The AssemblyManager maintains information about loaded assemblies
/// namespaces and provides an interface for name-based type lookup.
Expand All @@ -19,7 +24,9 @@ internal class AssemblyManager
// therefore this should be a ConcurrentDictionary
static ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>> namespaces;
//static Dictionary<string, Dictionary<string, string>> generics;
#if NET46
static AssemblyLoadEventHandler lhandler;
#endif
static ResolveEventHandler rhandler;
// updated only under GIL?
static Dictionary<string, int> probed;
Expand Down Expand Up @@ -47,14 +54,15 @@ internal static void Initialize()
pypath = new List<string>(16);

AppDomain domain = AppDomain.CurrentDomain;

#if NET46
lhandler = new AssemblyLoadEventHandler(AssemblyLoadHandler);
domain.AssemblyLoad += lhandler;

#endif
rhandler = new ResolveEventHandler(ResolveHandler);
domain.AssemblyResolve += rhandler;

Assembly[] items = domain.GetAssemblies();

foreach (var a in items)
{
try
Expand All @@ -77,11 +85,13 @@ internal static void Initialize()
internal static void Shutdown()
{
AppDomain domain = AppDomain.CurrentDomain;
#if NET46
domain.AssemblyLoad -= lhandler;
#endif
domain.AssemblyResolve -= rhandler;
}


#if NET46
//===================================================================
// Event handler for assembly load events. At the time the Python
// runtime loads, we scan the app domain to map the assemblies that
Expand All @@ -96,7 +106,7 @@ static void AssemblyLoadHandler(Object ob, AssemblyLoadEventArgs args)
assemblies.Add(assembly);
ScanAssembly(assembly);
}

#endif

//===================================================================
// Event handler for assembly resolve events. This is needed because
Expand All @@ -120,7 +130,6 @@ static Assembly ResolveHandler(Object ob, ResolveEventArgs args)
return LoadAssemblyPath(args.Name);
}


//===================================================================
// We __really__ want to avoid using Python objects or APIs when
// probing for assemblies to load, since our ResolveHandler may be
Expand Down Expand Up @@ -204,7 +213,11 @@ public static Assembly LoadAssembly(string name)
Assembly assembly = null;
try
{
#if NET46
assembly = Assembly.Load(name);
#else
assembly = Assembly.Load(new AssemblyName(name));
#endif
}
catch (System.Exception e)
{
Expand All @@ -228,7 +241,11 @@ public static Assembly LoadAssemblyPath(string name)
{
try
{
#if NET46
assembly = Assembly.LoadFrom(path);
#else
assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(path);
#endif
}
catch
{
Expand All @@ -253,7 +270,11 @@ public static Assembly LoadAssemblyFullPath(string name)
{
try
{
#if NET46
assembly = Assembly.LoadFrom(name);
#else
assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(name);
#endif
}
catch
{
Expand Down Expand Up @@ -373,7 +394,7 @@ internal static void ScanAssembly(Assembly assembly)
namespaces[ns].TryAdd(assembly, String.Empty);
}

if (ns != null && t.IsGenericTypeDefinition)
if (ns != null && t.GetTypeInfo().IsGenericTypeDefinition)
{
GenericUtil.Register(t);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Python.Runtime/classbase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using System.Reflection;
using System.Security;
using System.Runtime.InteropServices;
using ReflectionBridge.Extensions;

namespace Python.Runtime
{

/// <summary>
/// Base class for Python types that reflect managed types / classes.
/// Concrete subclasses include ClassObject and DelegateObject. This
Expand All @@ -27,7 +29,7 @@ internal ClassBase(Type tp) : base()

internal virtual bool CanSubclass()
{
return (!this.type.IsEnum);
return (!this.type.IsEnum());
}

//====================================================================
Expand Down
Loading

0 comments on commit 65d1eda

Please sign in to comment.