1 |
# Copyright (c) 2001, 2002 by Intevation GmbH |
# Copyright (c) 2001, 2002, 2003 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
18 |
import os |
import os |
19 |
from types import TupleType |
from types import TupleType |
20 |
from distutils.core import setup, Extension, Command |
from distutils.core import setup, Extension, Command |
21 |
from distutils.command.install import install |
from distutils.command.install import install, INSTALL_SCHEMES, subst_vars |
22 |
from distutils.command.build_py import build_py |
from distutils.command.build_py import build_py |
23 |
from distutils.command.bdist_rpm import bdist_rpm |
from distutils.command.bdist_rpm import bdist_rpm |
24 |
from distutils.file_util import write_file |
from distutils.file_util import write_file |
43 |
proj4_lib = "proj" |
proj4_lib = "proj" |
44 |
|
|
45 |
|
|
46 |
# You shpuldn't have to modify anything below here |
# You shouldn't have to modify anything below here |
47 |
################################################################### |
################################################################### |
48 |
|
|
49 |
# The installation prefix (similar to autoconf's --prefix). This is |
# The installation prefix (similar to autoconf's --prefix). This is |
50 |
# only the default value, you can override it on the command line |
# only the default value, you can override it on the command line |
51 |
# with the install command's --prefix option |
# with the install command's --prefix option. |
52 |
|
# |
53 |
|
# Note that there's a separate prefix option for the bdist_rpm |
54 |
|
# command completely independend of this one. |
55 |
prefix = "/usr/local/" |
prefix = "/usr/local/" |
56 |
|
|
57 |
|
# Whether to create the thubaninit module. You can override this |
58 |
|
# value on the commandline with the --create-init-module to the |
59 |
|
# install command. |
60 |
|
create_init_module = 1 |
61 |
|
|
62 |
# On POSIX-systems we run wxgtk-config to determine the C++-compiler |
# On POSIX-systems we run wxgtk-config to determine the C++-compiler |
63 |
# flags |
# flags |
64 |
wx_config_script = "wx-config" |
wx_config_script = "wx-config" |
80 |
proj4_lib = "proj_i" |
proj4_lib = "proj_i" |
81 |
|
|
82 |
# Define include and lib directories for wxWindows and |
# Define include and lib directories for wxWindows and |
83 |
wx_prefix = r"D:\wx230" |
wx_prefix = r"D:\wx240" |
84 |
wx_inc = os.path.join(wx_prefix, "include") |
wx_inc = [os.path.join(wx_prefix, 'lib', 'mswdllh'), |
85 |
wx_lib = os.path.join(wx_prefix, "lib") |
os.path.join(wx_prefix, "include")] |
86 |
|
wx_lib = [os.path.join(wx_prefix, "lib")] |
87 |
|
|
88 |
|
|
89 |
# |
# |
90 |
# Unless you use a wxPython version other than 2.3.1, you probably |
# Unless you use a wxPython version other than 2.4.0, you probably |
91 |
# shouldn't have to modify anything below here |
# shouldn't have to modify anything below here |
92 |
################################################################## |
################################################################## |
93 |
|
|
96 |
# the command line with the install command's --prefix option |
# the command line with the install command's --prefix option |
97 |
prefix = r"install" |
prefix = r"install" |
98 |
|
|
99 |
|
# Whether to create the thubaninit module. You can override this |
100 |
|
# value on the commandline with the --create-init-module to the |
101 |
|
# install command. By default we don't create it under NT because we |
102 |
|
# most often run install only as part of bdist_inno where we can't |
103 |
|
# really create because it needs information only known at install |
104 |
|
# time. |
105 |
|
create_init_module = 0 |
106 |
|
|
107 |
# There doesn't seem to be an easy way to get at the wx compiler |
# There doesn't seem to be an easy way to get at the wx compiler |
108 |
# flags, so we define them here. These flags work for us with |
# flags, so we define them here. These flags work for us with |
109 |
# wxPython 2.3.1. They may have to be modified for other versions. |
# wxPython 2.3.1. They may have to be modified for other versions. |
129 |
('WXP_USE_THREAD', '1'), |
('WXP_USE_THREAD', '1'), |
130 |
] |
] |
131 |
|
|
132 |
wx_incdirs = [wx_inc] |
wx_incdirs = wx_inc |
133 |
wx_libdirs = [wx_lib] |
wx_libdirs = wx_lib |
134 |
wx_libs = ["wx23_1h"] |
wx_libs = ["wxmsw24h"] |
135 |
|
|
136 |
wx_libs = wx_libs + ['kernel32', 'user32', 'gdi32', 'comdlg32', |
wx_libs = wx_libs + ['kernel32', 'user32', 'gdi32', 'comdlg32', |
137 |
'winspool', 'winmm', 'shell32', 'oldnames', |
'winspool', 'winmm', 'shell32', 'oldnames', |
138 |
'comctl32', 'ctl3d32', 'odbc32', 'ole32', 'oleaut32', |
'comctl32', 'ctl3d32', 'odbc32', 'ole32', 'oleaut32', |
219 |
# |
# |
220 |
|
|
221 |
extensions.append(Extension("Lib.wxproj", |
extensions.append(Extension("Lib.wxproj", |
222 |
[ext_dir + "/thuban/wxproj.cpp", |
[ext_dir + "/thuban/wxproj.cpp"], |
223 |
shp_dir + "/shpopen.c"], |
include_dirs = ([shp_dir, proj4_incdir, |
224 |
include_dirs = [shp_dir, proj4_incdir] +wx_incdirs, |
ext_dir + "/pyshapelib/"] |
225 |
|
+ wx_incdirs), |
226 |
define_macros = wx_defs, |
define_macros = wx_defs, |
227 |
library_dirs = [proj4_libdir] + wx_libdirs, |
library_dirs = [proj4_libdir] + wx_libdirs, |
228 |
libraries = [proj4_lib] + wx_libs)) |
libraries = [proj4_lib] + wx_libs)) |
233 |
|
|
234 |
extensions.append(Extension("Lib.shapelibc", |
extensions.append(Extension("Lib.shapelibc", |
235 |
[ext_dir + "/pyshapelib/shapelib_wrap.c", |
[ext_dir + "/pyshapelib/shapelib_wrap.c", |
236 |
shp_dir + "/shpopen.c"], |
shp_dir + "/shpopen.c", |
237 |
|
shp_dir + "/shptree.c"], |
238 |
|
include_dirs = [shp_dir])) |
239 |
|
extensions.append(Extension("Lib.shptree", |
240 |
|
[ext_dir + "/pyshapelib/shptreemodule.c"], |
241 |
include_dirs = [shp_dir])) |
include_dirs = [shp_dir])) |
242 |
extensions.append(Extension("Lib.dbflibc", |
extensions.append(Extension("Lib.dbflibc", |
243 |
[ext_dir + "/pyshapelib/dbflib_wrap.c", |
[ext_dir + "/pyshapelib/dbflib_wrap.c", |
420 |
|
|
421 |
user_options = [ |
user_options = [ |
422 |
('skip-build', None, "skip the build steps"), |
('skip-build', None, "skip the build steps"), |
423 |
|
('create-init-module', None, |
424 |
|
"Create the thubaninit.py module to ease use of Thuban as a library"), |
425 |
|
('dont-create-init-module', None, |
426 |
|
"Do not create the thubaninit.py module"), |
427 |
] |
] |
428 |
|
|
429 |
|
boolean_options = ["create-init-module"] |
430 |
|
negative_opt = {'dont-create-init-module' : 'create-init-module'} |
431 |
|
|
432 |
|
|
433 |
def initialize_options (self): |
def initialize_options (self): |
434 |
self.extensions = None |
self.extensions = None |
435 |
self.build_dir = None |
self.build_dir = None |
436 |
self.skip_build = None |
self.skip_build = None |
437 |
|
self.create_init_module = None |
438 |
|
|
439 |
def finalize_options (self): |
def finalize_options (self): |
440 |
self.set_undefined_options("install", |
self.set_undefined_options("install", |
441 |
("build_lib", "build_dir"), |
("build_lib", "build_dir"), |
442 |
('skip_build', 'skip_build')) |
('skip_build', 'skip_build')) |
443 |
self.extensions = self.distribution.ext_modules |
self.extensions = self.distribution.ext_modules |
444 |
|
if self.create_init_module is None: |
445 |
|
# by default we create the init module |
446 |
|
self.create_init_module = 1 |
447 |
|
|
448 |
def run(self): |
def run(self): |
449 |
# Make sure we have built everything we need first |
# Make sure we have built everything we need first |
457 |
else: |
else: |
458 |
self.copy_tree(libdir, "Lib") |
self.copy_tree(libdir, "Lib") |
459 |
|
|
460 |
|
# create the init module if desired |
461 |
|
if self.create_init_module: |
462 |
|
# create the init module |
463 |
|
initfilename = "thubaninit.py" |
464 |
|
contents = thubaninit_contents("") |
465 |
|
self.execute(write_file, (initfilename, contents), |
466 |
|
"Create %s" % initfilename) |
467 |
|
|
468 |
def link_dir(self, src, dest): |
def link_dir(self, src, dest): |
469 |
"""Create a symbolic link dest pointing to src""" |
"""Create a symbolic link dest pointing to src""" |
470 |
if self.verbose: |
if self.verbose: |
491 |
distribution. |
distribution. |
492 |
""" |
""" |
493 |
|
|
494 |
|
# FIXME: When Thuban can rely on Python 2.3 as the oldest supported |
495 |
|
# Python release we don't need to override the run and |
496 |
|
# find_all_modules methods anymore. distutils will allow both python |
497 |
|
# modules and packages starting with 2.3. |
498 |
|
|
499 |
def run(self): |
def run(self): |
500 |
"""The same the as the original in build_py revision 1.33 except |
"""The same the as the original in build_py revision 1.33 except |
501 |
that this allows both packages and modules to be in one |
that this allows both packages and modules to be in one |
547 |
return modules |
return modules |
548 |
|
|
549 |
|
|
550 |
|
thubaninit_contents_start = """ |
551 |
|
# This module was automatically generated by Thuban's install script |
552 |
|
'''Import this module once per program (best place is probably the file |
553 |
|
that ends up as your __main__ module) to be able to import Thuban |
554 |
|
afterwards. |
555 |
|
|
556 |
|
Usage: |
557 |
|
|
558 |
|
import thubaninit |
559 |
|
import Thuban |
560 |
|
''' |
561 |
|
import sys, os |
562 |
|
""" |
563 |
|
|
564 |
|
thubaninit_contents_thubaninitdir = """ |
565 |
|
sys.path.insert(0, %(thubandir)s) |
566 |
|
""" |
567 |
|
thubaninit_contents_otherdirs = """ |
568 |
|
# Put the Lib dir into the path. The Lib dir contains some extra Python |
569 |
|
# modules |
570 |
|
import Thuban |
571 |
|
thubandir = os.path.join(Thuban.__path__[0], '..') |
572 |
|
dir = os.path.join(thubandir, "Lib") |
573 |
|
if os.path.isdir(dir): |
574 |
|
sys.path.insert(0, dir) |
575 |
|
""" |
576 |
|
|
577 |
|
def thubaninit_contents(thubandir): |
578 |
|
"""Return the contents of the the thubaninit file as a list of lines. |
579 |
|
|
580 |
|
The parameter thubandir is the parent directory where the Thuban/ |
581 |
|
package or the empty string if the thubaninit file itself will be |
582 |
|
located in that direcory as well. |
583 |
|
""" |
584 |
|
contents = thubaninit_contents_start |
585 |
|
if thubandir: |
586 |
|
thubandir = repr(thubandir) |
587 |
|
contents += thubaninit_contents_thubaninitdir % locals() |
588 |
|
contents += thubaninit_contents_otherdirs |
589 |
|
return contents.split("\n") |
590 |
|
|
591 |
|
|
592 |
class ThubanInstall(install): |
class ThubanInstall(install): |
593 |
|
|
604 |
"(default on posix systems and only relevant there)"), |
"(default on posix systems and only relevant there)"), |
605 |
|
|
606 |
("extra-files", None, |
("extra-files", None, |
607 |
"List of filenames or (src, dest) pairs describing " |
"List of filenames or (src, dest) pairs describing" |
608 |
" extra files to install " |
" extra files to install " |
609 |
"(can only be set from witin setup.py"), |
"(can only be set from witin setup.py"), |
610 |
|
|
611 |
|
("create-init-module=", None, |
612 |
|
"If true, create a module in the site-packages" |
613 |
|
" directory that tweaks sys.path to let you easily" |
614 |
|
" import thuban modules from outside of thuban."), |
615 |
|
("init-module-dir=", None, |
616 |
|
"Directory in which to create the init module." |
617 |
|
" Defaults to Python's site-packages directory."), |
618 |
]) |
]) |
619 |
|
|
620 |
boolean_options = install.boolean_options[:] |
boolean_options = install.boolean_options[:] |
621 |
boolean_options.append("do-symlink") |
boolean_options.append("do-symlink") |
622 |
|
boolean_options.append("create-init-module") |
623 |
|
|
624 |
def initialize_options(self): |
def initialize_options(self): |
625 |
self.do_symlink = None |
self.do_symlink = None |
626 |
self.extra_files = [] |
self.extra_files = [] |
627 |
|
|
628 |
|
# initialize the create_init_module flag from the global |
629 |
|
# determined at runtime |
630 |
|
self.create_init_module = create_init_module |
631 |
|
self.init_module_dir = None |
632 |
install.initialize_options(self) |
install.initialize_options(self) |
633 |
|
|
634 |
def finalize_options(self): |
def finalize_options(self): |
638 |
else: |
else: |
639 |
self.do_symlink = 0 |
self.do_symlink = 0 |
640 |
install.finalize_options(self) |
install.finalize_options(self) |
641 |
|
self.expand_with_pure_python_dirs(["init_module_dir"]) |
642 |
|
|
643 |
|
def expand_with_pure_python_dirs(self, attrs): |
644 |
|
"""Expand the attributes with default values of base and platbase""" |
645 |
|
# it seems that the values for "prefix" and "exec_prefix" in |
646 |
|
# self.config_vars are the corresponding values used by the |
647 |
|
# python interpreter, so we just assign these to "base" and |
648 |
|
# "platbase". |
649 |
|
config_vars = self.config_vars.copy() |
650 |
|
config_vars["base"] = self.config_vars["prefix"] |
651 |
|
config_vars["platbase"] = self.config_vars["exec_prefix"] |
652 |
|
for attr in attrs: |
653 |
|
val = getattr(self, attr) |
654 |
|
if val is not None: |
655 |
|
if os.name == 'posix': |
656 |
|
val = os.path.expanduser(val) |
657 |
|
val = subst_vars(val, config_vars) |
658 |
|
setattr(self, attr, val) |
659 |
|
|
660 |
|
def select_scheme(self, scheme): |
661 |
|
"""Extend the inherited method to set init_module_dir""" |
662 |
|
install.select_scheme(self, scheme) |
663 |
|
# only set init_module_dir if it wasn't set by the user |
664 |
|
if self.init_module_dir is None: |
665 |
|
self.init_module_dir = INSTALL_SCHEMES[scheme]['purelib'] |
666 |
|
|
667 |
|
def convert_paths(self, *args): |
668 |
|
"""Extend the inherited method so that we can remember some filename |
669 |
|
""" |
670 |
|
# remember the installation directory before its root gets |
671 |
|
# changed |
672 |
|
self.install_lib_orig = self.install_lib |
673 |
|
apply(install.convert_paths, (self,) + args) |
674 |
|
|
675 |
def run(self): |
def run(self): |
676 |
install.run(self) |
install.run(self) |
679 |
src, dest = item |
src, dest = item |
680 |
else: |
else: |
681 |
src = dest = item |
src = dest = item |
682 |
self.copy_file(convert_path(src), |
self.copy_file(convert_path(src), |
683 |
os.path.join(self.root, convert_path(dest))) |
os.path.join(self.root, convert_path(dest))) |
684 |
|
|
685 |
if os.name == "posix" and self.do_symlink: |
if os.name == "posix" and self.do_symlink: |
694 |
self.mkpath(bindir) |
self.mkpath(bindir) |
695 |
self.link_file(scriptfile, binfile) |
self.link_file(scriptfile, binfile) |
696 |
|
|
697 |
|
if self.create_init_module: |
698 |
|
# create the init module |
699 |
|
initfilename = self.thuban_init_filename() |
700 |
|
if self.root: |
701 |
|
initfilename = change_root(self.root, initfilename) |
702 |
|
contents = thubaninit_contents(self.install_lib_orig) |
703 |
|
self.mkpath(os.path.dirname(initfilename)) |
704 |
|
self.execute(write_file, (initfilename, contents), |
705 |
|
"Create %s" % initfilename) |
706 |
|
|
707 |
def link_file(self, src, dest): |
def link_file(self, src, dest): |
708 |
"""Create a symbolic link dest pointing to src. |
"""Create a symbolic link dest pointing to src. |
709 |
|
|
718 |
if not os.path.exists(dest): |
if not os.path.exists(dest): |
719 |
os.symlink(src, dest) |
os.symlink(src, dest) |
720 |
|
|
721 |
|
def thuban_init_filename(self): |
722 |
|
"""Return the filename for the init-module""" |
723 |
|
# Since we override the normal install dirs to point to our own |
724 |
|
# prefix we have to reach into installed |
725 |
|
return self.init_module_dir + "/thubaninit.py" |
726 |
|
|
727 |
def get_outputs (self): |
def get_outputs (self): |
728 |
outputs = install.get_outputs(self) |
outputs = install.get_outputs(self) |
738 |
bindir = change_root(self.root, bindir) |
bindir = change_root(self.root, bindir) |
739 |
binfile = os.path.join(bindir, "thuban") |
binfile = os.path.join(bindir, "thuban") |
740 |
outputs.append(binfile) |
outputs.append(binfile) |
741 |
|
if self.create_init_module: |
742 |
|
initfilename = self.thuban_init_filename() |
743 |
|
if self.root: |
744 |
|
initfilename = change_root(self.root, initfilename) |
745 |
|
outputs.append(initfilename) |
746 |
return outputs |
return outputs |
747 |
|
|
748 |
|
|
749 |
|
# scripts to override some of the commands put into the spec-file by the |
750 |
|
# bdist_rpm command. |
751 |
|
|
752 |
bdist_rpm_prep_script = ''' |
bdist_rpm_prep_script = ''' |
753 |
%setup |
%setup |
754 |
cp extensions/pyshapelib/{README,README.pyshapelib} |
cp extensions/pyshapelib/{README,README.pyshapelib} |
756 |
cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection} |
cp extensions/pyprojection/{LICENSE,LICENSE.pyprojection} |
757 |
''' |
''' |
758 |
|
|
759 |
|
bdist_rpm_install_script = ''' |
760 |
|
%(python)s setup.py install --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES \ |
761 |
|
--prefix=%(prefix)s |
762 |
|
''' |
763 |
|
|
764 |
|
|
|
|
|
765 |
class thuban_bdist_rpm(bdist_rpm): |
class thuban_bdist_rpm(bdist_rpm): |
766 |
|
|
767 |
"""Thuban specific RPM distribution command""" |
"""Thuban specific RPM distribution command""" |
768 |
|
|
769 |
|
user_options = bdist_rpm.user_options[:] |
770 |
|
user_options.extend([("prefix=", None, "Install prefix for the RPM"), |
771 |
|
]) |
772 |
|
|
773 |
def initialize_options(self): |
def initialize_options(self): |
774 |
# create the prep script for the spec-file |
# per default, RPMs are installed in /usr |
775 |
open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script) |
self.prefix = "/usr/" |
776 |
|
|
777 |
|
# create the scripts we want to override. We actually fill them |
778 |
|
# with contents later because some values we put into those |
779 |
|
# scripts such as the python interpreter to use are only known |
780 |
|
# then. |
781 |
|
open("bdist_rpm_prep", "w").close() |
782 |
|
open("bdist_rpm_install", "w").close() |
783 |
bdist_rpm.initialize_options(self) |
bdist_rpm.initialize_options(self) |
784 |
|
|
785 |
|
def _make_spec_file(self): |
786 |
|
# create the scripts for the spec-file. Now we know the python |
787 |
|
# interpreter to use. |
788 |
|
open("bdist_rpm_prep", "w").write(bdist_rpm_prep_script) |
789 |
|
install = bdist_rpm_install_script % {"python": self.python, |
790 |
|
"prefix": self.prefix} |
791 |
|
open("bdist_rpm_install", "w").write(install) |
792 |
|
|
793 |
|
# |
794 |
|
return bdist_rpm._make_spec_file(self) |
795 |
|
|
796 |
|
|
797 |
class bdist_inno(Command): |
class bdist_inno(Command): |
798 |
|
|
895 |
self.execute(write_file, (iss_file, self.generate_iss()), |
self.execute(write_file, (iss_file, self.generate_iss()), |
896 |
"Create Inno Setup script file %s" % iss_file) |
"Create Inno Setup script file %s" % iss_file) |
897 |
|
|
898 |
# and invoke |
# and invoke |
899 |
if self.run_inno: |
if self.run_inno: |
900 |
self.spawn(["iscc", iss_file]) |
self.spawn(["iscc", iss_file]) |
901 |
|
|
961 |
line = 'Name: "{group}\\%s"; Filename: "%s";' \ |
line = 'Name: "{group}\\%s"; Filename: "%s";' \ |
962 |
% (icon.title, icon.install_name) |
% (icon.title, icon.install_name) |
963 |
iss.append(line) |
iss.append(line) |
964 |
|
|
965 |
return iss |
return iss |
966 |
|
|
967 |
|
|
977 |
else: |
else: |
978 |
self.install_name = filename |
self.install_name = filename |
979 |
|
|
980 |
|
|
981 |
class thuban_bdist_inno(bdist_inno): |
class thuban_bdist_inno(bdist_inno): |
982 |
|
|
983 |
"""Thuban specific Inno Setup stuff""" |
"""Thuban specific Inno Setup stuff""" |
993 |
# that we can generate the iss-file even on Linux |
# that we can generate the iss-file even on Linux |
994 |
install_options["do_symlink"] = 0 |
install_options["do_symlink"] = 0 |
995 |
bdist_inno.run(self, install_options) |
bdist_inno.run(self, install_options) |
996 |
|
|
997 |
|
|
998 |
# |
# |
999 |
# Run the script |
# Run the script |
1000 |
# |
# |
1005 |
""" |
""" |
1006 |
|
|
1007 |
setup(name = "Thuban", |
setup(name = "Thuban", |
1008 |
version = "0.1.1", |
version = "0.2.0", |
1009 |
description = "Geographic data viewer", |
description = "Geographic data viewer", |
1010 |
long_description = long_description, |
long_description = long_description, |
1011 |
licence = "GPL", |
licence = "GPL", |
1012 |
author = "Intevation GmbH", |
author = "Intevation GmbH", |
1013 |
author_email = "[email protected]", |
author_email = "[email protected]", |
1014 |
url = "ftp:intevation.de/", |
url = "http://thuban.intevation.de/", |
1015 |
|
|
1016 |
scripts = ["thuban.py"], |
scripts = ["thuban.py"], |
1017 |
packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"], |
packages = ["Thuban", "Thuban.Lib", "Thuban.Model", "Thuban.UI"], |
1025 |
{"prefix": prefix, |
{"prefix": prefix, |
1026 |
# make sure both libs and scripts are installed in the |
# make sure both libs and scripts are installed in the |
1027 |
# same directory. |
# same directory. |
1028 |
"install_lib": "$base/thuban", |
"install_lib": "$base/lib/thuban", |
1029 |
"install_scripts": "$base/thuban", |
"install_scripts": "$base/lib/thuban", |
1030 |
"install_data": "$base/thuban", |
"install_data": "$base/lib/thuban", |
1031 |
|
|
1032 |
# Don't print warning messages about the lib dir not |
# Don't print warning messages about the lib dir not |
1033 |
# being on Python's path. The libraries are Thuban |
# being on Python's path. The libraries are Thuban |