Mercurial > p > roundup > code
comparison setup.py @ 2365:3a80831ecebe
If the target platform is win32, create .bat files...
...instead of *nix shell scripts.
Target platform is set to "win32" if main command is 'bdist_wininst'
or if the command is 'bdist' and it has the list of formats (from
command line or config file) and the first item on that list is wininst.
Otherwise target platform is set to current (build) platform.
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Wed, 26 May 2004 10:00:53 +0000 |
| parents | 804c5c735bf1 |
| children | 487d9256f32e |
comparison
equal
deleted
inserted
replaced
| 2364:dfce8454848d | 2365:3a80831ecebe |
|---|---|
| 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 14 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 15 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 16 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 17 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 18 # | 18 # |
| 19 # $Id: setup.py,v 1.68 2004-05-18 19:46:35 a1s Exp $ | 19 # $Id: setup.py,v 1.69 2004-05-26 10:00:53 a1s Exp $ |
| 20 | 20 |
| 21 from distutils.core import setup, Extension | 21 from distutils.core import setup, Extension |
| 22 from distutils.util import get_platform | 22 from distutils.util import get_platform |
| 23 from distutils.command.build_scripts import build_scripts | 23 from distutils.command.build_scripts import build_scripts |
| 24 from distutils.command.build import build | 24 from distutils.command.build import build |
| 50 | 50 |
| 51 <packagename>.scripts.<mangled_scriptname> | 51 <packagename>.scripts.<mangled_scriptname> |
| 52 | 52 |
| 53 The mangling of script names replaces '-' and '/' characters | 53 The mangling of script names replaces '-' and '/' characters |
| 54 with '-' and '.', so that they are valid module paths. | 54 with '-' and '.', so that they are valid module paths. |
| 55 | |
| 56 If the target platform is win32, create .bat files instead of | |
| 57 *nix shell scripts. Target platform is set to "win32" if main | |
| 58 command is 'bdist_wininst' or if the command is 'bdist' and | |
| 59 it has the list of formats (from command line or config file) | |
| 60 and the first item on that list is wininst. Otherwise | |
| 61 target platform is set to current (build) platform. | |
| 55 """ | 62 """ |
| 56 package_name = None | 63 package_name = None |
| 64 | |
| 65 def initialize_options(self): | |
| 66 build_scripts.initialize_options(self) | |
| 67 self.script_preamble = None | |
| 68 self.target_platform = None | |
| 69 self.python_executable = None | |
| 70 | |
| 71 def finalize_options(self): | |
| 72 build_scripts.finalize_options(self) | |
| 73 cmdopt=self.distribution.command_options | |
| 74 | |
| 75 # find the target platform | |
| 76 if self.target_platform: | |
| 77 # TODO? allow explicit setting from command line | |
| 78 target = self.target_platform | |
| 79 if "bdist_wininst" in cmdopt: | |
| 80 target = "win32" | |
| 81 elif "formats" in cmdopt.get("bdist", {}): | |
| 82 formats = cmdopt["bdist"]["formats"][1].split(",") | |
| 83 if formats[0] == "wininst": | |
| 84 target = "win32" | |
| 85 else: | |
| 86 target = sys.platform | |
| 87 if len(formats) > 1: | |
| 88 self.warn( | |
| 89 "Scripts are built for %s only (requested formats: %s)" | |
| 90 % (target, ",".join(formats))) | |
| 91 else: | |
| 92 # default to current platform | |
| 93 target = sys.platform | |
| 94 self.target_platfom = target | |
| 95 | |
| 96 # for native builds, use current python executable path; | |
| 97 # for cross-platform builds, use default executable name | |
| 98 if self.python_executable: | |
| 99 # TODO? allow command-line option | |
| 100 pass | |
| 101 if target == sys.platform: | |
| 102 self.python_executable = os.path.normpath(sys.executable) | |
| 103 else: | |
| 104 self.python_executable = "python" | |
| 105 | |
| 106 # for windows builds, add ".bat" extension | |
| 107 if target == "win32": | |
| 108 # *nix-like scripts may be useful also on win32 (cygwin) | |
| 109 # to build both script versions, use: | |
| 110 #self.scripts = list(self.scripts) + [script + ".bat" | |
| 111 # for script in self.scripts] | |
| 112 self.scripts = [script + ".bat" for script in self.scripts] | |
| 113 | |
| 114 # tweak python path for installations outside main python library | |
| 115 if "prefix" in cmdopt.get("install", {}): | |
| 116 prefix = cmdopt['install']['prefix'][1] | |
| 117 version = '%d.%d'%sys.version_info[:2] | |
| 118 self.script_preamble = ''' | |
| 119 import sys | |
| 120 sys.path.insert(1, "%s/lib/python%s/site-packages") | |
| 121 '''%(prefix, version) | |
| 122 else: | |
| 123 self.script_preamble = '' | |
| 57 | 124 |
| 58 def copy_scripts(self): | 125 def copy_scripts(self): |
| 59 """ Create each script listed in 'self.scripts' | 126 """ Create each script listed in 'self.scripts' |
| 60 """ | 127 """ |
| 61 if not self.package_name: | 128 if not self.package_name: |
| 76 self.announce("would create %s" % outfile) | 143 self.announce("would create %s" % outfile) |
| 77 continue | 144 continue |
| 78 | 145 |
| 79 module = os.path.splitext(os.path.basename(script))[0] | 146 module = os.path.splitext(os.path.basename(script))[0] |
| 80 module = string.translate(module, to_module) | 147 module = string.translate(module, to_module) |
| 81 cmdopt=self.distribution.command_options | |
| 82 if (cmdopt.has_key('install') and | |
| 83 cmdopt['install'].has_key('prefix')): | |
| 84 prefix = cmdopt['install']['prefix'][1] | |
| 85 version = '%d.%d'%sys.version_info[:2] | |
| 86 prefix = ''' | |
| 87 import sys | |
| 88 sys.path.insert(1, "%s/lib/python%s/site-packages") | |
| 89 '''%(prefix, version) | |
| 90 else: | |
| 91 prefix = '' | |
| 92 script_vars = { | 148 script_vars = { |
| 93 'python': os.path.normpath(sys.executable), | 149 'python': self.python_executable, |
| 94 'package': self.package_name, | 150 'package': self.package_name, |
| 95 'module': module, | 151 'module': module, |
| 96 'prefix': prefix, | 152 'prefix': self.script_preamble, |
| 97 } | 153 } |
| 98 | 154 |
| 99 self.announce("creating %s" % outfile) | 155 self.announce("creating %s" % outfile) |
| 100 file = open(outfile, 'w') | 156 file = open(outfile, 'w') |
| 101 | 157 |
| 102 try: | 158 try: |
| 103 if sys.platform == "win32": | 159 # could just check self.target_platform, |
| 160 # but looking at the script extension | |
| 161 # makes it possible to build both *nix-like | |
| 162 # and windows-like scripts on win32. | |
| 163 # may be useful for cygwin. | |
| 164 if os.path.splitext(outfile)[1] == ".bat": | |
| 104 file.write('@echo off\n' | 165 file.write('@echo off\n' |
| 105 'if NOT "%%_4ver%%" == "" "%(python)s" -O -c "from %(package)s.scripts.%(module)s import run; run()" %%$\n' | 166 'if NOT "%%_4ver%%" == "" "%(python)s" -O -c "from %(package)s.scripts.%(module)s import run; run()" %%$\n' |
| 106 'if "%%_4ver%%" == "" "%(python)s" -O -c "from %(package)s.scripts.%(module)s import run; run()" %%*\n' | 167 'if "%%_4ver%%" == "" "%(python)s" -O -c "from %(package)s.scripts.%(module)s import run; run()" %%*\n' |
| 107 % script_vars) | 168 % script_vars) |
| 108 else: | 169 else: |
| 123 """ Helper for building a list of script names from a list of | 184 """ Helper for building a list of script names from a list of |
| 124 module files. | 185 module files. |
| 125 """ | 186 """ |
| 126 script = os.path.splitext(os.path.basename(path))[0] | 187 script = os.path.splitext(os.path.basename(path))[0] |
| 127 script = string.replace(script, '_', '-') | 188 script = string.replace(script, '_', '-') |
| 128 if sys.platform == "win32": | |
| 129 script = script + ".bat" | |
| 130 return script | 189 return script |
| 131 | 190 |
| 132 ### Build Roundup | 191 ### Build Roundup |
| 133 | 192 |
| 134 def list_message_files(suffix=".mo"): | 193 def list_message_files(suffix=".mo"): |
