Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 166a3d2

Browse files
committed
Format setup, geninterop, demo
And removed unneded file
1 parent cf5035c commit 166a3d2

File tree

6 files changed

+62
-42
lines changed

6 files changed

+62
-42
lines changed

demo/helloform.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
14
import clr
25

36
SWF = clr.AddReference("System.Windows.Forms")
@@ -13,7 +16,7 @@ class HelloApp(WinForms.Form):
1316
def __init__(self):
1417
self.Text = "Hello World From Python"
1518
self.AutoScaleBaseSize = Size(5, 13)
16-
self.ClientSize = Size(392, 117);
19+
self.ClientSize = Size(392, 117)
1720
h = WinForms.SystemInformation.CaptionHeight
1821
self.MinimumSize = Size(392, (117 + h))
1922

@@ -36,8 +39,8 @@ def __init__(self):
3639

3740
# Add the controls to the form
3841
self.AcceptButton = self.button
39-
self.Controls.Add(self.button);
40-
self.Controls.Add(self.textbox);
42+
self.Controls.Add(self.button)
43+
self.Controls.Add(self.textbox)
4144

4245
def button_Click(self, sender, args):
4346
"""Button click event handler"""

demo/splitter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
14
import clr
5+
6+
import System
27
import System.Windows.Forms as WinForms
8+
39
from System.Drawing import Color, Size, Point
4-
import System
510

611

712
class Splitter(WinForms.Form):

demo/wordpad.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
14
import clr
5+
import System
26
import System.Windows.Forms as WinForms
3-
from System.Threading import Thread, ThreadStart, ApartmentState
4-
from System.Drawing import Color, Size, Point
5-
from System.Text import Encoding
7+
68
from System.IO import File
7-
import System
9+
from System.Text import Encoding
10+
from System.Drawing import Color, Point, Size
11+
from System.Threading import ApartmentState, Thread, ThreadStart
812

913

1014
class Wordpad(WinForms.Form):

setup.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
14
"""
25
Setup script for building clr.pyd and dependencies using mono and into
36
an egg or wheel.
47
"""
8+
59
from setuptools import setup, Extension
610
from distutils.command.build_ext import build_ext
711
from distutils.command.install_lib import install_lib
@@ -23,7 +27,7 @@
2327

2428

2529
def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
26-
"""Return full path to one of the microsoft build tools"""
30+
"""Return full path to one of the Microsoft build tools"""
2731
path = find_executable(tool)
2832
if path:
2933
return path
@@ -82,7 +86,8 @@ def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
8286
finally:
8387
hreg.Close()
8488

85-
# Add Visual C++ for Python as a fallback in case one of the other Windows SDKs isn't installed
89+
# Add Visual C++ for Python as a fall-back in case one
90+
# of the other Windows SDKs isn't installed
8691
if use_windows_sdk:
8792
localappdata = os.environ["LOCALAPPDATA"]
8893
pywinsdk = localappdata + r"\Programs\Common\Microsoft\Visual C++ for Python\9.0\WinSDK\Bin"
@@ -110,14 +115,13 @@ def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
110115
_config = "%sMono" % CONFIG
111116

112117
else:
113-
raise NotImplementedError("DevTools %s not supported (use MsDev or Mono)" % DEVTOOLS)
118+
raise NotImplementedError(
119+
"DevTools %s not supported (use MsDev or Mono)" % DEVTOOLS)
114120

115121

116122
class PythonNET_BuildExt(build_ext):
117123
def build_extension(self, ext):
118-
"""
119-
Builds the .pyd file using msbuild or xbuild.
120-
"""
124+
"""Builds the .pyd file using msbuild or xbuild"""
121125
if ext.name != "clr":
122126
return build_ext.build_extension(self, ext)
123127

@@ -129,8 +133,8 @@ def build_extension(self, ext):
129133
if not os.path.exists(dest_dir):
130134
os.makedirs(dest_dir)
131135

132-
# Up to Python 3.2 sys.maxunicode is used to determine the size of Py_UNICODE
133-
# but from 3.3 onwards Py_UNICODE is a typedef of wchar_t.
136+
# Up to Python 3.2 sys.maxunicode is used to determine the size of
137+
# Py_UNICODE, but from 3.3 onwards Py_UNICODE is a typedef of wchar_t.
134138
if sys.version_info[:2] <= (3, 2):
135139
unicode_width = 2 if sys.maxunicode < 0x10FFFF else 4
136140
else:
@@ -204,7 +208,8 @@ def _get_manifest(self, build_dir):
204208
if DEVTOOLS == "MsDev" and sys.version_info[:2] > (2, 5):
205209
mt = _find_msbuild_tool("mt.exe", use_windows_sdk=True)
206210
manifest = os.path.abspath(os.path.join(build_dir, "app.manifest"))
207-
cmd = [mt, '-inputresource:"%s"' % sys.executable, '-out:"%s"' % manifest]
211+
cmd = [mt, '-inputresource:"%s"' % sys.executable,
212+
'-out:"%s"' % manifest]
208213
self.announce("Extracting manifest from %s" % sys.executable)
209214
check_call(" ".join(cmd), shell=False)
210215
return manifest
@@ -282,8 +287,7 @@ def run(self):
282287

283288
def _check_output(*popenargs, **kwargs):
284289
"""subprocess.check_output from python 2.7.
285-
Added here to support building for earlier versions
286-
of Python.
290+
Added here to support building for earlier versions of Python.
287291
"""
288292
process = Popen(stdout=PIPE, *popenargs, **kwargs)
289293
output, unused_err = process.communicate()
@@ -304,7 +308,7 @@ def _get_interop_filename():
304308
as most windows users won't have Clang installed, which is
305309
required to generate the file.
306310
"""
307-
interop_file = "interop%d%s%s.cs" % (sys.version_info[0], sys.version_info[1], getattr(sys, "abiflags", ""))
311+
interop_file = "interop%d%d%s.cs" % (sys.version_info[0], sys.version_info[1], getattr(sys, "abiflags", ""))
308312
return os.path.join("src", "runtime", interop_file)
309313

310314

@@ -336,18 +340,21 @@ def _get_interop_filename():
336340
name="pythonnet",
337341
version="2.2.0",
338342
description=".Net and Mono integration for Python",
339-
url='http://pythonnet.github.io/',
340-
author="Python for .Net developers",
343+
url='https://pythonnet.github.io/',
344+
license='MIT',
345+
author="The Python for .Net developers",
341346
classifiers=[
347+
'Development Status :: 5 - Production/Stable',
348+
'Intended Audience :: Developers',
349+
'License :: OSI Approved :: MIT License',
350+
'Programming Language :: C#',
351+
'Programming Language :: Python :: 2',
342352
'Programming Language :: Python :: 2.7',
353+
'Programming Language :: Python :: 3',
343354
'Programming Language :: Python :: 3.3',
344355
'Programming Language :: Python :: 3.4',
345356
'Programming Language :: Python :: 3.5',
346357
'Programming Language :: Python :: 3.6',
347-
'Programming Language :: C#',
348-
'License :: OSI Approved :: MIT License',
349-
'Development Status :: 5 - Production/Stable',
350-
'Intended Audience :: Developers',
351358
'Operating System :: Microsoft :: Windows',
352359
'Operating System :: POSIX :: Linux',
353360
'Operating System :: MacOS :: MacOS X',

src/embed_tests/Embeddingtest.nunit

Lines changed: 0 additions & 7 deletions
This file was deleted.

tools/geninterop/geninterop.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
14
"""
25
TypeOffset is a C# class that mirrors the in-memory layout of heap
36
allocated Python objects.
@@ -9,6 +12,9 @@
912
- pycparser
1013
- clang
1114
"""
15+
16+
from __future__ import print_function
17+
1218
from distutils.sysconfig import get_config_var
1319
from subprocess import Popen, CalledProcessError, PIPE
1420
from pycparser import c_parser, c_ast
@@ -86,8 +92,8 @@ def visit_struct(self, struct):
8692
self.__struct_members_stack.pop(0)
8793
self.__struct_stack.pop(0)
8894
elif self.__ptr_decl_depth:
89-
# the struct is empty, but add it as a member to the current struct
90-
# as the current member maybe a pointer to it.
95+
# the struct is empty, but add it as a member to the current
96+
# struct as the current member maybe a pointer to it.
9197
self.__add_struct_member(struct.name)
9298

9399
def visit_decl(self, decl):
@@ -109,7 +115,8 @@ def __add_struct_member(self, type_name):
109115
# add member to current struct
110116
current_struct = self.__struct_stack[0]
111117
member_name = self.__struct_members_stack[0]
112-
struct_members = self.__struct_members.setdefault(self.__get_struct_name(current_struct), [])
118+
struct_members = self.__struct_members.setdefault(
119+
self.__get_struct_name(current_struct), [])
113120

114121
# get the node associated with this type
115122
node = None
@@ -118,7 +125,8 @@ def __add_struct_member(self, type_name):
118125
elif type_name in self.__structs:
119126
node = self.__structs[type_name]
120127

121-
# If it's a struct (and not a pointer to a struct) expand it into the current struct definition
128+
# If it's a struct (and not a pointer to a struct) expand
129+
# it into the current struct definition
122130
if not self.__ptr_decl_depth and isinstance(node, c_ast.Struct):
123131
for decl in node.decls or []:
124132
self.__struct_members_stack.insert(0, decl.name)
@@ -141,8 +149,7 @@ def __get_struct_name(self, node):
141149

142150
def check_output(*popenargs, **kwargs):
143151
"""subprocess.check_output from python 2.7.
144-
Added here to support building for earlier versions
145-
of Python.
152+
Added here to support building for earlier versions of Python.
146153
"""
147154
process = Popen(stdout=PIPE, *popenargs, **kwargs)
148155
output, unused_err = process.communicate()
@@ -161,7 +168,8 @@ def preprocess_python_headers():
161168
"""Return Python.h pre-processed, ready for parsing.
162169
Requires clang.
163170
"""
164-
fake_libc_include = os.path.join(os.path.dirname(__file__), "fake_libc_include")
171+
fake_libc_include = os.path.join(os.path.dirname(__file__),
172+
"fake_libc_include")
165173
include_dirs = [fake_libc_include]
166174

167175
include_py = get_config_var("INCLUDEPY")
@@ -198,7 +206,7 @@ def gen_interop_code(members):
198206
"""Generate the TypeOffset C# class"""
199207

200208
defines = [
201-
"PYTHON%d%s" % (sys.version_info[:2])
209+
"PYTHON%d%d" % (sys.version_info[:2])
202210
]
203211

204212
if hasattr(sys, "abiflags"):
@@ -278,7 +286,7 @@ def main():
278286
interop_cs = gen_interop_code(members)
279287

280288
if len(sys.argv) > 1:
281-
with open(sys.argv[1], "wt") as fh:
289+
with open(sys.argv[1], "w") as fh:
282290
fh.write(interop_cs)
283291
else:
284292
print(interop_cs)

0 commit comments

Comments
 (0)