Skip to content
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

123 #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="dot-net MyGet Feed" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" protocolVersion="3"/>
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
</configuration>
2 changes: 1 addition & 1 deletion src/runtime/BorrowedReference.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Python.Runtime
/// Represents a reference to a Python object, that is being lent, and
/// can only be safely used until execution returns to the caller.
/// </summary>
readonly ref struct BorrowedReference
public readonly ref struct BorrowedReference
{
readonly IntPtr pointer;
public bool IsNull => this.pointer == IntPtr.Zero;
Expand Down
192 changes: 19 additions & 173 deletions src/runtime/Python.Runtime.csproj
Original file line number Diff line number Diff line change
@@ -1,186 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{097B4AC0-74E9-4C58-BCF8-C69746EC8271}</ProjectGuid>
<OutputType>Library</OutputType>
<AssemblyName>Python.Runtime</AssemblyName>
<RootNamespace>Python.Runtime</RootNamespace>
<DocumentationFile>bin\Python.Runtime.xml</DocumentationFile>
<OutputPath>bin\</OutputPath>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile />
<NoWarn>1591</NoWarn>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)\bin\</PythonBuildDir>
<AppDesignerFolder>Properties</AppDesignerFolder>
<LangVersion>7.3</LangVersion>
<AssemblyName>pyRevitLabs.PythonNet</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>..\pythonnet.snk</AssemblyOriginatorKeyFile>
<Configurations>Debug;ReleasePY37;ReleasePY38</Configurations>
</PropertyGroup>
<!--We can relax binding to platform because code references no any platform dependent assemblies-->
<!--This will allows to use any build of this assebly as a compile ref assebly-->
<!--<PropertyGroup Condition=" '$(Platform)' == 'x86'">
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'x64'">
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>-->
<PropertyGroup Condition=" '$(Configuration)' == 'ReleaseMono'">
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS4</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'ReleaseMonoPY3'">
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS4</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'DebugMono'">
<DebugSymbols>true</DebugSymbols>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS4;TRACE;DEBUG</DefineConstants>
<Optimize>false</Optimize>
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'DebugMonoPY3'">
<DebugSymbols>true</DebugSymbols>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS4;TRACE;DEBUG</DefineConstants>
<Optimize>false</Optimize>
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'ReleaseWin'">
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS2</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'ReleaseWinPY3'">
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS2</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>

<PropertyGroup>
<DefaultItemExcludes>Properties\AssemblyInfo.cs</DefaultItemExcludes>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'DebugWin'">
<DebugSymbols>true</DebugSymbols>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON2;PYTHON27;UCS2;TRACE;DEBUG</DefineConstants>
<Optimize>false</Optimize>
<DebugType>full</DebugType>

<PropertyGroup Condition=" '$(Configuration)' == 'ReleasePY37'">
<DefineConstants>$(DefineConstants);PYTHON3;PYTHON37;UCS2</DefineConstants>
<EngineDir>CPY378</EngineDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'DebugWinPY3'">
<DebugSymbols>true</DebugSymbols>
<DefineConstants Condition="'$(DefineConstants)' == ''">PYTHON3;PYTHON38;UCS2;TRACE;DEBUG</DefineConstants>
<Optimize>false</Optimize>
<DebugType>full</DebugType>

<PropertyGroup Condition="'$(Configuration)'=='ReleasePY38'">
<DefineConstants>$(DefineConstants);PYTHON3;PYTHON38;UCS2</DefineConstants>
<EngineDir>CPY385</EngineDir>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="Codecs\EncoderGroup.cs" />
<Compile Include="Codecs\DecoderGroup.cs" />
<Compile Include="Codecs\RawProxyEncoder.cs" />
<Compile Include="Codecs\TupleCodecs.cs" />
<Compile Include="converterextensions.cs" />
<Compile Include="finalizer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="arrayobject.cs" />
<Compile Include="assemblymanager.cs" />
<Compile Include="BorrowedReference.cs" />
<Compile Include="classderived.cs" />
<Compile Include="classbase.cs" />
<Compile Include="classmanager.cs" />
<Compile Include="classobject.cs" />
<Compile Include="clrobject.cs" />
<Compile Include="codegenerator.cs" />
<Compile Include="constructorbinder.cs" />
<Compile Include="constructorbinding.cs" />
<Compile Include="converter.cs" />
<Compile Include="CustomMarshaler.cs" />
<Compile Include="debughelper.cs" />
<Compile Include="delegatemanager.cs" />
<Compile Include="delegateobject.cs" />
<Compile Include="eventbinding.cs" />
<Compile Include="eventobject.cs" />
<Compile Include="exceptions.cs" />
<Compile Include="extensiontype.cs" />
<Compile Include="fieldobject.cs" />
<Compile Include="generictype.cs" />
<Compile Include="genericutil.cs" />
<Compile Include="importhook.cs" />
<Compile Include="indexer.cs" />
<Compile Include="interfaceobject.cs" />
<Compile Include="interfaces.cs" />
<Compile Include="interop.cs" />
<Compile Include="iterator.cs" />
<Compile Include="managedtype.cs" />
<Compile Include="metatype.cs" />
<Compile Include="methodbinder.cs" />
<Compile Include="methodbinding.cs" />
<Compile Include="methodobject.cs" />
<Compile Include="methodwrapper.cs" />
<Compile Include="modulefunctionobject.cs" />
<Compile Include="moduleobject.cs" />
<Compile Include="modulepropertyobject.cs" />
<Compile Include="nativecall.cs" />
<Compile Include="NewReference.cs" />
<Compile Include="NonCopyableAttribute.cs" />
<Compile Include="overload.cs" />
<Compile Include="propertyobject.cs" />
<Compile Include="pyansistring.cs" />
<Compile Include="pydict.cs" />
<Compile Include="PyExportAttribute.cs" />
<Compile Include="pyfloat.cs" />
<Compile Include="pyint.cs" />
<Compile Include="pyiter.cs" />
<Compile Include="pylist.cs" />
<Compile Include="pylong.cs" />
<Compile Include="pynumber.cs" />
<Compile Include="pyobject.cs" />
<Compile Include="pyscope.cs" />
<Compile Include="pysequence.cs" />
<Compile Include="pystring.cs" />
<Compile Include="pythonengine.cs" />
<Compile Include="pythonexception.cs" />
<Compile Include="pytuple.cs" />
<Compile Include="ReferenceExtensions.cs" />
<Compile Include="runtime.cs" />
<Compile Include="typemanager.cs" />
<Compile Include="typemethod.cs" />
<Compile Include="Util.cs" />
<Compile Include="platform\Types.cs" />
<Compile Include="platform\LibraryLoader.cs" />
<Compile Include="polyfill\ReflectionPolifills.cs" />
<Compile Include="slots\mp_length.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(PythonInteropFile)' != '' ">
<Compile Include="$(PythonInteropFile)" />
</ItemGroup>
<ItemGroup Condition=" '$(PythonInteropFile)' == '' ">
<Compile Include="interop27.cs" />
<Compile Include="interop34.cs" />
<Compile Include="interop35.cs" />
<Compile Include="interop36.cs" />
<Compile Include="interop37.cs" />
<Compile Include="interop38.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\pythonnet.snk" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="resources\clr.py">
<LogicalName>clr.py</LogicalName>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
<PropertyGroup>
<TargetAssembly>$(TargetPath)</TargetAssembly>
<TargetAssemblyPdb>$(TargetDir)$(TargetName).pdb</TargetAssemblyPdb>
</PropertyGroup>
<Target Name="AfterBuild">
<Copy SourceFiles="$(TargetAssembly)" DestinationFolder="$(PythonBuildDir)" />
<!--Copy SourceFiles="$(TargetAssemblyPdb)" Condition="Exists('$(TargetAssemblyPdb)')" DestinationFolder="$(PythonBuildDir)" /-->

<Target Name="Deploy" AfterTargets="AfterBuild">
<Copy SourceFiles="$(TargetDir)\pyRevitLabs.PythonNet.dll" DestinationFolder="$(PyRevitEnginesDir)\$(EngineDir)" />
</Target>
</Project>
</Project>
14 changes: 7 additions & 7 deletions src/runtime/runtime.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ public static extern int Py_Main(
internal static extern void PyEval_RestoreThread(IntPtr tstate);

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr PyEval_GetBuiltins();
public static extern IntPtr PyEval_GetBuiltins();

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr PyEval_GetGlobals();
Expand Down Expand Up @@ -1559,7 +1559,7 @@ internal static IntPtr PyUnicode_FromString(string s)
return PyUnicode_FromUnicode(s, s.Length);
}

internal static string GetManagedString(in BorrowedReference borrowedReference)
public static string GetManagedString(in BorrowedReference borrowedReference)
=> GetManagedString(borrowedReference.DangerousGetAddress());
/// <summary>
/// Function to access the internal PyUnicode/PyString object and
Expand Down Expand Up @@ -1625,7 +1625,7 @@ internal static bool PyDict_Check(IntPtr ob)
internal static extern int PyDict_SetItem(IntPtr pointer, IntPtr key, IntPtr value);

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyDict_SetItemString(IntPtr pointer, string key, IntPtr value);
public static extern int PyDict_SetItemString(IntPtr pointer, string key, IntPtr value);

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyDict_DelItem(IntPtr pointer, IntPtr key);
Expand Down Expand Up @@ -1683,13 +1683,13 @@ internal static IntPtr PyList_New(long size)
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr PyList_AsTuple(IntPtr pointer);

internal static BorrowedReference PyList_GetItem(IntPtr pointer, long index)
public static BorrowedReference PyList_GetItem(IntPtr pointer, long index)
{
return PyList_GetItem(pointer, new IntPtr(index));
}

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern BorrowedReference PyList_GetItem(IntPtr pointer, IntPtr index);
public static extern BorrowedReference PyList_GetItem(IntPtr pointer, IntPtr index);

internal static int PyList_SetItem(IntPtr pointer, long index, IntPtr value)
{
Expand All @@ -1699,7 +1699,7 @@ internal static int PyList_SetItem(IntPtr pointer, long index, IntPtr value)
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern int PyList_SetItem(IntPtr pointer, IntPtr index, IntPtr value);

internal static int PyList_Insert(BorrowedReference pointer, long index, IntPtr value)
public static int PyList_Insert(BorrowedReference pointer, long index, IntPtr value)
{
return PyList_Insert(pointer, new IntPtr(index), value);
}
Expand All @@ -1708,7 +1708,7 @@ internal static int PyList_Insert(BorrowedReference pointer, long index, IntPtr
private static extern int PyList_Insert(BorrowedReference pointer, IntPtr index, IntPtr value);

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyList_Append(BorrowedReference pointer, IntPtr value);
public static extern int PyList_Append(BorrowedReference pointer, IntPtr value);

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyList_Reverse(BorrowedReference pointer);
Expand Down