Skip to content

Commit 138bda7

Browse files
committed
Merge pull request #78 from renshawbay/python3
Merge from renshawbay/pythonnet Fixes #12
2 parents e5c4e74 + dd2dcd0 commit 138bda7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+4548
-1011
lines changed

.travis.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ language: python
22
python:
33
- 2.6
44
- 2.7
5+
- 3.2
6+
- 3.4
57
before_install:
68
- sudo apt-get install software-properties-common
79
- sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ trusty main universe"
@@ -12,7 +14,8 @@ before_install:
1214
- yes | sudo certmgr -ssl -m https://nugetgallery.blob.core.windows.net
1315
- yes | sudo certmgr -ssl -m https://nuget.org
1416
install:
17+
- pip install six
1518
- python setup.py build_ext --inplace
1619
script:
17-
- export PYTHONPATH=`pwd`
18-
- ./npython src/tests/runtests.py
20+
- export PYTHONPATH=`pwd`:$PYTHONPATH
21+
- python src/tests/runtests.py

Python.Runtime.dll.config

+6
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ For more information read:
1414
<dllmap dll="python25" target="libpython2.5.so" os="!windows" />
1515
<dllmap dll="python26" target="libpython2.6.so" os="!windows" />
1616
<dllmap dll="python27" target="libpython2.7.so" os="!windows" />
17+
<dllmap dll="python32" target="libpython3.2.so" os="!windows" />
18+
<dllmap dll="python33" target="libpython3.3.so" os="!windows" />
19+
<dllmap dll="python34" target="libpython3.4.so" os="!windows" />
1720
<dllmap dll="python23.dll" target="libpython2.3.so" os="!windows" />
1821
<dllmap dll="python24.dll" target="libpython2.4.so" os="!windows" />
1922
<dllmap dll="python25.dll" target="libpython2.5.so" os="!windows" />
2023
<dllmap dll="python26.dll" target="libpython2.6.so" os="!windows" />
2124
<dllmap dll="python27.dll" target="libpython2.7.so" os="!windows" />
25+
<dllmap dll="python32.dll" target="libpython3.2.so" os="!windows" />
26+
<dllmap dll="python33.dll" target="libpython3.3.so" os="!windows" />
27+
<dllmap dll="python34.dll" target="libpython3.4.so" os="!windows" />
2228
</configuration>
2329

Python.Test.csproj

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{6F401A34-273B-450F-9A4C-13550BE0767B}</ProjectGuid>
7+
<OutputType>Library</OutputType>
8+
<NoStandardLibraries>false</NoStandardLibraries>
9+
<AssemblyName>Python.Test</AssemblyName>
10+
<RootNamespace>Python.Test</RootNamespace>
11+
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
12+
<FileUpgradeFlags>
13+
</FileUpgradeFlags>
14+
<UpgradeBackupLocation>
15+
</UpgradeBackupLocation>
16+
<OldToolsVersion>3.5</OldToolsVersion>
17+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
18+
<TargetFrameworkProfile />
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>false</Optimize>
24+
<OutputPath>.\bin\Debug\</OutputPath>
25+
<DefineConstants>DEBUG;TRACE</DefineConstants>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>.\bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
</PropertyGroup>
33+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'EmbeddingTest|AnyCPU' ">
34+
<DebugSymbols>true</DebugSymbols>
35+
<OutputPath>bin\EmbeddingTest\</OutputPath>
36+
<DefineConstants>DEBUG;TRACE</DefineConstants>
37+
<DebugType>full</DebugType>
38+
<PlatformTarget>AnyCPU</PlatformTarget>
39+
</PropertyGroup>
40+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'UnitTests|AnyCPU' ">
41+
<DebugSymbols>true</DebugSymbols>
42+
<OutputPath>bin\UnitTests\</OutputPath>
43+
<DefineConstants>DEBUG;TRACE</DefineConstants>
44+
<DebugType>full</DebugType>
45+
<PlatformTarget>AnyCPU</PlatformTarget>
46+
</PropertyGroup>
47+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
48+
<DebugSymbols>true</DebugSymbols>
49+
<OutputPath>bin\x86\Debug\</OutputPath>
50+
<DefineConstants>DEBUG;TRACE</DefineConstants>
51+
<DebugType>full</DebugType>
52+
<PlatformTarget>x86</PlatformTarget>
53+
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
54+
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
55+
</PropertyGroup>
56+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
57+
<OutputPath>bin\x86\Release\</OutputPath>
58+
<DefineConstants>TRACE</DefineConstants>
59+
<Optimize>true</Optimize>
60+
<DebugType>pdbonly</DebugType>
61+
<PlatformTarget>x86</PlatformTarget>
62+
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
63+
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
64+
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
65+
</PropertyGroup>
66+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'EmbeddingTest|x86'">
67+
<DebugSymbols>true</DebugSymbols>
68+
<OutputPath>bin\x86\EmbeddingTest\</OutputPath>
69+
<DefineConstants>DEBUG;TRACE</DefineConstants>
70+
<DebugType>full</DebugType>
71+
<PlatformTarget>x86</PlatformTarget>
72+
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
73+
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
74+
<CodeAnalysisFailOnMissingRules>true</CodeAnalysisFailOnMissingRules>
75+
</PropertyGroup>
76+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'UnitTests|x86'">
77+
<DebugSymbols>true</DebugSymbols>
78+
<OutputPath>bin\x86\UnitTests\</OutputPath>
79+
<DefineConstants>DEBUG;TRACE</DefineConstants>
80+
<DebugType>full</DebugType>
81+
<PlatformTarget>x86</PlatformTarget>
82+
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
83+
<CodeAnalysisFailOnMissingRules>true</CodeAnalysisFailOnMissingRules>
84+
</PropertyGroup>
85+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugMono_x86|AnyCPU'">
86+
<DebugSymbols>true</DebugSymbols>
87+
<OutputPath>bin\DebugMono_x86\</OutputPath>
88+
<DefineConstants>DEBUG;TRACE</DefineConstants>
89+
<DebugType>full</DebugType>
90+
<PlatformTarget>AnyCPU</PlatformTarget>
91+
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
92+
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
93+
</PropertyGroup>
94+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugMono_x86|x86'">
95+
<DebugSymbols>true</DebugSymbols>
96+
<OutputPath>bin\x86\DebugMono_x86\</OutputPath>
97+
<DefineConstants>DEBUG;TRACE</DefineConstants>
98+
<DebugType>full</DebugType>
99+
<PlatformTarget>x86</PlatformTarget>
100+
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
101+
</PropertyGroup>
102+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
103+
<DebugSymbols>true</DebugSymbols>
104+
<OutputPath>bin\x64\Debug\</OutputPath>
105+
<DefineConstants>DEBUG;TRACE</DefineConstants>
106+
<DebugType>full</DebugType>
107+
<PlatformTarget>x64</PlatformTarget>
108+
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
109+
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
110+
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
111+
</PropertyGroup>
112+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
113+
<OutputPath>bin\x64\Release\</OutputPath>
114+
<DefineConstants>TRACE</DefineConstants>
115+
<Optimize>true</Optimize>
116+
<DebugType>pdbonly</DebugType>
117+
<PlatformTarget>x64</PlatformTarget>
118+
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
119+
</PropertyGroup>
120+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'EmbeddingTest|x64'">
121+
<DebugSymbols>true</DebugSymbols>
122+
<OutputPath>bin\x64\EmbeddingTest\</OutputPath>
123+
<DefineConstants>DEBUG;TRACE</DefineConstants>
124+
<DebugType>full</DebugType>
125+
<PlatformTarget>x64</PlatformTarget>
126+
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
127+
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
128+
<CodeAnalysisFailOnMissingRules>true</CodeAnalysisFailOnMissingRules>
129+
</PropertyGroup>
130+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'UnitTests|x64'">
131+
<DebugSymbols>true</DebugSymbols>
132+
<OutputPath>bin\x64\UnitTests\</OutputPath>
133+
<DefineConstants>DEBUG;TRACE</DefineConstants>
134+
<DebugType>full</DebugType>
135+
<PlatformTarget>x64</PlatformTarget>
136+
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
137+
<CodeAnalysisFailOnMissingRules>true</CodeAnalysisFailOnMissingRules>
138+
</PropertyGroup>
139+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugMono_x86|x64'">
140+
<DebugSymbols>true</DebugSymbols>
141+
<OutputPath>bin\x64\DebugMono_x86\</OutputPath>
142+
<DefineConstants>DEBUG;TRACE</DefineConstants>
143+
<DebugType>full</DebugType>
144+
<PlatformTarget>x64</PlatformTarget>
145+
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
146+
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
147+
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
148+
</PropertyGroup>
149+
<ItemGroup>
150+
<Compile Include="arraytest.cs" />
151+
<Compile Include="subclasstest.cs" />
152+
<Compile Include="classtest.cs" />
153+
<Compile Include="constructortests.cs" />
154+
<Compile Include="conversiontest.cs" />
155+
<Compile Include="delegatetest.cs" />
156+
<Compile Include="enumtest.cs" />
157+
<Compile Include="eventtest.cs" />
158+
<Compile Include="exceptiontest.cs" />
159+
<Compile Include="fieldtest.cs" />
160+
<Compile Include="generictest.cs" />
161+
<Compile Include="globaltest.cs" />
162+
<Compile Include="indexertest.cs" />
163+
<Compile Include="interfacetest.cs" />
164+
<Compile Include="methodtest.cs" />
165+
<Compile Include="propertytest.cs" />
166+
<Compile Include="threadtest.cs" />
167+
</ItemGroup>
168+
<ItemGroup>
169+
<Reference Include="System" />
170+
<Reference Include="System.Core">
171+
<RequiredTargetFramework>3.5</RequiredTargetFramework>
172+
</Reference>
173+
<Reference Include="System.Windows.Forms" />
174+
</ItemGroup>
175+
<ItemGroup>
176+
<ProjectReference Include="..\runtime\Python.Runtime.csproj">
177+
<Project>{097B4AC0-74E9-4C58-BCF8-C69746EC8271}</Project>
178+
<Name>Python.Runtime</Name>
179+
</ProjectReference>
180+
</ItemGroup>
181+
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
182+
<ProjectExtensions>
183+
<VisualStudio AllowExistingFolder="true" />
184+
</ProjectExtensions>
185+
<PropertyGroup>
186+
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)"
187+
copy "$(TargetDir)*.pdb" "$(SolutionDir)"
188+
</PostBuildEvent>
189+
</PropertyGroup>
190+
</Project>

README.md

+58-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,63 @@
11
pythonnet
22
=========
33

4-
Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers.
4+
Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers. It allows Python code to interact with the CLR, and may also be used to embed Python into a .NET application.
55

6-
[![Build Status](https://travis-ci.org/pythonnet/pythonnet.png?branch=develop)](https://travis-ci.org/pythonnet/pythonnet)
6+
[![Build Status](https://travis-ci.org/pythonnet/pythonnet.png?branch=master)](https://travis-ci.org/pythonnet/pythonnet)
77

8-
[![Build status](https://ci.appveyor.com/api/projects/status/65riiu1hvgaxsbwb)](https://ci.appveyor.com/project/davidanthoff/pythonnet)
8+
[![Build status](https://ci.appveyor.com/api/projects/status/c8k0miljb3n1c7be/branch/master)](https://ci.appveyor.com/project/TonyRoberts/pythonnet-480xs)
9+
10+
**Calling .NET code from Python**
11+
12+
Python for .NET allows CLR namespaces to be treated essentially as Python packages.
13+
14+
```python
15+
import clr
16+
from System import String
17+
from System.Collections import *
18+
```
19+
To load an assembly, use the "AddReference" function in the "clr" module:
20+
21+
```python
22+
import clr
23+
clr.AddReference("System.Windows.Forms")
24+
from System.Windows.Forms import Form
25+
```
26+
27+
**Embedding Python in .NET**
28+
29+
+ All calls to python should be inside a "using (Py.GIL()) {/* Your code here */}" block.
30+
+ Import python modules using dynamic mod = Py.Import("mod"), then you can call functions as normal, eg mod.func(args).
31+
+ Use mod.func(args, Py.kw("keywordargname", keywordargvalue)) to apply keyword arguments.
32+
+ All python objects should be declared as 'dynamic' type.
33+
+ Mathematical operations involving python and literal/managed types must have the python object first, eg np.pi*2 works, 2*np.pi doesn't
34+
35+
EG:
36+
```csharp
37+
static void Main(string[] args)
38+
{
39+
using (Py.GIL()) {
40+
dynamic np = Py.Import("numpy");
41+
dynamic sin = np.sin;
42+
Console.WriteLine(np.cos(np.pi*2));
43+
Console.WriteLine(sin(5));
44+
double c = np.cos(5) + sin(5);
45+
Console.WriteLine(c);
46+
dynamic a = np.array(new List<float> { 1, 2, 3 });
47+
dynamic b = np.array(new List<float> { 6, 5, 4 }, Py.kw("dtype", np.int32));
48+
Console.WriteLine(a.dtype);
49+
Console.WriteLine(b.dtype);
50+
Console.WriteLine(a * b);
51+
Console.ReadKey();
52+
}
53+
}
54+
```
55+
outputs:
56+
```
57+
1.0
58+
-0.958924274663
59+
-0.6752620892
60+
float64
61+
int32
62+
[ 6. 10. 12.]
63+
```

appveyor.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ environment:
99
- pythonurl: http://www.python.org/ftp/python/2.7.6/python-2.7.6.msi
1010
- pythonurl: http://www.python.org/ftp/python/2.6.6/python-2.6.6.msi
1111
- pythonurl: http://www.python.org/ftp/python/2.6.6/python-2.6.6.amd64.msi
12+
- pythonurl: http://www.python.org/ftp/python/3.2.3/python-3.2.3.msi
13+
- pythonurl: http://www.python.org/ftp/python/3.2.3/python-3.2.3.amd64.msi
14+
- pythonurl: http://www.python.org/ftp/python/3.4.2/python-3.4.2.msi
15+
- pythonurl: http://www.python.org/ftp/python/3.4.2/python-3.4.2.amd64.msi
1216

1317
install:
1418
- ps: (new-object net.webclient).DownloadFile($env:pythonurl, 'C:\python.msi')
@@ -19,6 +23,7 @@ install:
1923
- set PATH=C:\Python;%PATH%
2024
- C:\Python\python.exe c:\get-pip.py
2125
- C:\Python\Scripts\pip.exe install wheel
26+
- C:\Python\Scripts\pip.exe install six
2227

2328
build_script:
2429
- C:\python\python.exe setup.py bdist_wheel
@@ -28,4 +33,3 @@ test_script:
2833
- mkdir c:\testdir
2934
- ps: copy-item (gci -path build -re -include Python.Test.dll)[0].FullName c:\testdir
3035
- c:\python\python.exe src\tests\runtests.py
31-
- c:\python\scripts\npython.exe src\tests\runtests.py

0 commit comments

Comments
 (0)