Skip to content

Commit 4a4d4c9

Browse files
committed
added setup directory which contains swig output for building SNAP Python without swig
1 parent cac0eaf commit 4a4d4c9

File tree

11 files changed

+150261
-41
lines changed

11 files changed

+150261
-41
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*.so
55

66
# Swig files
7-
*.cxx
7+
swig/*.cxx
88
swig/snap.py
99

1010
# Packages

Makefile.config

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# compilation parameters for SNAP Python
3+
#
4+
5+
UNAME := $(shell uname)
6+
7+
ifeq ($(UNAME), Linux)
8+
# Linux flags
9+
CXXFLAGS += -fPIC -shared -D__STDC_LIMIT_MACROS
10+
LDFLAGS += -lrt
11+
else ifeq ($(UNAME), Darwin)
12+
# OS X flags
13+
LDFLAGS += -lpython -dynamiclib
14+
else ifeq ($(shell uname -o), Cygwin)
15+
# Cygwin flags
16+
CXXFLAGS += -shared -D__STDC_LIMIT_MACROS
17+
LIBS += -lpython2.6
18+
endif
19+

dev/test/install-dir.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
print out the Python install directory
5+
"""
6+
7+
import inspect
8+
import os
9+
import sys
10+
11+
# get the installation directory
12+
13+
# get the system Python directory
14+
sys_install = os.path.join(
15+
os.path.dirname(inspect.getfile(inspect)),
16+
"site-packages")
17+
18+
# check for an alternative Python user directory
19+
user_install = sys_install
20+
for p in sys.path:
21+
n = p.find("site-packages")
22+
if n > 0:
23+
user_install = os.path.join(p[:n],"site-packages")
24+
break
25+
26+
print "install-prefix", user_install
27+

setup/MANIFEST

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
setup.py
2+
snap.py
3+
_snap.so

setup/Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#
2+
# Makefile for compilation of SNAP Python from SWIG output
3+
#
4+
5+
SNAPVER = 2.x
6+
7+
# set the path to your SNAP directory here
8+
GITDIR = ../Snap-$(SNAPVER)
9+
SNAPDIR = $(GITDIR)/$(SNAP)
10+
GLIBDIR = $(GITDIR)/$(GLIB)
11+
12+
SWIGDIR = ../swig
13+
14+
# include compilation parameters
15+
include $(GITDIR)/Makefile.config
16+
include ../Makefile.config
17+
18+
all: _snap.so
19+
20+
snap_wrap.o: snap_wrap.cxx
21+
@if ! diff Version $(GITDIR)/Version >/dev/null ; then echo "*** Error: SNAP versions do not match"; exit 1; fi
22+
g++ $(CXXFLAGS) -c snap_wrap.cxx -I$(SWIGDIR) -I$(SNAPDIR) -I$(GLIBDIR) -I/usr/include/python2.6 -I/usr/include/python2.7
23+
24+
Snap.o:
25+
@if ! diff Version $(GITDIR)/Version >/dev/null ; then echo "*** Error: SNAP versions do not match"; exit 1; fi
26+
$(CC) $(CXXFLAGS) -c $(SNAPDIR)/Snap.cpp -I$(SNAPDIR) -I$(GLIBDIR)
27+
28+
_snap.so: snap_wrap.o Snap.o
29+
g++ $(LDFLAGS) $(CXXFLAGS) snap_wrap.o Snap.o $(LIBS) -o _snap.so
30+
31+
snap.py: snap_wrap.cxx
32+
33+
install: setup.py snap.py _snap.so
34+
sudo python setup.py install
35+
36+
dist: setup.py snap.py _snap.so
37+
python setup.py sdist
38+
39+
build:
40+
swig -python -c++ -w302,312,317,325,362,383,384,389,401,503,508,509 -O -D_CMPWARN -outcurrentdir -I$(SWIGDIR) -I$(SNAPDIR) -I$(GLIBDIR) $(SWIGDIR)/snap.i
41+
cp $(GITDIR)/Version .
42+
43+
clean:
44+
rm -f *.o _*.so *.pyc
45+

setup/Version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Snap-2.0-20130513-163356

setup/setup.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
setup.py file for SNAP (Stanford Network Analysis Platform) Python
5+
CentOS version
6+
"""
7+
8+
import inspect
9+
import os
10+
import platform
11+
import sys
12+
13+
from distutils.core import setup, Extension
14+
15+
#
16+
# determine package parameters:
17+
# snap-py version, python version, os version, architecture
18+
#
19+
20+
# snap-py version
21+
snap_version = "0.1"
22+
try:
23+
f = open("Version","r")
24+
content = f.read()
25+
f.close()
26+
w = content.split("-")
27+
snap_version += "-" + w[1]
28+
except:
29+
pass
30+
31+
# python version
32+
python_version = "py" + str(sys.version_info[0]) + "." + str(sys.version_info[1])
33+
34+
# os version
35+
try:
36+
f = open("/etc/centos-release","r")
37+
except:
38+
f = open("/etc/redhat-release","r")
39+
40+
content = f.read()
41+
f.close()
42+
w = content.split(" ")
43+
os_version = (w[0] + w[2]).lower()
44+
45+
# architecture
46+
uname = platform.uname()
47+
arch = "i386"
48+
if uname[-1] == "x86_64":
49+
arch = "x64"
50+
51+
pkg_version = "-".join([snap_version, os_version, arch, python_version])
52+
53+
#print "pkg_version", pkg_version
54+
#sys.exit(0)
55+
56+
#
57+
# get the installation directory
58+
#
59+
60+
# get the system Python directory
61+
sys_install = os.path.join(
62+
os.path.dirname(inspect.getfile(inspect)),
63+
"site-packages")
64+
65+
# check for an alternative Python user directory
66+
user_install = sys_install
67+
for p in sys.path:
68+
n = p.find("site-packages")
69+
if n > 0:
70+
user_install = os.path.join(p[:n],"site-packages")
71+
break
72+
73+
#
74+
# setup configuration
75+
#
76+
77+
setup (name = 'snappy',
78+
py_modules = ["snap"],
79+
#ext_modules = [snap_module],
80+
data_files = [(user_install, ["_snap.so"])],
81+
version = pkg_version,
82+
author = "snap.stanford.edu",
83+
description = """SNAP (Stanford Network Analysis Platform) Python""",
84+
)
85+

0 commit comments

Comments
 (0)