← Back to team overview

instant team mailing list archive

Patches for Windows

 

Hi all,

In Viper, FFC, and Instant there are Python scripts like viper, ffc,
ffc-clean, instant-clean, and instant-showcache. In Windows you cannot
execute these scripts by themselfs, even if they are in PATH (unless you
are using MSYS or Cygwin), so if you for instance want to display a mesh
with Viper, you can't do

  viper mesh.xml

but you have to do

  python <installation_prefix>\Scripts\viper mesh.xml

This is not very useful and breaks the code many places (like plotting in
DOLFIN). A simple solution is to create a batch file (e.g. viper.bat) that
executes the line above. The batch files are installed together with the
Python scripts into <installation_prefix>\Scripts and after adding this
folder to the PATH environment variable, one can start the scripts as one
would expect (no need to specify the .bat extension). I have created three
patches, one for each of Viper, FFC, and Instant (see attachment). Feel
free to modify the patches as you like.

Johannes
# HG changeset patch
# User Johannes Ring <johannr@xxxxxxxxx>
# Date 1220520497 -7200
# Node ID 9d4696d9267210ee2c00e68e989e4fe04dc4af28
# Parent  8196a6a82a52ec9476b909621760f5933bfe4e59
Generate batch files for Windows.

diff -r 8196a6a82a52 -r 9d4696d92672 setup.py
--- a/setup.py	Wed Sep 03 10:15:57 2008 +0200
+++ b/setup.py	Thu Sep 04 11:28:17 2008 +0200
@@ -2,12 +2,39 @@
 from distutils import sysconfig
 import sys, os, glob
 from os.path import join
+import platform
 
-if sys.platform.startswith('win') or 'bdist_wininst' in sys.argv:
+scripts = [join("src", "bin", "viper")]
+if platform.system() == "Windows" or "bdist_wininst" in sys.argv:
+    # In the Windows command prompt we can't execute Python scripts 
+    # without the .py extension. A solution is to create a batch file
+    # that runs the viper script.
+
+    # try to determine the installation prefix
+    # first set up a default prefix:
+    if platform.system() == "Windows":
+        prefix = sys.prefix
+    else:
+        # we are running bdist_wininst on a non-Windows platform
+        pymajor, pyminor = sysconfig.get_python_version().split(".")
+        prefix = "C:\\Python%s%s" % (major, pyminor)
+
+    # if --prefix is specified we use this instead of the default:
+    for arg in sys.argv:
+        if "--prefix" in arg:
+            prefix = arg.split("=")[1]
+            break
+
+    # create batch file for Windows:
+    f = open("viper.bat", "w")
+    f.write("@python %s %%*" % join(prefix, "Scripts", "viper"))
+    f.close()
+    scripts.append("viper.bat")
+    
     datadir = join('Lib','site-packages','viper','data')
 else:
     datadir = join("lib", "python%s" % sysconfig.get_python_version(), "site-packages", "viper", "data")
-
+    
 setup(name='viper',
     version='0.3.0',
     description='Simple vtk based visualization software',
@@ -16,7 +43,7 @@
     url='http://www.fenics.org/wiki/Viper',
     packages=['viper'],
     package_dir={'viper': join("src", "viper")},
-    scripts=[join("src", "bin", "viper")],
+    scripts=scripts,
     data_files=[(datadir, glob.glob(join("src", "viper", "data", "*.lut")) )]
     )
 
# HG changeset patch
# User Johannes Ring <johannr@xxxxxxxxx>
# Date 1220520152 -7200
# Node ID b7eb035ad49db8e8a4de2e4a7bde5eccc798003d
# Parent  678e3e8482c4daeaa2e9bb4b4825f6317d6be7c6
Generate batch files for Windows.

diff -r 678e3e8482c4 -r b7eb035ad49d setup.py
--- a/setup.py	Wed Sep 03 21:46:42 2008 +0200
+++ b/setup.py	Thu Sep 04 11:22:32 2008 +0200
@@ -1,8 +1,38 @@
 #!/usr/bin/env python
 
+import sys, platform
 from distutils.core import setup
 from os import chdir
-from os.path import join
+from os.path import join, splitext
+
+scripts = [join("src", "bin", "ffc"), join("src", "bin", "ffc-clean")]
+if platform.system() == "Windows" or "bdist_wininst" in sys.argv:
+    # In the Windows command prompt we can't execute Python scripts 
+    # without the .py extension. A solution is to create batch files
+    # that runs the different scripts.
+
+    # try to determine the installation prefix
+    # first set up a default prefix:
+    if platform.system() == "Windows":
+        prefix = sys.prefix
+    else:
+        # we are running bdist_wininst on a non-Windows platform
+        pymajor, pyminor = sysconfig.get_python_version().split(".")
+        prefix = "C:\\Python%s%s" % (major, pyminor)
+
+    # if --prefix is specified we use this instead of the default:
+    for arg in sys.argv:
+        if "--prefix" in arg:
+            prefix = arg.split("=")[1]
+            break
+
+    # create batch files for Windows:
+    for batch_file in ["ffc.bat", "ffc-clean.bat"]:
+        f = open(batch_file, "w")
+        f.write("@python %s %%*" % \
+                join(prefix, "Scripts", splitext(batch_file)[0]))
+        f.close()
+        scripts.append(batch_file)
 
 setup(name = "FFC",
       version = "0.5.0",
@@ -27,5 +57,5 @@
                   "ffc.compiler.analysis",
                   "ffc.jit"],
       package_dir={"ffc": join("src", "ffc")},
-      scripts = [join("src", "bin", "ffc"), join("src", "bin", "ffc-clean")],
+      scripts = scripts,
       data_files = [(join("share", "man", "man1"), [join("doc", "man", "man1", "ffc.1.gz")])])
# HG changeset patch
# User Johannes Ring <johannr@xxxxxxxxx>
# Date 1220520335 -7200
# Node ID 0205c90f43b9d8504333efc88521b691f2bb5f58
# Parent  1309a5640879d1eb7d7194a9f6c117da1f5e8c79
Generate batch files for Windows.

diff -r 1309a5640879 -r 0205c90f43b9 setup.py
--- a/setup.py	Wed Sep 03 18:18:38 2008 +0200
+++ b/setup.py	Thu Sep 04 11:25:35 2008 +0200
@@ -1,7 +1,37 @@
 #!/usr/bin/env python
 
-from os.path import join
+import sys, platform
+from os.path import join, splitext
 from distutils.core import setup
+
+scripts = [join("etc", "instant-clean"), join("etc", "instant-showcache")]
+if platform.system() == "Windows" or "bdist_wininst" in sys.argv:
+    # In the Windows command prompt we can't execute Python scripts 
+    # without the .py extension. A solution is to create batch files
+    # that runs the different scripts.
+
+    # try to determine the installation prefix
+    # first set up a default prefix:
+    if platform.system() == "Windows":
+        prefix = sys.prefix
+    else:
+        # we are running bdist_wininst on a non-Windows platform
+        pymajor, pyminor = sysconfig.get_python_version().split(".")
+        prefix = "C:\\Python%s%s" % (major, pyminor)
+
+    # if --prefix is specified we use this instead of the default:
+    for arg in sys.argv:
+        if "--prefix" in arg:
+            prefix = arg.split("=")[1]
+            break
+
+    # create batch files for Windows:
+    for batch_file in ["instant-clean.bat", "instant-showcache.bat"]:
+        f = open(batch_file, "w")
+        f.write("@python %s %%*" % \
+                join(prefix, "Scripts", splitext(batch_file)[0]))
+        f.close()
+        scripts.append(batch_file)
 
 setup(name = "instant", version = '0.9.5', 
       description = "Instant Inlining of C/C++ in Python", 
@@ -10,5 +40,5 @@
       url = "http://www.fenics.org/instant";, 
       packages = ['instant'],
       package_dir = {'instant': 'src/instant'}, 
-      scripts = [join("etc", "instant-clean"), join("etc", "instant-showcache")])
+      scripts = scripts)