You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2016/02/09 18:11:24 UTC
[07/12] lucy-clownfish git commit: Start runtime Python bindings.
Start runtime Python bindings.
Add setup.py which only runs charmonizer and cleanup targets. Add a
stub __init__.py file.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/856d7c1d
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/856d7c1d
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/856d7c1d
Branch: refs/heads/master
Commit: 856d7c1d84c619bcaa44cc992e575e8052af630a
Parents: b10130e
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Jan 19 18:25:51 2016 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Sat Feb 6 10:23:08 2016 -0800
----------------------------------------------------------------------
runtime/python/setup.py | 130 ++++++++++++++++++++++++++
runtime/python/src/clownfish/__init__.py | 15 +++
2 files changed, 145 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/856d7c1d/runtime/python/setup.py
----------------------------------------------------------------------
diff --git a/runtime/python/setup.py b/runtime/python/setup.py
new file mode 100644
index 0000000..a522cb9
--- /dev/null
+++ b/runtime/python/setup.py
@@ -0,0 +1,130 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from distutils.core import setup
+from distutils.command.build import build as _build
+from distutils.command.clean import clean as _clean
+from distutils.cmd import Command as _Command
+from distutils.dep_util import newer_group
+import distutils.ccompiler
+import os
+import glob
+import shutil
+import subprocess
+import sysconfig
+
+# Get a compiler object and and strings representing the compiler type and
+# CFLAGS. Add the Python headers include dir to CFLAGS.
+compiler = distutils.ccompiler.new_compiler()
+cflags = sysconfig.get_config_var('CFLAGS')
+compiler_type = distutils.ccompiler.get_default_compiler()
+
+# There's no public way to get a string representing the compiler executable
+# out of distutils, but the member variable has been in the same place for a
+# long time, so violating encapsulation may be ok.
+compiler_name = " ".join(compiler.compiler)
+make_command = "make" # TODO portability
+
+BASE_DIR = os.path.abspath(os.path.join(os.pardir, os.pardir))
+PARENT_DIR = os.path.abspath(os.pardir)
+CORE_SOURCE_DIR = os.path.join(PARENT_DIR, 'core')
+CFEXT_DIR = 'cfext'
+COMMON_SOURCE_DIR = os.path.join(PARENT_DIR, 'common')
+CHARMONIZER_C = os.path.join(COMMON_SOURCE_DIR, 'charmonizer.c')
+CHARMONIZER_EXE_NAME = compiler.executable_filename('charmonizer')
+CHARMONIZER_EXE_PATH = os.path.join(os.curdir, CHARMONIZER_EXE_NAME)
+CHARMONY_H_PATH = 'charmony.h'
+
+c_filepaths = []
+paths_to_clean = [
+ CHARMONIZER_EXE_PATH,
+ CHARMONY_H_PATH,
+ '_charm*',
+]
+
+def _quotify(text):
+ text = text.replace('\\', '\\\\')
+ text = text.replace('"', '\\"')
+ return '"' + text + '"'
+
+class charmony(_Command):
+ description = "Build and run charmonizer"
+ user_options = []
+ def initialize_options(self):
+ pass
+ def finalize_options(self):
+ pass
+ def run(self):
+ # Compile charmonizer.
+ if newer_group([CHARMONIZER_C], CHARMONIZER_EXE_PATH):
+ command = [compiler_name]
+ if compiler_type == 'msvc':
+ command.append('/Fe' + CHARMONIZER_EXE_PATH)
+ else:
+ command.extend(['-o', CHARMONIZER_EXE_PATH])
+ command.append(CHARMONIZER_C)
+ print(" ".join(command))
+ subprocess.check_call(command)
+
+ # Run charmonizer.
+ if newer_group([CHARMONIZER_EXE_PATH], CHARMONY_H_PATH):
+ command = [
+ CHARMONIZER_EXE_PATH,
+ '--cc=' + _quotify(compiler_name),
+ '--enable-c',
+ '--enable-python',
+ '--host=python',
+ '--enable-makefile',
+ '--',
+ cflags
+ ]
+ if 'CHARM_VALGRIND' in os.environ:
+ command[0:0] = "valgrind", "--leak-check=yes";
+ print(" ".join(command))
+ subprocess.check_call(command)
+
+class my_clean(_clean):
+ def run(self):
+ _clean.run(self)
+ if os.path.isfile("Makefile"):
+ subprocess.check_call([make_command, 'distclean'])
+ for elem in paths_to_clean:
+ for path in glob.glob(elem):
+ print("removing " + path)
+ if os.path.isdir(path):
+ shutil.rmtree(path)
+ else:
+ os.unlink(path)
+
+class my_build(_build):
+ def run(self):
+ self.run_command('charmony')
+ _build.run(self)
+
+setup(name = 'clownfish',
+ version = '0.4.0',
+ description = 'Clownfish runtime',
+ author = 'Apache Lucy Project',
+ author_email = 'dev at lucy dot apache dot org',
+ url = 'http://lucy.apache.org',
+ packages = ['clownfish',
+ ],
+ cmdclass = {
+ 'build': my_build,
+ 'clean': my_clean,
+ 'charmony': charmony,
+ },
+ package_dir={'': 'src'},)
+
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/856d7c1d/runtime/python/src/clownfish/__init__.py
----------------------------------------------------------------------
diff --git a/runtime/python/src/clownfish/__init__.py b/runtime/python/src/clownfish/__init__.py
new file mode 100644
index 0000000..09697dc
--- /dev/null
+++ b/runtime/python/src/clownfish/__init__.py
@@ -0,0 +1,15 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+