Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
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
9 changes: 3 additions & 6 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ if /i [%1] == [--buildDotNetBridgeOnly] (
if /i [%1] == [--skipDotNetBridge] (
set SkipDotNetBridge=True
shift && goto :Arg_Loop
)
else goto :Usage
) else goto :Usage

:Usage
echo "Usage: build.cmd [--configuration <Configuration>] [--runTests] [--buildDotNetBridgeOnly] [--skipDotNetBridge]"
Expand Down Expand Up @@ -187,8 +186,7 @@ if "%VisualStudioVersion%"=="15.0" (
goto :VS2017
) else if "%VisualStudioVersion%"=="14.0" (
goto :VS2015
)
else goto :MissingVersion
) else goto :MissingVersion

:MissingVersion
:: Can't find VS 2015 or 2017
Expand Down Expand Up @@ -261,8 +259,7 @@ copy "%BuildOutputDir%%Configuration%\pybridge.pyd" "%__currentScriptDir%src\py

if %PythonVersion% == 2.7 (
copy "%BuildOutputDir%%Configuration%\Platform\win-x64\publish\*.dll" "%__currentScriptDir%src\python\nimbusml\internal\libs\"
)
else (
) else (
for /F "tokens=*" %%A in (build/libs_win.txt) do copy "%BuildOutputDir%%Configuration%\Platform\win-x64\publish\%%A" "%__currentScriptDir%src\python\nimbusml\internal\libs\"
)

Expand Down
20 changes: 3 additions & 17 deletions src/python/nimbusml/internal/utils/entrypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import functools
import json
import os
import pkg_resources
import tempfile
from collections import OrderedDict
from enum import Enum
Expand All @@ -23,7 +22,7 @@
from .data_stream import FileDataStream
from .dataframes import resolve_dataframe, resolve_csr_matrix, pd_concat, \
resolve_output
from .utils import try_set
from .utils import try_set, set_clr_environment_vars, get_clr_path
from ..libs.pybridge import px_call


Expand Down Expand Up @@ -453,21 +452,8 @@ def remove_multi_level_index(c):
call_parameters['dotnetClrPath'] = try_set(nimbusml_path, True, str)
# dotnetcore2 package is available only for python 3.x
if six.PY3:
from dotnetcore2 import runtime as clr_runtime
dependencies_path = None
try:
# try to resolve dependencies, for ex. libunwind
dependencies_path = clr_runtime.ensure_dependencies()
except:
pass
os.environ['DOTNET_SYSTEM_GLOBALIZATION_INVARIANT'] = 'true'
if dependencies_path is not None:
os.environ['LD_LIBRARY_PATH'] = dependencies_path
dotnet_module = pkg_resources.get_distribution('dotnetcore2')
dotnet_path = os.path.join(
dotnet_module.module_path, 'dotnetcore2', 'bin', 'shared',
'Microsoft.NETCore.App', dotnet_module.version)
call_parameters['dotnetClrPath'] = try_set(dotnet_path, True, str)
set_clr_environment_vars()
call_parameters['dotnetClrPath'] = try_set(get_clr_path(), True, str)
if random_state:
call_parameters['seed'] = try_set(random_state, False, int)
ret = self._try_call_bridge(
Expand Down
42 changes: 42 additions & 0 deletions src/python/nimbusml/internal/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import logging
import os
import pkg_resources
import tempfile
from datetime import datetime

Expand Down Expand Up @@ -276,3 +277,44 @@ def set_shape(pred, X):
pred.input_shape_ = (len(X), len(X[0]))
else:
pred.input_shape_ = (len(X), 1)

def set_clr_environment_vars():
"""
Set system environment variables required by the .NET CLR.
Python 3.x only, as dotnetcore2 is not available for Python 2.x.
"""
from dotnetcore2 import runtime as clr_runtime
dependencies_path = None
try:
# try to resolve dependencies, for ex. libunwind
dependencies_path = clr_runtime.ensure_dependencies()
except:
pass
os.environ['DOTNET_SYSTEM_GLOBALIZATION_INVARIANT'] = 'true'
if dependencies_path is not None:
os.environ['LD_LIBRARY_PATH'] = dependencies_path

def get_clr_path():
"""
Return path to .NET CLR binaries.
Python 3.x only, as dotnetcore2 is not available for Python 2.x.
"""
from dotnetcore2 import runtime as clr_runtime
clr_version = pkg_resources.get_distribution('dotnetcore2').version
partial_path = os.path.join(clr_runtime._get_bin_folder(), 'shared', 'Microsoft.NETCore.App')
clr_path = os.path.join(partial_path, clr_version)
if not os.path.exists(clr_path):
# If folder name does not match published version, use the folder that
# exists
try:
version_folder = os.listdir(partial_path)[0]
except IndexError:
raise ImportError("Trouble importing dotnetcore2: "
"{} had no version folder.".format(partial_path))
clr_path = os.path.join(partial_path, version_folder)
# Verify binaries are present
if not os.path.exists(os.path.join(clr_path, 'Microsoft.CSharp.dll')):
raise ImportError(
"Trouble importing dotnetcore2: Microsoft.CSharp.dll was not "
"found in {}.".format(clr_path))
return clr_path