source: orange/install-scripts/linux/setup.py @ 3993:146f3d0a141b

Revision 3993:146f3d0a141b, 17.5 KB checked in by tomazc <tomaz.curk@…>, 6 years ago (diff)

need this before Qt4 become trunk (main branch)

Line 
1#!/usr/bin/env python
2# To use:
3#       python setup.py install
4
5# all kind of checks
6
7# Change this to something else than ADDVERSION
8OrangeVer="ADDVERSION"
9
10# got* is used to gather information of the system and print it out at the end
11gotPython = '';
12gotQt = '';
13gotPyQt = '';
14gotNumPy = '';
15gotGcc = '';
16gotQwt = '';
17
18try:
19    import sys,commands,traceback,os
20    from distutils import sysconfig
21    from distutils.core import setup,Extension
22    from glob import glob
23    from stat import *
24except:
25    traceback.print_exc()
26    print "Unable to import python distutils."
27    print "You may want to install the python-dev package on your distribution."
28    sys.exit(1)
29
30gotPython = sys.version.split()[0]
31
32if not hasattr(sys, 'version_info') or sys.version_info < (2,3,0,'alpha',0):
33    raise SystemExit, "Python 2.3 or later is required to build Orange."
34
35#if os.geteuid() != 0:
36#    print "This script should be run as superuser!"
37#    sys.exit(1)
38
39try:
40    import qt,pyqtconfig
41except:
42    print "NOTE: Python Qt not installed, OrangeCanvas and OrangeWidgets will not work."
43    print "You can get it at: http://www.riverbankcomputing.co.uk/pyqt/index.php"
44    # we are using Qt 2.3 - Qt 3.3
45
46try:
47    gotPyQt = pyqtconfig.Configuration().pyqt_version_str;
48except:
49    gotPyQt = ''
50    # any PyQt that supports Qt 2.3-3.8
51
52try:
53    import sipconfig
54    tmp = "%x" % sipconfig.Configuration().qt_version
55    gotPy = tmp.replace('0','.')
56except:
57    print "Sipconfig not found, Qt version could not be found!"
58    gotPy = ''
59    # depends on version of PyQt
60
61try:
62    import numpy
63except:
64    print "NumPy should be installed!"
65    print "You can get it at: http://numpy.scipy.org/"
66    sys.exit(1)
67    # use latest, from 23.0 on
68
69try:
70    import numpy
71    gotNumPy = numpy.__version__
72except:
73    print "Can not determine NumPy version!"
74    gotNumPy = "n/a"
75
76try:
77    import qwt
78    gotQwt = "n/a"
79except:
80    print "PyQwt not installed!"
81    print "You can get it at: http://pyqwt.sourceforge.net/"
82    # depends on PyQt
83   
84if os.system("gcc --version > /dev/null 2>&1") != 0:
85    print "GCC should be installed!"
86    sys.exit(1)
87
88# catching version of GCC
89try:
90    (stdout_err, stdin) = popen2.popen4("gcc --version");
91    tmp = stdout_err.readlines()[0]
92    gotGcc = tmp.split()[2]
93except:
94    print "Can not determine GCC version!"
95    gotGcc = "n/a"
96    # version 3.3 on
97
98if OrangeVer is "ADDVERSION":
99    print "Version should be added manually (edit setup.py and replace ADDVERSION)"
100    sys.exit(1)
101
102if "FreeBSD" in sys.version:
103    HostOS="FreeBSD"
104elif "Linux" in sys.version:
105    HostOS="Linux"
106else:
107    HostOS="unknown"
108
109# creating custom commands
110# uninstall deletes everything which was installed
111from distutils.core import Command
112from distutils.command.install import install
113from distutils.command.install_data import install_data
114
115class uninstall(Command):
116    description = "uninstall current version"
117
118    user_options = [('orangepath=', None, "Orange installation path"),
119                    ('docpath=', None, "Orange documentaiton path"),
120                    ('libpath=', None, "Orange library path")]
121
122   
123    def initialize_options (self):
124        self.orangepath = None
125        self.docpath = None
126        self.libpath = None
127        self.systemUninstall = False
128       
129    def finalize_options(self):
130        if self.orangepath == None and 'root' in self.__dict__.keys() and self.root <> None:
131            self.orangepath = self.root
132            self.root = None
133
134        if self.orangepath is None:
135            try:
136                fo = file(sys.argv[0].replace("/setup.py", "/user_install"), "r")
137                self.orangepath=fo.read()
138                fo.close
139            except:
140                print "user_install file could not be opened, performing system uninstall"
141
142        else:
143            self.systemUninstall = False
144           
145        if self.orangepath is None:
146            self.systemUninstall = True
147            if self.orangepath is None:
148                self.orangepath = os.path.join("lib", PythonVer,
149                                               "site-packages", "orange")
150            if self.docpath is None:
151                self.docpath = os.path.join(sys.prefix, "share", "doc", "orange")
152            if self.libpath is None:
153                self.libpath = os.path.join(sys.prefix, "lib")
154        else:
155            if self.docpath is None:
156                self.docpath = os.path.join(self.orangepath, "doc")
157                self.orangepath = os.path.join(self.orangepath, "orange")
158               
159    def run(self):
160        if self.systemUninstall is True:
161            if os.geteuid() != 0:
162                print "Uninstallation should be run as superuser!"
163                sys.exit(1)
164            self.orangepath = os.path.join(sys.prefix, self.orangepath)
165            sysBinFile = os.path.join("/", "usr", "bin", "orange")
166            print "Performing system uninstallation from: "+self.orangepath
167        else:
168            sysBinFile = None
169            print "Performing user uninstallation from: "+self.orangepath
170        print "Removing orange.pth file...",
171        os.remove(os.path.join(self.orangepath, "..", "orange.pth"))
172        print "done!"
173        print "Removing installation directory "+self.orangepath+" ...",
174        self.rmdir(self.orangepath)
175        os.rmdir(self.orangepath)
176        print "done!"
177        print "Removing documentation directory "+self.docpath+" ...",
178        self.rmdir(self.docpath)
179        os.rmdir(self.docpath)
180        print "done!"
181        if self.systemUninstall is True:
182            print "Removing symbolic links for the orange libraries ...",
183            for orngLib in OrangeLibList:
184                os.remove(os.path.join(self.libpath, "lib"+orngLib))
185            print "done!"
186            print "Removing Orange Canvas shortcut "+sysBinFile+"...",
187            os.remove(sysBinFile);
188            print "done!"
189
190    def rmdir(self,top):
191        for root, dirs, files in os.walk(top, topdown=False):
192            for name in files:
193                os.remove(os.path.join(root, name))
194            for name in dirs:
195                os.rmdir(os.path.join(root, name))
196
197# compile goes to orange/source directory and compiles orange
198class compile(Command):
199    # add Different make programs support"
200    description = "compiles Orange"
201
202    user_options = [('coptions=', None, "special compiling options")]
203
204    def initialize_options(self):
205        self.coptions = None
206        self.makeCmd = None
207
208    def finalize_options(self):
209        if self.coptions is None:
210            print "Default compiler options are taken..."
211        if HostOS is "FreeBSD":
212            self.makeCmd = "gmake"
213        else:
214            self.makeCmd = "make"
215           
216    def run(self):
217        #compile Orange with make files
218        SourceDir = os.path.join("source")
219        os.chdir(SourceDir)
220        print "Compiling... this might take a while, logging into compiling.log...",
221        make=self.makeCmd+"> ../compiling.log"
222        retval = os.system(make)
223        if retval != 0:
224            print "Compiling Orange failed... exiting!"
225            sys.exit(1)
226        print "done"
227        os.chdir(BaseDir)
228
229# change correct directories in data_files (we don't know target directory in
230# the 'main' script
231
232class install_data_wrap(install_data):
233    description = "Orange specific data installation"
234
235    print "Orange specific data installation"
236
237    global OrangeInstallDir
238   
239    user_options = install_data.user_options
240   
241    def initialize_options(self):
242        install_data.initialize_options(self)
243
244    def finalize_options(self):
245        install_data.finalize_options(self)
246        if self.install_dir != os.path.join(self.root, sys.prefix):
247            OrangeInstallDir = os.path.join(self.install_dir, "orange")
248            OrangeInstallDoc = os.path.join(self.install_dir, "doc", "orange")
249#            OrangeInstallLib = os.path.join(self.install_dir, "lib")
250            self.data_files = [(OrangeInstallDir, OrangeLibs),
251                               (os.path.join(OrangeInstallDir,
252                                             "OrangeWidgets", "icons"),
253                                OrangeWidgetIcons),
254                               (os.path.join(OrangeInstallDir,
255                                             "OrangeCanvas", "icons"),
256                                OrangeCanvasIcons),
257                               (os.path.join(OrangeInstallDir, "OrangeCanvas"),
258                                OrangeCanvasPyw)]
259            for root, dirs, files in os.walk(os.path.join("doc")):
260                OrangeDocs = glob(os.path.join("", "")) # Create a Docs file list
261                if 'CVS' in dirs:
262                    dirs.remove('CVS')  # don't visit CVS directories
263                for name in files:
264                    OrangeDocs += glob(os.path.join(root,name))
265                if(root.split('doc/')[-1] == 'doc/'):
266                    root = ''
267                self.data_files += [(os.path.join(OrangeInstallDoc,
268                                             root.split('doc/')[-1]), OrangeDocs)]
269
270            self.data_files += [(OrangeInstallDoc,['setup.py'])]
271           
272    def run(self):
273        install_data.run(self)
274
275# install is 'normal distutils' install, after installation symlinks libraries
276# and calles ldconfig
277class install_wrap(install):
278    description = "Orange specific installation"
279
280    user_options = install.user_options + [('orangepath=',
281                                            None, "Orange install directory")]
282
283    def initialize_options(self):
284        install.initialize_options(self)
285        self.orangepath = None;
286
287    def finalize_options(self):
288        if self.orangepath == None and self.root <> None:
289            self.orangepath = self.root
290            self.root = None
291
292        if self.orangepath == None:
293            print "Using default system initialization, checking for privileges..."
294            if os.geteuid() != 0:
295                print "should be run as superuser or --orangepath should be used"
296                sys.exit(1)
297            print "done"
298            self.OrangeInstallDir = os.path.join("lib", PythonVer,
299                                            "site-packages", "orange")
300            self.OrangeInstallDoc = os.path.join(sys.prefix, "share", "doc",
301                                            "orange")
302            self.OrangeInstallLib = os.path.join(sys.prefix, "lib")
303        else:
304            self.install_purelib = self.orangepath;
305            self.install_data = self.orangepath;
306
307        install.finalize_options(self);
308 
309    def run(self):
310        install.run(self)
311
312        if self.orangepath == None:
313        binFile = os.path.join(sys.prefix, self.OrangeInstallDir, "OrangeCanvas", "orngCanvas.pyw")
314        sysBinFile = os.path.join("/", "usr", "bin", "orange")
315        os.system("echo python "+binFile+" >> "+sysBinFile)
316            os.chmod(sysBinFile,
317                      S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
318
319            print "Linking libraries...",
320            for currentLib in OrangeLibList:
321                try:
322                    os.symlink(os.path.join(sys.prefix,
323                                            self.OrangeInstallDir,currentLib),
324                               os.path.join(self.OrangeInstallLib,"lib"+currentLib))
325                   
326                except:
327                    print "problems with "+currentLib+"... ignoring... ",
328                   
329                os.system("/sbin/ldconfig")
330                print "success"
331        else:
332        sysBinFile = None
333            # link orange.so into liborange.so
334            try:
335                os.symlink(os.path.join(self.orangepath, "orange", "orange.so"), os.path.join(self.orangepath, "orange", "liborange.so"))
336            except:
337                print "problems creating link to liborange.so:", os.path.join(self.orangepath, "orange", "liborange.so")
338            print "Libraries were not exported to the system library path (using 'non-system' installation)"
339           
340        print "Creating path file...",
341        if self.orangepath == None:
342            pth = os.path.join(sys.prefix,self.OrangeInstallDir,"..","orange.pth")
343        else:
344            pth = os.path.join(self.orangepath, "orange.pth")
345
346        if os.access(pth, os.F_OK) is True:
347            os.remove(pth)
348
349        fo = file(pth,"w+")
350
351        if self.orangepath == None:
352            pthInstallDir = os.path.join(sys.prefix, self.OrangeInstallDir)
353        else:
354            pthInstallDir = os.path.join(self.orangepath, "orange")
355           
356        fo.write(pthInstallDir+"\n")
357        for root,dirs,files in os.walk(pthInstallDir):
358            for name in dirs:
359                fo.write(os.path.join(root,name)+"\n")
360        fo.close()
361        print "success"
362
363        print "Preparing filename masks...",
364    for root, dirs, files in os.walk(pthInstallDir):
365        for name in files:
366        if name in OrangeLibList: # libraries must have +x flag too
367            os.chmod(os.path.join(root,name),   
368                 S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
369
370        else:
371                os.chmod(os.path.join(root,name),
372                         S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH)
373        for name in dirs:
374            os.chmod(os.path.join(root,name),
375                     S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
376        print "success"
377    print ""
378        print "Python version: "+gotPython
379        print "PyQt version: "+gotPyQt
380        print "Qt version: "+gotPy
381        print "NumPy version: "+gotNumPy
382        print "Qwt version: "+gotQwt
383        print "GCC version: "+gotGcc
384
385        if self.orangepath != None:
386            # we save orangepath for uninstallation to the file user_install
387            fo = file(os.path.join(self.orangepath, "doc",
388                                  "orange", "user_install"), "w+")
389            fo.write(self.orangepath)
390            fo.close()
391            OrangeInstallDir = os.path.join(self.orangepath, "orange")
392            OrangeInstallDoc = os.path.join(self.orangepath, "doc", "orange")
393            print "Orange installation dir: "+OrangeInstallDir
394            print "Orange documentation dir: "+OrangeInstallDoc
395            print "To uninstall Orange type:"
396            print ""
397            print "    python "+OrangeInstallDoc+"/setup.py uninstall"
398        else:
399            print "Orange installation dir: "+sys.prefix+self.OrangeInstallDir
400            print "Orange library links in: "+self.OrangeInstallLib
401            print "Orange documentation dir: "+self.OrangeInstallDoc
402            print "To uninstall Orange type:"
403            print ""
404            print "    python "+self.OrangeInstallDoc+"/setup.py uninstall"
405           
406        print ""
407        print "It will remove Orange, Orange documentation and links to Orange libraries"
408        if sysBinFile != None:
409        print ""
410        print "To run Orange Canvas run: "+sysBinFile
411    else:
412        print ""
413        print "Orange Canvas shortcut not created ('non-system' installation)"
414        print ""
415        print "PLEASE ADD to your environment: LD_LIBRARY_PATH="+OrangeInstallDir+":$LD_LIBRARY_PATH ; export LD_LIBRARY_PATH"
416        print ""
417   
418# preparing data for Distutils
419
420PythonVer = "python"+sys.version[:3]
421
422OrangeInstallDir = os.path.join("lib", PythonVer, "site-packages", "orange")
423OrangeInstallDoc = os.path.join(sys.prefix, "share", "doc",
424                                "orange")
425OrangeInstallLib = os.path.join(sys.prefix, "lib")
426
427OrangeLibList = ['orange.so', 'orangene.so','orangeom.so','statc.so','corn.so']
428       
429BaseDir = os.getcwd()
430OrangeDirs = ["orange", "orange.OrangeCanvas", "orange.OrangeWidgets"]
431OrangeWidgetsDirs = []
432for root,dirs,files in os.walk(os.path.join("OrangeWidgets"), topdown=False):
433    if 'CVS' in dirs:
434        dirs.remove('CVS')
435    for name in dirs:
436    tmp = "orange."+root+"."+name
437        OrangeWidgetsDirs.append(tmp.replace('/','.'))
438OrangeDirs += OrangeWidgetsDirs
439
440packages =  OrangeDirs
441package_dir = {"orange" : ""}
442
443OrangeLibs = []
444for currentLib in OrangeLibList:
445    OrangeLibs += [os.path.join(currentLib)]
446
447OrangeWidgetIcons = glob(os.path.join("OrangeWidgets", "icons", "*.png"))
448OrangeCanvasIcons = glob(os.path.join("OrangeCanvas",  "icons", "*.png"))
449OrangeCanvasPyw   = glob(os.path.join("OrangeCanvas", "orngCanvas.pyw"));
450
451data_files = [(OrangeInstallDir, OrangeLibs),
452              (os.path.join(OrangeInstallDir, "OrangeWidgets", "icons"),
453               OrangeWidgetIcons),
454              (os.path.join(OrangeInstallDir, "OrangeCanvas", "icons"),
455               OrangeCanvasIcons),
456          (os.path.join(OrangeInstallDir, "OrangeCanvas"), OrangeCanvasPyw)]
457
458# Adding each doc/* directory by itself
459for root, dirs, files in os.walk(os.path.join("doc")):
460    OrangeDocs = glob(os.path.join("", "")) # Create a Docs file list
461    if 'CVS' in dirs:
462        dirs.remove('CVS')  # don't visit CVS directories
463    for name in files:
464        OrangeDocs += glob(os.path.join(root,name))
465    if(root.split('doc/')[-1] == 'doc/'):
466        root = ''
467    data_files += [(os.path.join(OrangeInstallDoc,root.split('doc/')[-1]),
468                                 OrangeDocs)]
469
470# we save setup.py, so we can uninstall complete orange installation
471data_files += [(OrangeInstallDoc,['setup.py'])]
472
473long_description = """Orange, data-mining software"""
474
475setup (name = "orange",
476       version = OrangeVer,
477       maintainer = "Jure Menart",
478       maintainer_email = "jurem@najdi.si",
479       description = "Orange Extension for Python",
480       long_description = long_description,
481       url = "http://www.ailab.si/orange",
482       packages = packages,
483       package_dir = package_dir,
484       data_files = data_files,
485       cmdclass = { 'uninstall': uninstall,
486                    'compile'  : compile,
487                    'install'  : install_wrap,
488                    'install_data' : install_data_wrap}
489       )
Note: See TracBrowser for help on using the repository browser.