🌐 AI搜索 & 代理 主页
Skip to content
This repository was archived by the owner on Jul 22, 2023. It is now read-only.

Commit 125eb7b

Browse files
committed
Merge branch 'release-2.1'
2 parents 3510dd8 + 8f88861 commit 125eb7b

File tree

177 files changed

+6925
-1432
lines changed

Some content is hidden

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

177 files changed

+6925
-1432
lines changed

.travis.yml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1+
sudo: required
12
language: python
23
python:
34
- 2.6
45
- 2.7
6+
- 3.2
7+
- 3.4
8+
- 3.5
59
before_install:
6-
- sudo apt-get install software-properties-common
710
- sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ trusty main universe"
8-
- sudo apt-get -qq update
9-
- sudo apt-get -qq install mono-devel mono-gmcs mono-xbuild nunit-console
10-
- sudo mozroots --import --machine --sync
11-
- yes | sudo certmgr -ssl -m https://go.microsoft.com
12-
- yes | sudo certmgr -ssl -m https://nugetgallery.blob.core.windows.net
13-
- yes | sudo certmgr -ssl -m https://nuget.org
11+
- sudo apt-get install software-properties-common
12+
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
13+
- echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
14+
- echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
15+
- sudo apt-get update
16+
- sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" install mono-devel mono-complete referenceassemblies-pcl ca-certificates-mono nunit-console
17+
1418
install:
19+
- pip install six
20+
- pip install pycparser
1521
- python setup.py build_ext --inplace
1622
script:
17-
- export PYTHONPATH=`pwd`
18-
- ./npython src/tests/runtests.py
23+
- export PYTHONPATH=`pwd`:$PYTHONPATH
24+
- python src/tests/runtests.py

CONTRIBUTING.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# How to contribute
2+
3+
PythonNet is developed and maintained by unpaid community members so well
4+
written, documented and tested pull requests are encouraged.
5+
6+
## Getting Started
7+
8+
* Make sure you have a [GitHub account](https://github.com/signup/free)
9+
* Submit a ticket for your issue, assuming one does not already exist.
10+
* Clearly describe the issue including steps to reproduce when it is a bug.
11+
* Make sure you include what Python version and operating system you are using.
12+
* Fork the repository on GitHub
13+
14+
## Making Changes
15+
16+
* Create a topic branch from where you want to base your work.
17+
* This is usually the develop branch.
18+
* Only target release branches if you are certain your fix must be on that
19+
branch.
20+
* To quickly create a topic branch based on develop; `git checkout -b
21+
fix/develop/my_contribution develop`. Please avoid working directly on the
22+
`master` branch.
23+
* Make commits of logical units.
24+
* Check for unnecessary whitespace with `git diff --check` before committing.
25+
* Make sure your commit messages are in the proper format.
26+
* Make sure you have added the necessary tests for your changes.
27+
* Run _all_ the tests to assure nothing else was accidentally broken.
28+
29+
30+
## Submitting Changes
31+
32+
* Push your changes to a topic branch in your fork of the repository.
33+
* Submit a pull request to the repository in the pythonnet organization.
34+
* After feedback has been given we expect responses within two weeks. After two
35+
weeks we may close the pull request if it isn't showing any activity.
36+
37+
# Additional Resources
38+
39+
* [General GitHub documentation](https://help.github.com/)
40+
* [GitHub pull request documentation](https://help.github.com/send-pull-requests/)

Python.Runtime.dll.config

Lines changed: 6 additions & 0 deletions
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

Lines changed: 190 additions & 0 deletions
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

Lines changed: 56 additions & 1 deletion
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

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

88
[![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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,33 @@ os: Windows Server 2012
33
environment:
44
global:
55
PYTHONPATH: c:\testdir
6+
PYTHONWARNINGS: 'ignore:::pip.pep425tags:'
67

78
matrix:
8-
- pythonurl: http://www.python.org/ftp/python/2.7.6/python-2.7.6.amd64.msi
9-
- pythonurl: http://www.python.org/ftp/python/2.7.6/python-2.7.6.msi
10-
- pythonurl: http://www.python.org/ftp/python/2.6.6/python-2.6.6.msi
11-
- pythonurl: http://www.python.org/ftp/python/2.6.6/python-2.6.6.amd64.msi
9+
# http://www.appveyor.com/docs/installed-software#python
10+
- PYTHON: "C:\\Python27"
11+
- PYTHON: "C:\\Python27-x64"
12+
- PYTHON: "C:\\Python33"
13+
- PYTHON: "C:\\Python33-x64"
14+
- PYTHON: "C:\\Python34"
15+
- PYTHON: "C:\\Python34-x64"
16+
- PYTHON: "C:\\Python35"
17+
- PYTHON: "C:\\Python35-x64"
1218

1319
install:
14-
- ps: (new-object net.webclient).DownloadFile($env:pythonurl, 'C:\python.msi')
15-
- ps: start-process -wait -FilePath msiexec.exe -ArgumentList "/qn /i C:\python.msi TARGETDIR=C:\Python"
16-
- ps: (new-object net.webclient).DownloadFile('https://raw.github.com/pypa/pip/master/contrib/get-pip.py', 'C:\get-pip.py')
17-
# appveyor has python 2.7.6 x86 preinstalled, but in the wrong directory, this works around this
18-
- ps: if ($env:pythonurl -eq "http://www.python.org/ftp/python/2.7.6/python-2.7.6.msi") {mi c:\python27 c:\python}
19-
- set PATH=C:\Python;%PATH%
20-
- C:\Python\python.exe c:\get-pip.py
21-
- C:\Python\Scripts\pip.exe install wheel
20+
- "%PYTHON%\\python.exe -m pip install --upgrade pip"
21+
- "%PYTHON%\\python.exe -m pip install wheel"
22+
- "%PYTHON%\\python.exe -m pip install six"
2223

2324
build_script:
24-
- C:\python\python.exe setup.py bdist_wheel
25+
- "%PYTHON%\\python.exe setup.py bdist_wheel"
2526

2627
test_script:
27-
- ps: C:\python\scripts\pip.exe install ("dist\" + (gci dist)[0].Name)
28+
- ps: '& "$env:PYTHON\\Scripts\\pip.exe" install --no-cache-dir --force-reinstall --ignore-installed ("dist\\" + (gci dist)[0].Name)'
2829
- mkdir c:\testdir
2930
- ps: copy-item (gci -path build -re -include Python.Test.dll)[0].FullName c:\testdir
30-
- c:\python\python.exe src\tests\runtests.py
31-
- c:\python\scripts\npython.exe src\tests\runtests.py
31+
- "%PYTHON%\\python.exe src\\tests\\runtests.py"
32+
33+
artifacts:
34+
# bdist_wheel puts your built wheel in the dist directory
35+
- path: dist\*

0 commit comments

Comments
 (0)