Subject: [UFC-dev] [HG UFC] updated setup.py

From: [email-masked] (UFC)
Date: Tue, 13 Jan 2009 21:50:59 +0100 (CET)

One or more new changesets pushed to the primary ufc repository.
A short summary of the last three changesets is included below.

changeset:   234:6a4004f20c90c62105ae289d3c10923b908dbc8c
tag:         tip
user:        Kent-Andre Mardal <[email-masked]>
date:        Tue Jan 13 21:50:13 2009 +0100
files:       TODO setup.py
description:
updated setup.py

changeset:   233:49d6988c66c81d455353771e39dae57b98f7321f
user:        "Johan Hake <[email-masked]>"
date:        Tue Jan 13 11:44:38 2009 +0100
files:       setup.py src/ufc/ufc.i
description:
Added a missing file and removed some uncommented old code.

changeset:   232:84fcf149cbe3d33b65338a4d2b2b004ca4387d4c
user:        "Johan Hake <[email-masked]>"
date:        Tue Jan 13 11:42:11 2009 +0100
files:       setup.py
description:
Added a swig interface file, ufc.i
  - In this shared_ptr typemaps is added for the main classes in ufc.h.
  - Changed name of the python module ufc/ to ufc_utils/

NOTE:
  - If installing from source, i.e., python setup.py install, you need to
    delete your old build before you install it again. Otherwise you will reinstall
    the old python module ufc/

----------------------------------------------------------------------
For more details, visit http://www.fenics.org/hg/ufc

---

From: Johan Hake <[email-masked]>
Date: Wed, 14 Jan 2009 08:41:04 +0100

> date:        Tue Jan 13 21:50:13 2009 +0100

This commit screwed up the setup.py file. Please apply the attached patch for 
a correction.

Johan

>     delete your old build before you install it again. Otherwise you will
> reinstall the old python module ufc/
>
> _______________________________________________
> UFC-dev mailing list
> [email-masked]
> http://fenics.org/mailman/listinfo/ufc-dev

# HG changeset patch
# User "Johan Hake <[email-masked]>"
# Date 1231918670 -3600
# Node ID 52f3e7878563b1fbc3b68d0e7b10a976fae601cc
# Parent  6a4004f20c90c62105ae289d3c10923b908dbc8c
Add back the correct setup.py file

diff -r 6a4004f20c90 -r 52f3e7878563 setup.py
--- a/setup.py	Tue Jan 13 21:50:13 2009 +0100
+++ b/setup.py	Wed Jan 14 08:37:50 2009 +0100
@@ -1,9 +1,19 @@
 #!/usr/bin/env python
 
-from distutils.core import setup
+from distutils.core import setup, Extension
 from distutils import sysconfig
 from os.path import join as pjoin
-import sys
+from os.path import pardir
+import sys, os
+
+# Taken from http://ivory.idyll.org/blog/mar-07/replacing-commands-with-subprocess
+from subprocess import Popen, PIPE, STDOUT
+def get_status_output(cmd, input=None, cwd=None, env=None):
+    pipe = Popen(cmd, shell=True, cwd=cwd, env=env, stdout=PIPE, stderr=STDOUT)
+    (output, errout) = pipe.communicate(input=input)
+    assert not errout
+    status = pipe.returncode
+    return (status, output)
 
 # Version number
 major = 1
@@ -18,6 +28,7 @@
         prefix = sys.argv[sys.argv.index('--prefix')+1]
     except:
         prefix = sys.prefix
+
 print "Installing UFC under %s..." % prefix
 
 # Generate pkgconfig file
@@ -29,14 +40,53 @@
 # FIXME: better way for this? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 file.close()
 
+# Checking for boost installation uses pkg-config
+# If no boost installation is found compiled the ufc extension module
+# without shared_ptr support
+
+# Set pkg-config to always include system flags
+env = os.environ.copy()
+try:
+    assert env["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] == "0"
+except:
+    env["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] = "1"
+
+# Check if pkg-config is installed
+result, output = get_status_output("pkg-config --version ")
+if result != 0: 
+    raise OSError("The pkg-config package is not installed on the system.")
+
+# Check if boost is installed
+result, output = get_status_output("pkg-config --exists boost")
+if result == 0:
+    boost_include_dir = [get_status_output("pkg-config --cflags-only-I boost",env=env)[1][2:]]
+    swig_cmd = "swig -python -c++ -fcompact -O -I. -small ufc.i"
+else:
+    print "*** Warning: Boost was not found. Python extension module compiled without shared_ptr support"
+    boost_include_dir = []
+    swig_cmd = "swig -python -c++ -fcompact -O -I. -DNO_SHARED_PTR -small ufc.i"
+    
+# Run swig on the ufc.i file
+os.chdir(pjoin("src","ufc"))
+print "Running swig command"
+print swig_cmd
+os.system(swig_cmd)
+os.chdir(os.pardir); os.chdir(os.pardir)
+sources = [pjoin("src","ufc","ufc_wrap.cxx")]
+
 setup(name = "UFC",
       version = "%d.%d" % (major, minor),
       description = "Unified Form-assembly Code",
       author = "Martin Sandve Alnaes, Hans Petter Langtangen, Anders Logg, Kent-Andre Mardal and Ola Skavhaug",
       author_email = "[email-masked]",
       url = "http://www.fenics.org/ufc/",
-      packages = ["ufc"],
-      package_dir = {"ufc": pjoin("src","utils","python","ufc")},
+      packages = ["","ufc_utils"],
+      package_dir = {"":pjoin("src","ufc"),
+                     "ufc_utils": pjoin("src","utils","python","ufc")},
       data_files = [("include", [pjoin("src","ufc","ufc.h")]),
                     (pjoin("lib","pkgconfig"), ["ufc-%d.pc" % major]),
-                    (pjoin("include","swig"),[pjoin("src","ufc","ufc.i")])])
+                    (pjoin("include","swig"),[pjoin("src","ufc","ufc.i")])],
+      ext_modules = [Extension("_ufc",
+                     sources,
+                     include_dirs=[pjoin("src","ufc")] + boost_include_dir
+                               )])