Commit cb7b498d authored by Michał Karzyński's avatar Michał Karzyński Committed by Robert Kimball

[Py] Apply PEP8 code style to setup.py (#1852)

* [Py] Apply PEP8 code style to setup.py

* Remove unused var

* Update version to 0.9.0
parent c85ff3b8
...@@ -21,7 +21,7 @@ import setuptools ...@@ -21,7 +21,7 @@ import setuptools
import os import os
import distutils.ccompiler import distutils.ccompiler
__version__ = '0.7.0' __version__ = '0.9.0'
PYNGRAPH_SOURCE_DIR = os.path.abspath(os.path.dirname(__file__)) PYNGRAPH_SOURCE_DIR = os.path.abspath(os.path.dirname(__file__))
NGRAPH_DEFAULT_INSTALL_DIR = os.environ.get('HOME') NGRAPH_DEFAULT_INSTALL_DIR = os.environ.get('HOME')
...@@ -36,8 +36,10 @@ def find_ngraph_dist_dir(): ...@@ -36,8 +36,10 @@ def find_ngraph_dist_dir():
found = os.path.exists(os.path.join(ngraph_dist_dir, 'include/ngraph')) found = os.path.exists(os.path.join(ngraph_dist_dir, 'include/ngraph'))
if not found: if not found:
print("Cannot find nGraph library in {} make sure that " print(
"NGRAPH_CPP_BUILD_PATH is set correctly".format(ngraph_dist_dir)) "Cannot find nGraph library in {} make sure that "
"NGRAPH_CPP_BUILD_PATH is set correctly".format(ngraph_dist_dir)
)
sys.exit(1) sys.exit(1)
else: else:
print("nGraph library found in {}".format(ngraph_dist_dir)) print("nGraph library found in {}".format(ngraph_dist_dir))
...@@ -52,8 +54,10 @@ def find_pybind_headers_dir(): ...@@ -52,8 +54,10 @@ def find_pybind_headers_dir():
found = os.path.exists(os.path.join(pybind_headers_dir, 'include/pybind11')) found = os.path.exists(os.path.join(pybind_headers_dir, 'include/pybind11'))
if not found: if not found:
print("Cannot find pybind11 library in {} make sure that " print(
"PYBIND_HEADERS_PATH is set correctly".format(pybind_headers_dir)) "Cannot find pybind11 library in {} make sure that "
"PYBIND_HEADERS_PATH is set correctly".format(pybind_headers_dir)
)
sys.exit(1) sys.exit(1)
else: else:
print("pybind11 library found in {}".format(pybind_headers_dir)) print("pybind11 library found in {}".format(pybind_headers_dir))
...@@ -66,13 +70,24 @@ NGRAPH_CPP_INCLUDE_DIR = NGRAPH_CPP_DIST_DIR + "/include" ...@@ -66,13 +70,24 @@ NGRAPH_CPP_INCLUDE_DIR = NGRAPH_CPP_DIST_DIR + "/include"
NGRAPH_CPP_LIBRARY_DIR = NGRAPH_CPP_DIST_DIR + "/lib" NGRAPH_CPP_LIBRARY_DIR = NGRAPH_CPP_DIST_DIR + "/lib"
# Parallel build from http://stackoverflow.com/questions/11013851/speeding-up-build-process-with-distutils # Parallel build from:
# http://stackoverflow.com/questions/11013851/speeding-up-build-process-with-distutils
# monkey-patch for parallel compilation # monkey-patch for parallel compilation
def parallelCCompile(self, sources, output_dir=None, macros=None, include_dirs=None, def parallelCCompile(
debug=0, extra_preargs=None, extra_postargs=None, depends=None): self,
sources,
output_dir=None,
macros=None,
include_dirs=None,
debug=0,
extra_preargs=None,
extra_postargs=None,
depends=None,
):
# those lines are copied from distutils.ccompiler.CCompiler directly # those lines are copied from distutils.ccompiler.CCompiler directly
macros, objects, extra_postargs, pp_opts, build = self._setup_compile( macros, objects, extra_postargs, pp_opts, build = self._setup_compile(
output_dir, macros, include_dirs, sources, depends, extra_postargs) output_dir, macros, include_dirs, sources, depends, extra_postargs
)
cc_args = self._get_cc_args(pp_opts, debug, extra_preargs) cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
# parallel code # parallel code
import multiprocessing.pool import multiprocessing.pool
...@@ -83,12 +98,13 @@ def parallelCCompile(self, sources, output_dir=None, macros=None, include_dirs=N ...@@ -83,12 +98,13 @@ def parallelCCompile(self, sources, output_dir=None, macros=None, include_dirs=N
except KeyError: except KeyError:
return return
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
# convert to list, imap is evaluated on-demand # convert to list, imap is evaluated on-demand
list(multiprocessing.pool.ThreadPool().imap(_single_compile, objects)) list(multiprocessing.pool.ThreadPool().imap(_single_compile, objects))
return objects return objects
distutils.ccompiler.CCompiler.compile=parallelCCompile distutils.ccompiler.CCompiler.compile = parallelCCompile
# As of Python 3.6, CCompiler has a `has_flag` method. # As of Python 3.6, CCompiler has a `has_flag` method.
...@@ -99,6 +115,7 @@ def has_flag(compiler, flagname): ...@@ -99,6 +115,7 @@ def has_flag(compiler, flagname):
the specified compiler. the specified compiler.
""" """
import tempfile import tempfile
with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f: with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f:
f.write('int main (int argc, char **argv) { return 0; }') f.write('int main (int argc, char **argv) { return 0; }')
try: try:
...@@ -118,11 +135,11 @@ def cpp_flag(compiler): ...@@ -118,11 +135,11 @@ def cpp_flag(compiler):
elif has_flag(compiler, '-std=c++11'): elif has_flag(compiler, '-std=c++11'):
return '-std=c++11' return '-std=c++11'
else: else:
raise RuntimeError('Unsupported compiler -- at least C++11 support ' raise RuntimeError('Unsupported compiler -- at least C++11 support is needed!')
'is needed!')
sources = ['pyngraph/function.cpp', sources = [
'pyngraph/function.cpp',
'pyngraph/serializer.cpp', 'pyngraph/serializer.cpp',
'pyngraph/node.cpp', 'pyngraph/node.cpp',
'pyngraph/node_vector.cpp', 'pyngraph/node_vector.cpp',
...@@ -216,67 +233,84 @@ sources = ['pyngraph/function.cpp', ...@@ -216,67 +233,84 @@ sources = ['pyngraph/function.cpp',
'pyngraph/passes/regmodule_pyngraph_passes.cpp', 'pyngraph/passes/regmodule_pyngraph_passes.cpp',
'pyngraph/types/element_type.cpp', 'pyngraph/types/element_type.cpp',
'pyngraph/types/regmodule_pyngraph_types.cpp', 'pyngraph/types/regmodule_pyngraph_types.cpp',
] ]
package_dir={'ngraph': PYNGRAPH_SOURCE_DIR + "/ngraph", package_dir = {
'ngraph': PYNGRAPH_SOURCE_DIR + "/ngraph",
'ngraph.utils': PYNGRAPH_SOURCE_DIR + "/ngraph/utils", 'ngraph.utils': PYNGRAPH_SOURCE_DIR + "/ngraph/utils",
'ngraph.impl': PYNGRAPH_SOURCE_DIR + "/ngraph/impl", 'ngraph.impl': PYNGRAPH_SOURCE_DIR + "/ngraph/impl",
'ngraph.impl.op': PYNGRAPH_SOURCE_DIR + "/ngraph/impl/op", 'ngraph.impl.op': PYNGRAPH_SOURCE_DIR + "/ngraph/impl/op",
'ngraph.impl.op.util': PYNGRAPH_SOURCE_DIR + "/ngraph/impl/op/util", 'ngraph.impl.op.util': PYNGRAPH_SOURCE_DIR + "/ngraph/impl/op/util",
'ngraph.impl.passes': PYNGRAPH_SOURCE_DIR + "/ngraph/impl/passes", 'ngraph.impl.passes': PYNGRAPH_SOURCE_DIR + "/ngraph/impl/passes",
'ngraph.impl.runtime': PYNGRAPH_SOURCE_DIR + "/ngraph/impl/runtime"} 'ngraph.impl.runtime': PYNGRAPH_SOURCE_DIR + "/ngraph/impl/runtime",
packages = ['ngraph', 'ngraph.utils', 'ngraph.impl', 'ngraph.impl.op', }
'ngraph.impl.op.util', 'ngraph.impl.passes', 'ngraph.impl.runtime'] packages = [
'ngraph',
'ngraph.utils',
'ngraph.impl',
'ngraph.impl.op',
'ngraph.impl.op.util',
'ngraph.impl.passes',
'ngraph.impl.runtime',
]
sources = [PYNGRAPH_SOURCE_DIR + "/" + source for source in sources] sources = [PYNGRAPH_SOURCE_DIR + "/" + source for source in sources]
include_dirs = [PYNGRAPH_SOURCE_DIR, include_dirs = [PYNGRAPH_SOURCE_DIR, NGRAPH_CPP_INCLUDE_DIR, PYBIND11_INCLUDE_DIR]
NGRAPH_CPP_INCLUDE_DIR,
PYBIND11_INCLUDE_DIR,
]
library_dirs = [NGRAPH_CPP_LIBRARY_DIR, library_dirs = [NGRAPH_CPP_LIBRARY_DIR]
]
libraries = ["ngraph", libraries = ["ngraph"]
]
extra_compile_args = [] extra_compile_args = []
extra_link_args = [] extra_link_args = []
data_files = [('lib', [NGRAPH_CPP_LIBRARY_DIR + "/" + library for library in os.listdir(NGRAPH_CPP_LIBRARY_DIR)]),] data_files = [
(
'lib',
[
NGRAPH_CPP_LIBRARY_DIR + "/" + library
for library in os.listdir(NGRAPH_CPP_LIBRARY_DIR)
],
)
]
ext_modules = [Extension( ext_modules = [
Extension(
'_pyngraph', '_pyngraph',
sources = sources, sources=sources,
include_dirs = include_dirs, include_dirs=include_dirs,
define_macros = [("VERSION_INFO", __version__)], define_macros=[("VERSION_INFO", __version__)],
library_dirs = library_dirs, library_dirs=library_dirs,
libraries = libraries, libraries=libraries,
extra_link_args = extra_link_args, extra_link_args=extra_link_args,
language = "c++", language="c++",
) )
] ]
if os.environ.get('NGRAPH_ONNX_IMPORT_ENABLE') == 'TRUE':
if(os.environ.get('NGRAPH_ONNX_IMPORT_ENABLE') == 'TRUE'): onnx_sources = [
onnx_sources = ['pyngraph/pyngraph_onnx_import.cpp'] 'pyngraph/pyngraph_onnx_import.cpp',
onnx_sources.append('pyngraph/onnx_import/onnx_import.cpp') 'pyngraph/onnx_import/onnx_import.cpp',
]
onnx_sources = [PYNGRAPH_SOURCE_DIR + "/" + source for source in onnx_sources] onnx_sources = [PYNGRAPH_SOURCE_DIR + "/" + source for source in onnx_sources]
package_dir['ngraph.impl.onnx_import'] = PYNGRAPH_SOURCE_DIR + "/ngraph/impl/onnx_import" package_dir['ngraph.impl.onnx_import'] = (
PYNGRAPH_SOURCE_DIR + "/ngraph/impl/onnx_import"
)
packages.append('ngraph.impl.onnx_import') packages.append('ngraph.impl.onnx_import')
ext_modules.append(Extension( ext_modules.append(
Extension(
'_pyngraph_onnx_import', '_pyngraph_onnx_import',
sources = onnx_sources, sources=onnx_sources,
include_dirs = include_dirs, include_dirs=include_dirs,
define_macros = [("VERSION_INFO", __version__)], define_macros=[("VERSION_INFO", __version__)],
library_dirs = library_dirs, library_dirs=library_dirs,
libraries = libraries, libraries=libraries,
extra_link_args = extra_link_args, extra_link_args=extra_link_args,
language = "c++", language="c++",
) )
) )
...@@ -285,8 +319,8 @@ class BuildExt(build_ext): ...@@ -285,8 +319,8 @@ class BuildExt(build_ext):
""" """
A custom build extension for adding compiler-specific options. A custom build extension for adding compiler-specific options.
""" """
def build_extensions(self): def build_extensions(self):
ct = self.compiler.compiler_type
for ext in self.extensions: for ext in self.extensions:
ext.extra_compile_args += [cpp_flag(self.compiler)] ext.extra_compile_args += [cpp_flag(self.compiler)]
if has_flag(self.compiler, '-fstack-protector-strong'): if has_flag(self.compiler, '-fstack-protector-strong'):
...@@ -296,7 +330,10 @@ class BuildExt(build_ext): ...@@ -296,7 +330,10 @@ class BuildExt(build_ext):
if has_flag(self.compiler, '-frtti'): if has_flag(self.compiler, '-frtti'):
ext.extra_compile_args += ['-frtti'] ext.extra_compile_args += ['-frtti']
if sys.platform == 'darwin': if sys.platform == 'darwin':
ext.extra_compile_args += ['-stdlib=libc++', '-mmacosx-version-min=10.7'] ext.extra_compile_args += [
'-stdlib=libc++',
'-mmacosx-version-min=10.7',
]
ext.extra_link_args += ["-Wl,-rpath,@loader_path/../.."] ext.extra_link_args += ["-Wl,-rpath,@loader_path/../.."]
else: else:
if has_flag(self.compiler, '-fvisibility=hidden'): if has_flag(self.compiler, '-fvisibility=hidden'):
...@@ -314,7 +351,6 @@ class BuildExt(build_ext): ...@@ -314,7 +351,6 @@ class BuildExt(build_ext):
with open(os.path.join(PYNGRAPH_SOURCE_DIR, 'requirements.txt')) as req: with open(os.path.join(PYNGRAPH_SOURCE_DIR, 'requirements.txt')) as req:
requirements = req.read().splitlines() requirements = req.read().splitlines()
setup( setup(
name='ngraph', name='ngraph',
version=__version__, version=__version__,
...@@ -326,9 +362,9 @@ setup( ...@@ -326,9 +362,9 @@ setup(
long_description='', long_description='',
ext_modules=ext_modules, ext_modules=ext_modules,
package_dir=package_dir, package_dir=package_dir,
packages = packages, packages=packages,
cmdclass={'build_ext': BuildExt}, cmdclass={'build_ext': BuildExt},
data_files = data_files, data_files=data_files,
install_requires = requirements, install_requires=requirements,
zip_safe=False, zip_safe=False,
) )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment