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

Skip to content

install packages using nuget in setup.py and cosmetic changes to make more PEP8 compliant #28

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

Merged
merged 2 commits into from
Mar 19, 2014
Merged
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
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ before_install:
- sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ trusty main universe"
- sudo apt-get -qq update
- sudo apt-get -qq install mono-devel mono-gmcs mono-xbuild nunit-console
- sudo mozroots --import --machine --sync
- yes | sudo certmgr -ssl -m https://go.microsoft.com
- yes | sudo certmgr -ssl -m https://nugetgallery.blob.core.windows.net
- yes | sudo certmgr -ssl -m https://nuget.org
install:
- cd pythonnet
- python setup.py build_ext --inplace
Expand Down
71 changes: 52 additions & 19 deletions pythonnet/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,47 @@
CONFIG = "Release" # Release or Debug
DEVTOOLS = "MsDev" if sys.platform == "win32" else "Mono"
VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic
PLATFORM = "x64" if architecture()[0] == "64bit" else "x86"

def FindMsBuildPath():

def _find_msbuild_path():
"""Return full path to msbuild.exe"""
import _winreg

aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
hreg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
try:
keysToCheck = [r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\12.0", r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0", r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\3.5", r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\2.0"]
aKey = None
for key in keysToCheck:
keys_to_check = [
r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\12.0",
r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0",
r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\3.5",
r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\2.0"
]
hkey = None
for key in keys_to_check:
try:
aKey = _winreg.OpenKey(aReg, key)
hkey = _winreg.OpenKey(hreg, key)
break
except WindowsError:
pass

if aKey==None:
raise RuntimeError("MSBUILD.exe could not be found")
if hkey is None:
raise RuntimeError("msbuild.exe could not be found")

try:
val, type = _winreg.QueryValueEx(aKey, "MSBuildToolsPath")

if type!=_winreg.REG_SZ:
raise RuntimeError("MSBUILD.exe could not be found")
val, type_ = _winreg.QueryValueEx(hkey, "MSBuildToolsPath")
if type_ != _winreg.REG_SZ:
raise RuntimeError("msbuild.exe could not be found")
finally:
aKey.Close()
hkey.Close()
finally:
aReg.Close()
hreg.Close()

msbuildpath = os.path.join(val, "msbuild.exe")
return msbuildpath


if DEVTOOLS == "MsDev":
_xbuild = "\"%s\"" % FindMsBuildPath()
_xbuild = "\"%s\"" % _find_msbuild_path()
_defines_sep = ";"
_config = "%sWin" % CONFIG
_npython_exe = "nPython.exe"
Expand All @@ -64,7 +71,6 @@ def FindMsBuildPath():
else:
raise NotImplementedError("DevTools %s not supported (use MsDev or Mono)" % DEVTOOLS)

_platform = "x64" if architecture()[0] == "64bit" else "x86"

class PythonNET_BuildExt(build_ext):

Expand All @@ -75,6 +81,9 @@ def build_extension(self, ext):
if ext.name != "clr":
return build_ext.build_extension(self, ext)

# install packages using nuget
self._install_packages()

dest_file = self.get_ext_fullpath(ext.name)
dest_dir = os.path.dirname(dest_file)
if not os.path.exists(dest_dir):
Expand All @@ -92,15 +101,16 @@ def build_extension(self, ext):
_xbuild,
"pythonnet.sln",
"/p:Configuration=%s" % _config,
"/p:Platform=%s" % _platform,
"/p:Platform=%s" % PLATFORM,
"/p:DefineConstants=\"%s\"" % _defines_sep.join(defines),
"/p:PythonBuildDir=%s" % os.path.abspath(dest_dir),
"/verbosity:%s" % VERBOSITY,
]

self.announce("Building: %s" % " ".join(cmd))
check_call(" ".join(cmd + ["/t:Clean"]), shell=(True if DEVTOOLS=="Mono" else False))
check_call(" ".join(cmd + ["/t:Build"]), shell=(True if DEVTOOLS=="Mono" else False))
use_shell = True if DEVTOOLS == "Mono" else False
check_call(" ".join(cmd + ["/t:Clean"]), shell=use_shell)
check_call(" ".join(cmd + ["/t:Build"]), shell=use_shell)

if DEVTOOLS == "Mono":
self._build_monoclr(ext)
Expand Down Expand Up @@ -157,6 +167,29 @@ def _build_monoclr(self, ext):
debug=self.debug)


def _install_packages(self):
"""install packages using nuget"""
nuget = os.path.join("tools", "nuget", "nuget.exe")
use_shell = False
if DEVTOOLS == "Mono":
nuget = "mono %s" % nuget
use_shell = True

for dir in os.listdir("src"):
if DEVTOOLS == "Mono" and dir == "clrmodule":
continue
if DEVTOOLS != "Mono" and dir == "monoclr":
continue

packages_cfg = os.path.join("src", dir, "packages.config")
if not os.path.exists(packages_cfg):
continue

cmd = "%s install %s -o packages" % (nuget, packages_cfg)
self.announce("Installng packages for %s: %s" % (dir, cmd))
check_call(cmd, shell=use_shell)


class PythonNET_InstallLib(install_lib):

def install(self):
Expand Down