From 48a4eb4f19d2894f9b782a0c937f983ba2ceeed2 Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Sun, 7 Apr 2019 13:18:48 +0200 Subject: [PATCH 1/2] Convert README to rst and drop pypandoc build dep --- README.md | 112 ---------------------------------------------------- README.rst | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 6 +-- 3 files changed, 114 insertions(+), 117 deletions(-) delete mode 100644 README.md create mode 100644 README.rst diff --git a/README.md b/README.md deleted file mode 100644 index 7e859481d..000000000 --- a/README.md +++ /dev/null @@ -1,112 +0,0 @@ -# pythonnet - Python for .NET - -[![Join the chat at https://gitter.im/pythonnet/pythonnet](https://badges.gitter.im/pythonnet/pythonnet.svg)](https://gitter.im/pythonnet/pythonnet?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - -[![appveyor shield][]](https://ci.appveyor.com/project/pythonnet/pythonnet/branch/master) -[![travis shield][]](https://travis-ci.org/pythonnet/pythonnet) -[![codecov shield][]](https://codecov.io/github/pythonnet/pythonnet) -[![coverity shield][]](https://scan.coverity.com/projects/pythonnet) - -[![license shield][]](./LICENSE) -[![pypi package version][]](https://pypi.python.org/pypi/pythonnet) -[![python supported shield][]](https://pypi.python.org/pypi/pythonnet) -[![stackexchange shield][]](http://stackoverflow.com/questions/tagged/python.net) -[![slack][]](https://pythonnet.slack.com) - -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. - -## Calling .NET code from Python - -Python for .NET allows CLR namespaces to be treated essentially -as Python packages. - -```python -import clr -from System import String -from System.Collections import * -``` - -To load an assembly, use the `AddReference` function in the `clr` module: - -```python -import clr -clr.AddReference("System.Windows.Forms") -from System.Windows.Forms import Form -``` - -## Embedding Python in .NET - -- All calls to python should be inside - a `using (Py.GIL()) {/* Your code here */}` block. -- Import python modules using `dynamic mod = Py.Import("mod")`, - then you can call functions as normal, eg `mod.func(args)`. -- Use `mod.func(args, Py.kw("keywordargname", keywordargvalue))` or `mod.func(args, keywordargname: keywordargvalue)` - to apply keyword arguments. -- All python objects should be declared as `dynamic` type. -- Mathematical operations involving python and literal/managed types must - have the python object first, eg. `np.pi * 2` works, `2 * np.pi` doesn't. - -### Example - -```csharp -static void Main(string[] args) -{ - using (Py.GIL()) - { - dynamic np = Py.Import("numpy"); - Console.WriteLine(np.cos(np.pi * 2)); - - dynamic sin = np.sin; - Console.WriteLine(sin(5)); - - double c = np.cos(5) + sin(5); - Console.WriteLine(c); - - dynamic a = np.array(new List { 1, 2, 3 }); - Console.WriteLine(a.dtype); - - dynamic b = np.array(new List { 6, 5, 4 }, dtype: np.int32); - Console.WriteLine(b.dtype); - - Console.WriteLine(a * b); - Console.ReadKey(); - } -} -``` - -Output: - -```c -1.0 --0.958924274663 --0.6752620892 -float64 -int32 -[ 6. 10. 12.] -``` - -Information on installation, FAQ, troubleshooting, debugging, and projects using pythonnet can be found in the Wiki: - -https://github.com/pythonnet/pythonnet/wiki - -[appveyor shield]: https://img.shields.io/appveyor/ci/pythonnet/pythonnet/master.svg?label=AppVeyor - -[codecov shield]: https://img.shields.io/codecov/c/github/pythonnet/pythonnet/master.svg?label=Codecov - -[coverity shield]: https://img.shields.io/coverity/scan/7830.svg - -[license shield]: https://img.shields.io/badge/license-MIT-blue.svg?maxAge=3600 - -[pypi package version]: https://img.shields.io/pypi/v/pythonnet.svg - -[python supported shield]: https://img.shields.io/pypi/pyversions/pythonnet.svg - -[slack]: https://img.shields.io/badge/chat-slack-color.svg?style=social - -[stackexchange shield]: https://img.shields.io/badge/StackOverflow-python.net-blue.svg - -[travis shield]: https://img.shields.io/travis/pythonnet/pythonnet/master.svg?label=Travis diff --git a/README.rst b/README.rst new file mode 100644 index 000000000..7cffbe19b --- /dev/null +++ b/README.rst @@ -0,0 +1,113 @@ +pythonnet - Python for .NET +=========================== + +|Join the chat at https://gitter.im/pythonnet/pythonnet| + +|appveyor shield| |travis shield| |codecov shield| + +|license shield| |pypi package version| |python supported shield| +|stackexchange shield| + +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. + +Calling .NET code from Python +----------------------------- + +Python for .NET allows CLR namespaces to be treated essentially as +Python packages. + +.. code-block:: + + import clr + from System import String + from System.Collections import * + +To load an assembly, use the ``AddReference`` function in the ``clr`` +module: + +.. code-block:: + + import clr + clr.AddReference("System.Windows.Forms") + from System.Windows.Forms import Form + +Embedding Python in .NET +------------------------ + +- All calls to python should be inside a + ``using (Py.GIL()) {/* Your code here */}`` block. +- Import python modules using ``dynamic mod = Py.Import("mod")``, then + you can call functions as normal, eg ``mod.func(args)``. +- Use ``mod.func(args, Py.kw("keywordargname", keywordargvalue))`` or + ``mod.func(args, keywordargname: keywordargvalue)`` to apply keyword + arguments. +- All python objects should be declared as ``dynamic`` type. +- Mathematical operations involving python and literal/managed types + must have the python object first, eg. ``np.pi * 2`` works, + ``2 * np.pi`` doesn’t. + +Example +~~~~~~~ + +.. code-block:: csharp + + static void Main(string[] args) + { + using (Py.GIL()) + { + dynamic np = Py.Import("numpy"); + Console.WriteLine(np.cos(np.pi * 2)); + + dynamic sin = np.sin; + Console.WriteLine(sin(5)); + + double c = np.cos(5) + sin(5); + Console.WriteLine(c); + + dynamic a = np.array(new List { 1, 2, 3 }); + Console.WriteLine(a.dtype); + + dynamic b = np.array(new List { 6, 5, 4 }, dtype: np.int32); + Console.WriteLine(b.dtype); + + Console.WriteLine(a * b); + Console.ReadKey(); + } + } + +Output: + +.. code:: + + 1.0 + -0.958924274663 + -0.6752620892 + float64 + int32 + [ 6. 10. 12.] + +Information on installation, FAQ, troubleshooting, debugging, and +projects using pythonnet can be found in the Wiki: + +https://github.com/pythonnet/pythonnet/wiki + +.. |Join the chat at https://gitter.im/pythonnet/pythonnet| image:: https://badges.gitter.im/pythonnet/pythonnet.svg + :target: https://gitter.im/pythonnet/pythonnet?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge +.. |appveyor shield| image:: https://img.shields.io/appveyor/ci/pythonnet/pythonnet/master.svg?label=AppVeyor + :target: https://ci.appveyor.com/project/pythonnet/pythonnet/branch/master +.. |travis shield| image:: https://img.shields.io/travis/pythonnet/pythonnet/master.svg?label=Travis + :target: https://travis-ci.org/pythonnet/pythonnet +.. |codecov shield| image:: https://img.shields.io/codecov/c/github/pythonnet/pythonnet/master.svg?label=Codecov + :target: https://codecov.io/github/pythonnet/pythonnet +.. |license shield| image:: https://img.shields.io/badge/license-MIT-blue.svg?maxAge=3600 + :target: ./LICENSE +.. |pypi package version| image:: https://img.shields.io/pypi/v/pythonnet.svg + :target: https://pypi.python.org/pypi/pythonnet +.. |python supported shield| image:: https://img.shields.io/pypi/pyversions/pythonnet.svg + :target: https://pypi.python.org/pypi/pythonnet +.. |stackexchange shield| image:: https://img.shields.io/badge/StackOverflow-python.net-blue.svg + :target: http://stackoverflow.com/questions/tagged/python.net diff --git a/setup.py b/setup.py index f5690962a..c9960ad87 100644 --- a/setup.py +++ b/setup.py @@ -132,11 +132,7 @@ def _get_source_files(): def _get_long_description(): """Helper to populate long_description for pypi releases""" - try: - import pypandoc - return pypandoc.convert('README.md', 'rst') - except ImportError: - return '.Net and Mono integration for Python' + return open("README.rst").read() def _update_xlat_devtools(): global DEVTOOLS From 1765cbc5202a9e301a5ae1ebcdab533c4339f6ea Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Sun, 7 Apr 2019 13:24:17 +0200 Subject: [PATCH 2/2] Run black on setup.py --- setup.py | 375 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 239 insertions(+), 136 deletions(-) diff --git a/setup.py b/setup.py index c9960ad87..818241f0d 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ CONFIG = "Release" # Release or Debug VERBOSITY = "normal" # quiet, minimal, normal, detailed, diagnostic -is_64bits = sys.maxsize > 2**32 +is_64bits = sys.maxsize > 2 ** 32 DEVTOOLS = "MsDev" if sys.platform == "win32" else "Mono" ARCH = "x64" if is_64bits else "x86" PY_MAJOR = sys.version_info[0] @@ -32,7 +32,7 @@ ############################################################################### # Windows Keys Constants for MSBUILD tools -RegKey = collections.namedtuple('RegKey', 'sdk_name key value_name suffix') +RegKey = collections.namedtuple("RegKey", "sdk_name key value_name suffix") vs_python = "Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\WinSDK" vs_root = "SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\{0}" sdks_root = "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v{0}Win32Tools" @@ -40,55 +40,105 @@ kits_suffix = os.path.join("bin", ARCH) WIN_SDK_KEYS = [ - RegKey(sdk_name="Windows Kit 10.0", key=kits_root, - value_name="KitsRoot10", suffix=os.path.join("bin", "10.0.16299.0", ARCH)), - - RegKey(sdk_name="Windows Kit 10.0", key=kits_root, - value_name="KitsRoot10", suffix=os.path.join("bin", "10.0.15063.0", ARCH)), - - RegKey(sdk_name="Windows Kit 10.0", key=kits_root, - value_name="KitsRoot10", suffix=kits_suffix), - - RegKey(sdk_name="Windows Kit 8.1", key=kits_root, - value_name="KitsRoot81", suffix=kits_suffix), - - RegKey(sdk_name="Windows Kit 8.0", key=kits_root, - value_name="KitsRoot", suffix=kits_suffix), - - RegKey(sdk_name="Windows SDK 7.1A", key=sdks_root.format("7.1A\\WinSDK-"), - value_name="InstallationFolder", suffix=""), - - RegKey(sdk_name="Windows SDK 7.1", key=sdks_root.format("7.1\\WinSDK"), - value_name="InstallationFolder", suffix=""), - - RegKey(sdk_name="Windows SDK 7.0A", key=sdks_root.format("7.0A\\WinSDK-"), - value_name="InstallationFolder", suffix=""), - - RegKey(sdk_name="Windows SDK 7.0", key=sdks_root.format("7.0\\WinSDK"), - value_name="InstallationFolder", suffix=""), - - RegKey(sdk_name="Windows SDK 6.0A", key=sdks_root.format("6.0A\\WinSDK"), - value_name="InstallationFolder", suffix=""), + RegKey( + sdk_name="Windows Kit 10.0", + key=kits_root, + value_name="KitsRoot10", + suffix=os.path.join("bin", "10.0.16299.0", ARCH), + ), + RegKey( + sdk_name="Windows Kit 10.0", + key=kits_root, + value_name="KitsRoot10", + suffix=os.path.join("bin", "10.0.15063.0", ARCH), + ), + RegKey( + sdk_name="Windows Kit 10.0", + key=kits_root, + value_name="KitsRoot10", + suffix=kits_suffix, + ), + RegKey( + sdk_name="Windows Kit 8.1", + key=kits_root, + value_name="KitsRoot81", + suffix=kits_suffix, + ), + RegKey( + sdk_name="Windows Kit 8.0", + key=kits_root, + value_name="KitsRoot", + suffix=kits_suffix, + ), + RegKey( + sdk_name="Windows SDK 7.1A", + key=sdks_root.format("7.1A\\WinSDK-"), + value_name="InstallationFolder", + suffix="", + ), + RegKey( + sdk_name="Windows SDK 7.1", + key=sdks_root.format("7.1\\WinSDK"), + value_name="InstallationFolder", + suffix="", + ), + RegKey( + sdk_name="Windows SDK 7.0A", + key=sdks_root.format("7.0A\\WinSDK-"), + value_name="InstallationFolder", + suffix="", + ), + RegKey( + sdk_name="Windows SDK 7.0", + key=sdks_root.format("7.0\\WinSDK"), + value_name="InstallationFolder", + suffix="", + ), + RegKey( + sdk_name="Windows SDK 6.0A", + key=sdks_root.format("6.0A\\WinSDK"), + value_name="InstallationFolder", + suffix="", + ), ] VS_KEYS = ( - RegKey(sdk_name="MSBuild 15", key=vs_root.format("15.0"), - value_name="MSBuildToolsPath", suffix=""), - - RegKey(sdk_name="MSBuild 14", key=vs_root.format("14.0"), - value_name="MSBuildToolsPath", suffix=""), - - RegKey(sdk_name="MSBuild 12", key=vs_root.format("12.0"), - value_name="MSBuildToolsPath", suffix=""), - - RegKey(sdk_name="MSBuild 4", key=vs_root.format("4.0"), - value_name="MSBuildToolsPath", suffix=""), - - RegKey(sdk_name="MSBuild 3.5", key=vs_root.format("3.5"), - value_name="MSBuildToolsPath", suffix=""), - - RegKey(sdk_name="MSBuild 2.0", key=vs_root.format("2.0"), - value_name="MSBuildToolsPath", suffix=""), + RegKey( + sdk_name="MSBuild 15", + key=vs_root.format("15.0"), + value_name="MSBuildToolsPath", + suffix="", + ), + RegKey( + sdk_name="MSBuild 14", + key=vs_root.format("14.0"), + value_name="MSBuildToolsPath", + suffix="", + ), + RegKey( + sdk_name="MSBuild 12", + key=vs_root.format("12.0"), + value_name="MSBuildToolsPath", + suffix="", + ), + RegKey( + sdk_name="MSBuild 4", + key=vs_root.format("4.0"), + value_name="MSBuildToolsPath", + suffix="", + ), + RegKey( + sdk_name="MSBuild 3.5", + key=vs_root.format("3.5"), + value_name="MSBuildToolsPath", + suffix="", + ), + RegKey( + sdk_name="MSBuild 2.0", + key=vs_root.format("2.0"), + value_name="MSBuildToolsPath", + suffix="", + ), ) @@ -108,19 +158,19 @@ def _get_interop_filename(): required to generate the file. """ interop_filename = "interop{0}{1}{2}.cs".format( - PY_MAJOR, PY_MINOR, getattr(sys, "abiflags", "")) + PY_MAJOR, PY_MINOR, getattr(sys, "abiflags", "") + ) return os.path.join("src", "runtime", interop_filename) def _get_source_files(): """Walk project and collect the files needed for ext_module""" - for ext in (".sln", ): + for ext in (".sln",): for path in glob.glob("*" + ext): yield path for root, dirnames, filenames in os.walk("src"): - for ext in (".cs", ".csproj", ".snk", ".config", - ".py", ".c", ".h", ".ico"): + for ext in (".cs", ".csproj", ".snk", ".config", ".py", ".c", ".h", ".ico"): for filename in fnmatch.filter(filenames, "*" + ext): yield os.path.join(root, filename) @@ -134,6 +184,7 @@ def _get_long_description(): """Helper to populate long_description for pypi releases""" return open("README.rst").read() + def _update_xlat_devtools(): global DEVTOOLS if DEVTOOLS == "MsDev": @@ -141,12 +192,15 @@ def _update_xlat_devtools(): elif DEVTOOLS == "Mono": DEVTOOLS = "dotnet" + def _collect_installed_windows_kits_v10(winreg): """Adds the installed Windows 10 kits to WIN_SDK_KEYS """ global WIN_SDK_KEYS installed_kits = [] - with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, kits_root, 0, winreg.KEY_READ) as key: + with winreg.OpenKey( + winreg.HKEY_LOCAL_MACHINE, kits_root, 0, winreg.KEY_READ + ) as key: i = 0 while True: try: @@ -156,18 +210,22 @@ def _collect_installed_windows_kits_v10(winreg): break def make_reg_key(version): - return RegKey(sdk_name="Windows Kit 10.0", key=kits_root, - value_name="KitsRoot10", suffix=os.path.join("bin", version, ARCH)) + return RegKey( + sdk_name="Windows Kit 10.0", + key=kits_root, + value_name="KitsRoot10", + suffix=os.path.join("bin", version, ARCH), + ) - WIN_SDK_KEYS += [make_reg_key(e) for e in installed_kits if e.startswith('10.')] + WIN_SDK_KEYS += [make_reg_key(e) for e in installed_kits if e.startswith("10.")] # Make sure this function won't be called again - _collect_installed_windows_kits_v10 = (lambda:None) + _collect_installed_windows_kits_v10 = lambda: None + class BuildExtPythonnet(build_ext.build_ext): - user_options = build_ext.build_ext.user_options + [ - ('xplat', None, None) - ] + user_options = build_ext.build_ext.user_options + [("xplat", None, None)] + def initialize_options(self): build_ext.build_ext.initialize_options(self) self.xplat = None @@ -177,7 +235,7 @@ def finalize_options(self): def build_extension(self, ext): if self.xplat: - _update_xlat_devtools() + _update_xlat_devtools() """Builds the .pyd file using msbuild or xbuild""" if ext.name != "clr": @@ -198,6 +256,7 @@ def build_extension(self, ext): unicode_width = 2 if sys.maxunicode < 0x10FFFF else 4 else: import ctypes + unicode_width = ctypes.sizeof(ctypes.c_wchar) defines = [ @@ -219,7 +278,7 @@ def build_extension(self, ext): # Double-check if libpython is linked dynamically with python ldd_cmd = ["otool", "-L"] if on_darwin else ["ldd"] lddout = _check_output(ldd_cmd + [sys.executable]) - if 'libpython' not in lddout: + if "libpython" not in lddout: enable_shared = False if not enable_shared: @@ -241,36 +300,41 @@ def build_extension(self, ext): if DEVTOOLS == "MsDev": _xbuild = '"{0}"'.format(self._find_msbuild_tool("msbuild.exe")) _config = "{0}Win".format(CONFIG) - _solution_file = 'pythonnet.sln' + _solution_file = "pythonnet.sln" _custom_define_constants = False elif DEVTOOLS == "MsDev15": - _xbuild = '"{0}"'.format(self._find_msbuild_tool_15()) + _xbuild = '"{0}"'.format(self._find_msbuild_tool_15()) _config = "{0}Win".format(CONFIG) - _solution_file = 'pythonnet.15.sln' + _solution_file = "pythonnet.15.sln" _custom_define_constants = True elif DEVTOOLS == "Mono": - _xbuild = 'xbuild' + _xbuild = "xbuild" _config = "{0}Mono".format(CONFIG) - _solution_file = 'pythonnet.sln' + _solution_file = "pythonnet.sln" _custom_define_constants = False elif DEVTOOLS == "dotnet": - _xbuild = 'dotnet msbuild' + _xbuild = "dotnet msbuild" _config = "{0}Mono".format(CONFIG) - _solution_file = 'pythonnet.15.sln' + _solution_file = "pythonnet.15.sln" _custom_define_constants = True else: raise NotImplementedError( - "DevTool {0} not supported (use MsDev/MsDev15/Mono/dotnet)".format(DEVTOOLS)) + "DevTool {0} not supported (use MsDev/MsDev15/Mono/dotnet)".format( + DEVTOOLS + ) + ) cmd = [ _xbuild, _solution_file, - '/p:Configuration={}'.format(_config), - '/p:Platform={}'.format(ARCH), - '/p:{}DefineConstants="{}"'.format('Custom' if _custom_define_constants else '','%3B'.join(defines)), + "/p:Configuration={}".format(_config), + "/p:Platform={}".format(ARCH), + '/p:{}DefineConstants="{}"'.format( + "Custom" if _custom_define_constants else "", "%3B".join(defines) + ), '/p:PythonBuildDir="{}"'.format(os.path.abspath(dest_dir)), '/p:PythonInteropFile="{}"'.format(os.path.basename(interop_file)), - '/verbosity:{}'.format(VERBOSITY), + "/verbosity:{}".format(VERBOSITY), ] manifest = self._get_manifest(dest_dir) @@ -283,7 +347,16 @@ def build_extension(self, ext): subprocess.check_call(" ".join(cmd + ["/t:Clean"]), shell=use_shell) subprocess.check_call(" ".join(cmd + ["/t:Build"]), shell=use_shell) if DEVTOOLS == "MsDev15" or DEVTOOLS == "dotnet": - subprocess.check_call(" ".join(cmd + ['"/t:Console_15:publish;Python_EmbeddingTest_15:publish"', "/p:TargetFramework=netcoreapp2.0"]), shell=use_shell) + subprocess.check_call( + " ".join( + cmd + + [ + '"/t:Console_15:publish;Python_EmbeddingTest_15:publish"', + "/p:TargetFramework=netcoreapp2.0", + ] + ), + shell=use_shell, + ) if DEVTOOLS == "Mono" or DEVTOOLS == "dotnet": self._build_monoclr() @@ -292,8 +365,11 @@ def _get_manifest(self, build_dir): return mt = self._find_msbuild_tool("mt.exe", use_windows_sdk=True) manifest = os.path.abspath(os.path.join(build_dir, "app.manifest")) - cmd = [mt, '-inputresource:"{0}"'.format(sys.executable), - '-out:"{0}"'.format(manifest)] + cmd = [ + mt, + '-inputresource:"{0}"'.format(sys.executable), + '-out:"{0}"'.format(manifest), + ] self.debug_print("Extracting manifest from {}".format(sys.executable)) subprocess.check_call(" ".join(cmd), shell=False) return manifest @@ -315,12 +391,9 @@ def _build_monoclr(self): # build the clr python module clr_ext = Extension( "clr", - sources=[ - "src/monoclr/pynetinit.c", - "src/monoclr/clrmod.c" - ], + sources=["src/monoclr/pynetinit.c", "src/monoclr/clrmod.c"], extra_compile_args=cflags.split(" "), - extra_link_args=libs.split(" ") + extra_link_args=libs.split(" "), ) build_ext.build_ext.build_extension(self, clr_ext) @@ -335,7 +408,9 @@ def _install_packages(self): elif DEVTOOLS == "dotnet": _config = "{0}Mono".format(CONFIG) - cmd = "dotnet msbuild /t:Restore pythonnet.15.sln /p:Configuration={0} /p:Platform={1}".format(_config, ARCH) + cmd = "dotnet msbuild /t:Restore pythonnet.15.sln /p:Configuration={0} /p:Platform={1}".format( + _config, ARCH + ) self.debug_print("Updating packages with xplat: {0}".format(cmd)) subprocess.check_call(cmd, shell=use_shell) else: @@ -350,7 +425,9 @@ def _install_packages(self): try: # msbuild=14 is mainly for Mono issues - cmd = "{0} restore pythonnet.sln -MSBuildVersion 14 -o packages".format(nuget) + cmd = "{0} restore pythonnet.sln -MSBuildVersion 14 -o packages".format( + nuget + ) self.debug_print("Installing packages: {0}".format(cmd)) subprocess.check_call(cmd, shell=use_shell) except: @@ -363,17 +440,30 @@ def _find_msbuild_tool(self, tool="msbuild.exe", use_windows_sdk=False): """Return full path to one of the Microsoft build tools""" # trying to search path with help of vswhere when MSBuild 15.0 and higher installed. - if tool=="msbuild.exe" and use_windows_sdk==False: + if tool == "msbuild.exe" and use_windows_sdk == False: try: basePathes = subprocess.check_output( - ["tools\\vswhere\\vswhere.exe", "-latest", - "-version", "[15.0, 16.0)", - "-requires", "Microsoft.Component.MSBuild", - "-property", "InstallationPath"]).splitlines() + [ + "tools\\vswhere\\vswhere.exe", + "-latest", + "-version", + "[15.0, 16.0)", + "-requires", + "Microsoft.Component.MSBuild", + "-property", + "InstallationPath", + ] + ).splitlines() if len(basePathes): - return os.path.join(basePathes[0].decode(sys.stdout.encoding or "utf-8"), "MSBuild", "15.0", "Bin", "MSBuild.exe") + return os.path.join( + basePathes[0].decode(sys.stdout.encoding or "utf-8"), + "MSBuild", + "15.0", + "Bin", + "MSBuild.exe", + ) except: - pass # keep trying to search by old method. + pass # keep trying to search by old method. # Search in PATH first path = spawn.find_executable(tool) @@ -398,8 +488,9 @@ def _find_msbuild_tool(self, tool="msbuild.exe", use_windows_sdk=False): continue path = os.path.join(val, rkey.suffix, tool) if os.path.exists(path): - self.debug_print("Using {0} from {1}".format( - tool, rkey.sdk_name)) + self.debug_print( + "Using {0} from {1}".format(tool, rkey.sdk_name) + ) return path except WindowsError: # Key doesn't exist @@ -423,22 +514,40 @@ def _find_msbuild_tool_15(self): """Return full path to one of the Microsoft build tools""" try: basePathes = subprocess.check_output( - ["tools\\vswhere\\vswhere.exe", "-latest", - "-version", "[15.0, 16.0)", - "-requires", "Microsoft.Component.MSBuild", - "-property", "InstallationPath"]).splitlines() + [ + "tools\\vswhere\\vswhere.exe", + "-latest", + "-version", + "[15.0, 16.0)", + "-requires", + "Microsoft.Component.MSBuild", + "-property", + "InstallationPath", + ] + ).splitlines() if len(basePathes): - return os.path.join(basePathes[0].decode(sys.stdout.encoding or "utf-8"), "MSBuild", "15.0", "Bin", "MSBuild.exe") + return os.path.join( + basePathes[0].decode(sys.stdout.encoding or "utf-8"), + "MSBuild", + "15.0", + "Bin", + "MSBuild.exe", + ) else: raise RuntimeError("MSBuild >=15.0 could not be found.") except subprocess.CalledProcessError as e: - raise RuntimeError("MSBuild >=15.0 could not be found. {0}".format(e.output)) + raise RuntimeError( + "MSBuild >=15.0 could not be found. {0}".format(e.output) + ) + class InstallLibPythonnet(install_lib.install_lib): def install(self): if not os.path.isdir(self.build_dir): - self.warn("'{0}' does not exist -- no Python modules" - " to install".format(self.build_dir)) + self.warn( + "'{0}' does not exist -- no Python modules" + " to install".format(self.build_dir) + ) return if not os.path.exists(self.install_dir): @@ -446,8 +555,7 @@ def install(self): # only copy clr.pyd/.so for srcfile in glob.glob(os.path.join(self.build_dir, "clr.*")): - destfile = os.path.join( - self.install_dir, os.path.basename(srcfile)) + destfile = os.path.join(self.install_dir, os.path.basename(srcfile)) self.copy_file(srcfile, destfile) @@ -456,8 +564,7 @@ def run(self): build_cmd = self.get_finalized_command("build_ext") install_cmd = self.get_finalized_command("install") build_lib = os.path.abspath(build_cmd.build_lib) - install_platlib = os.path.relpath( - install_cmd.install_platlib, self.install_dir) + install_platlib = os.path.relpath(install_cmd.install_platlib, self.install_dir) for i, data_files in enumerate(self.data_files): if isinstance(data_files, str): @@ -470,10 +577,10 @@ def run(self): return install_data.install_data.run(self) + class InstallPythonnet(install.install): - user_options = install.install.user_options + [ - ('xplat', None, None) - ] + user_options = install.install.user_options + [("xplat", None, None)] + def initialize_options(self): install.install.initialize_options(self) self.xplat = None @@ -486,10 +593,10 @@ def run(self): _update_xlat_devtools() return install.install.run(self) + class BDistWheelPythonnet(bdist_wheel.bdist_wheel): - user_options = bdist_wheel.bdist_wheel.user_options + [ - ('xplat', None, None) - ] + user_options = bdist_wheel.bdist_wheel.user_options + [("xplat", None, None)] + def initialize_options(self): bdist_wheel.bdist_wheel.initialize_options(self) self.xplat = None @@ -503,6 +610,8 @@ def run(self): return bdist_wheel.bdist_wheel.run(self) ############################################################################### + + setupdir = os.path.dirname(__file__) if setupdir: os.chdir(setupdir) @@ -515,42 +624,36 @@ def run(self): name="pythonnet", version="2.4.0.dev0", description=".Net and Mono integration for Python", - url='https://pythonnet.github.io/', - license='MIT', + url="https://pythonnet.github.io/", + license="MIT", author="The Python for .Net developers", author_email="pythondotnet@python.org", setup_requires=setup_requires, long_description=_get_long_description(), - ext_modules=[ - Extension("clr", sources=list(_get_source_files())) - ], - data_files=[ - ("{install_platlib}", [ - "{build_lib}/Python.Runtime.dll", - ]), - ], + ext_modules=[Extension("clr", sources=list(_get_source_files()))], + data_files=[("{install_platlib}", ["{build_lib}/Python.Runtime.dll"])], cmdclass={ "install": InstallPythonnet, "build_ext": BuildExtPythonnet, "install_lib": InstallLibPythonnet, "install_data": InstallDataPythonnet, - "bdist_wheel": BDistWheelPythonnet + "bdist_wheel": BDistWheelPythonnet, }, classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: C#', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX :: Linux', - 'Operating System :: MacOS :: MacOS X', + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Programming Language :: C#", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Operating System :: Microsoft :: Windows", + "Operating System :: POSIX :: Linux", + "Operating System :: MacOS :: MacOS X", ], zip_safe=False, )