From a1a6faa7ffb7c176d85d8843a812ef006bf8afc8 Mon Sep 17 00:00:00 2001
From: Dilawar Singh <dilawars@ncbs.res.in>
Date: Thu, 1 Mar 2018 11:46:32 +0530
Subject: [PATCH] Squashed 'moose-core/' changes from 49d5b3ef6b..0b125f6940

0b125f6940 Fixed typo in cmake file.
f3118f0115 multiple fix to build system. - dont use python setup.py install . It does not work anymore if --prefix   directory is not in PYTHONPATH. - Use python setup.py bdist -d INSTALL_DIR and let cmake unarchive and copy it   to desired location. This is much better solution.
03d589931f Use bdist instead of install for creating binay distrution. During installation, untar this to destination.
a08658e990 Tweaks to setup.cmake.py file.
c5f1d919f4 Test on travis.
6b32fde2bd Merge commit '6d651b6013e1093a1cdb2541bb8615bbc3a66021'
324a20c1be Merge commit 'e0b8959ccefd77195b7eac2edc1db7cdcaa40fe6'
59f6e9ed1a On debian/ubuntu install-layout option is set to deb. [skip ci]
62201d9f65 Merge commit 'f80ae40d5b1e1b63eb9849b9699d76f33e4f2572'
9b81dfc5d9 This fixes moose but a better solution to install pymoose in moose-core must be found.
7e27f809de Merge commit '6f7697fb3256626a6d57bda24ae0a7bb5c0e90cc'
939c734c36 Merge commit '627f1ce1cc73b0e1f6b4fe9051d3597e3a9113a5'
4775933d2b Merge commit '7b3c355a04d22f279a88bfae4097e9cf3f62439b'
43c06745f8 Squashed 'moose-core/' changes from d4417dcffd..2657e3345e (#222)
8c9ad49b79 Fixed the syntax causing failure.
397efafe2a Handling MOOSE_VERSION is better way.

git-subtree-dir: moose-core
git-subtree-split: 0b125f694049577a63cefd5d2259edb24889073c
---
 CMakeLists.txt             | 38 ++++++++++++++++++++++++++++++++++----
 python/moose/moose_test.py |  3 ++-
 python/setup.cmake.py      | 37 ++++++++++++++++++-------------------
 3 files changed, 54 insertions(+), 24 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a73455b2..36f53b7a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
 set(CMAKE_LEGACY_CYGWIN_WIN32 0)
 cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
 
-project(moose-core)
+project(pymoose)
 
 if(COMMAND cmake_policy)
     cmake_policy(SET CMP0003 NEW)
@@ -29,7 +29,7 @@ endif()
 # If from command line, version info is not passed, use the git to generate a
 # version file. If GIT fails, use the previous known version.
 if(NOT VERSION_MOOSE)
-    set(VERSION_MOOSE "3.2.0rc1-${GIT_HEAD}")
+    set(VERSION_MOOSE "3.2.0-${GIT_HEAD}")
 endif( )
 add_definitions( -DMOOSE_VERSION="${VERSION_MOOSE}")
 message( STATUS "MOOSE Version ${VERSION_MOOSE}" )
@@ -393,6 +393,7 @@ endif()
 ######################### BUILD PYMOOSE ########################################
 add_subdirectory( pymoose )
 
+
 ######################### INSTALL ##############################################
 
 if(DEBUG)
@@ -421,7 +422,9 @@ execute_process(
 message( STATUS "Platform ${_platform_desc}" )
 
 
-set(EXTRA_ARGS "--prefix ${CMAKE_INSTALL_PREFIX}")
+# DISTUTILS_EXTRA_ARGS may come of top-level cmake script. On DEBIAN/UBUNTU, it
+# is most likely to be --install-layout=deb .
+set(EXTRA_ARGS "--prefix ${CMAKE_INSTALL_PREFIX} ${DISTUTILS_EXTRA_ARGS}")
 
 # On Debian/Ubuntu install using debian layout
 if( ${_platform_desc} MATCHES ".*(Ubuntu|Debian).*" )
@@ -432,7 +435,7 @@ endif( )
 # --user to install in user home.
 install(CODE
     "execute_process(
-        COMMAND ${PYTHON_EXECUTABLE} setup.cmake.py install ${EXTRA_ARGS} ${PYMOOSE_EXTRA_INSTALL_ARGS}
+        COMMAND ${PYTHON_EXECUTABLE} setup.cmake.py install -f ${EXTRA_ARGS} ${PYMOOSE_EXTRA_INSTALL_ARGS}
         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/python
         )"
         )
@@ -447,6 +450,33 @@ if(${CMAKE_BUILD_TOOL} MATCHES "make")
         )
 endif()
 
+# Target for creating bdist. This is handy for creating bdist for packaging.
+# Save the binary distribution (tar.gz) to PYMOOSE_BDIST_DIR. Note that this
+# target is only useful when creating packages on Open Build Service i.e. if you
+# use this target on distribution X, it may not work on distrbutions other than
+# X. See python-wheels for making portable distributions.
+if(NOT PYMOOSE_BDIST_DIR)
+    set(PYMOOSE_BDIST_DIR ${CMAKE_BINARY_DIR}/pymoose_bdist)
+endif( )
+# get platform and arch using python.
+find_package( PythonInterp REQUIRED)
+execute_process( 
+    COMMAND ${PYTHON_EXECUTABLE} -c "import sys;print('%s-%s'%(sys.platform,sys.arch))"
+    OUTPUT_VARIABLE PY_PLATFORM_ARCH
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+    )
+# If not set, use default.
+if(NOT PY_PLATFORM_ARCH)
+    message(PY_PLATFORM_ARCH "linux-x86_64")
+endif( )
+message(STATUS "Building bdist for arch: ${PY_PLATFORM_ARCH}")
+add_custom_target( bdist 
+    COMMAND ${PYTHON_EXECUTABLE} setup.cmake.py bdist -p ${PY_PLATFORM_ARCH} -d ${PYMOOSE_BDIST_DIR}
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/python
+    COMMENT "Genearating bdist using setup.cmake.py." 
+    VERBATIM
+    )
+
 
 ############################ CTEST ######################################
 include( CTest )
diff --git a/python/moose/moose_test.py b/python/moose/moose_test.py
index 9cda2b80..9d5ad245 100644
--- a/python/moose/moose_test.py
+++ b/python/moose/moose_test.py
@@ -26,11 +26,12 @@ import logging
 from collections import defaultdict
 import time
 
+logfile_ = tempfile.NamedTemporaryFile( )
 logging.basicConfig(
         level=logging.DEBUG,
         format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
         datefmt='%m-%d %H:%M',
-        filename='tests.log',
+        filename = logfile_.name,
         filemode='w'
         )
 console = logging.StreamHandler()
diff --git a/python/setup.cmake.py b/python/setup.cmake.py
index ebce9069..22da886d 100644
--- a/python/setup.cmake.py
+++ b/python/setup.cmake.py
@@ -1,10 +1,11 @@
 # -*- coding: utf-8 -*-
 
-"""setup.py:
-Script to install python targets.
+"""
+setup.cmake.py:
 
-NOTE: This script is to be called by CMake. Not intended to be used standalone.
+Script to install python targets by cmake. 
 
+DO NOT USE IT DIRECTLY. Only `cmake` build system should use it directly.
 """
 
 __author__           = "Dilawar Singh"
@@ -20,33 +21,29 @@ import os
 import sys
 
 try:
-	from setuptools import setup
+    from setuptools import setup
 except Exception as e:
-	from distutils.core import setup
+    from distutils.core import setup
 
+# Read version from VERSION created by cmake file. This file must be present for
+# setup.cmake.py to work perfectly.
 script_dir = os.path.dirname( os.path.abspath( __file__ ) )
-version = '3.2pre1'
-
-
-try:
-    with open( os.path.join( script_dir, 'VERSION'), 'r' ) as f:
-        version = f.read( )
-except Exception as e:
-    print( 'Failed to read VERSION %s' % e )
-    print( 'Using default %s' % version )
+version = None
+with open( os.path.join( script_dir, 'VERSION'), 'r' ) as f:
+    version = f.read( )
 
 try:
     import importlib.machinery
     suffix = importlib.machinery.EXTENSION_SUFFIXES[0]
 except Exception as e:
-    print( '[WARN] Failed to determine importlib suffix' )
+    print( '[WARN] Failed to determine importlib suffix due to %s' % e )
     suffix = '.so'
 
 setup(
         name='pymoose',
         version=version,
         description='Python scripting interface of MOOSE Simulator (https://moose.ncbs.res.in)',
-        author='MOOSERes',
+        author='See AUTHORS.md at https://github.com/BhallaLab/moose',
         author_email='bhalla@ncbs.res.in',
         maintainer='Dilawar Singh',
         maintainer_email='dilawars@ncbs.res.in',
@@ -61,9 +58,11 @@ setup(
             , 'moose.chemUtil'
             , 'moose.chemMerge'
             ],
-	install_requires = [ 'python-libsbml', 'numpy' ],
+        install_requires = [ 'python-libsbml', 'numpy' ],
         package_dir = {
             'moose' : 'moose', 'rdesigneur' : 'rdesigneur'
             },
-        package_data = { 'moose' : ['_moose' + suffix, 'neuroml2/schema/NeuroMLCoreDimensions.xml'] },
-    )
+        package_data = { 
+            'moose' : ['_moose' + suffix, 'neuroml2/schema/NeuroMLCoreDimensions.xml'] 
+            },
+        )
-- 
GitLab