Changeset 391 for python/trunk/Lib/distutils/command
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 22 edited
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/distutils/command/__init__.py
r2 r391 4 4 commands.""" 5 5 6 # This module should be kept compatible with Python 2.1. 7 8 __revision__ = "$Id: __init__.py 71272 2009-04-05 21:21:05Z georg.brandl $" 6 __revision__ = "$Id$" 9 7 10 8 __all__ = ['build', … … 26 24 'bdist_wininst', 27 25 'upload', 28 26 'check', 29 27 # These two are reserved for future use: 30 28 #'bdist_sdux', -
python/trunk/Lib/distutils/command/bdist.py
r2 r391 4 4 distribution).""" 5 5 6 # This module should be kept compatible with Python 2.1. 7 8 __revision__ = "$Id: bdist.py 62197 2008-04-07 01:53:39Z mark.hammond $" 6 __revision__ = "$Id$" 9 7 10 8 import os 11 from types import * 9 10 from distutils.util import get_platform 12 11 from distutils.core import Command 13 from distutils.errors import * 14 from distutils.util import get_platform 12 from distutils.errors import DistutilsPlatformError, DistutilsOptionError 15 13 16 14 17 def show_formats 15 def show_formats(): 18 16 """Print list of available formats (arguments to "--format" option). 19 17 """ 20 18 from distutils.fancy_getopt import FancyGetopt 21 formats =[]19 formats = [] 22 20 for format in bdist.format_commands: 23 21 formats.append(("formats=" + format, None, … … 27 25 28 26 29 class bdist 27 class bdist(Command): 30 28 31 29 description = "create a built (binary) distribution" … … 43 41 ('skip-build', None, 44 42 "skip rebuilding everything (for testing/debugging)"), 43 ('owner=', 'u', 44 "Owner name used when creating a tar file" 45 " [default: current user]"), 46 ('group=', 'g', 47 "Group name used when creating a tar file" 48 " [default: current group]"), 45 49 ] 46 50 … … 53 57 54 58 # The following commands do not take a format option from bdist 55 no_format_option = ('bdist_rpm', 56 #'bdist_sdux', 'bdist_pkgtool' 57 ) 59 no_format_option = ('bdist_rpm',) 58 60 59 61 # This won't do in reality: will need to distinguish RPM-ish Linux, 60 62 # Debian-ish Linux, Solaris, FreeBSD, ..., Windows, Mac OS. 61 default_format = { 62 63 'os2': 'zip',}63 default_format = {'posix': 'gztar', 64 'nt': 'zip', 65 'os2': 'zip'} 64 66 65 67 # Establish the preferred order (for the --help-formats option). 66 68 format_commands = ['rpm', 'gztar', 'bztar', 'ztar', 'tar', 67 'wininst', 'zip', 68 #'pkgtool', 'sdux' 69 ] 69 'wininst', 'zip', 'msi'] 70 70 71 71 # And the real information. 72 format_command = { 'rpm': ('bdist_rpm', "RPM distribution"), 73 'zip': ('bdist_dumb', "ZIP file"), 74 'gztar': ('bdist_dumb', "gzip'ed tar file"), 75 'bztar': ('bdist_dumb', "bzip2'ed tar file"), 76 'ztar': ('bdist_dumb', "compressed tar file"), 77 'tar': ('bdist_dumb', "tar file"), 78 'wininst': ('bdist_wininst', 79 "Windows executable installer"), 80 'zip': ('bdist_dumb', "ZIP file"), 81 #'pkgtool': ('bdist_pkgtool', 82 # "Solaris pkgtool distribution"), 83 #'sdux': ('bdist_sdux', "HP-UX swinstall depot"), 72 format_command = {'rpm': ('bdist_rpm', "RPM distribution"), 73 'gztar': ('bdist_dumb', "gzip'ed tar file"), 74 'bztar': ('bdist_dumb', "bzip2'ed tar file"), 75 'ztar': ('bdist_dumb', "compressed tar file"), 76 'tar': ('bdist_dumb', "tar file"), 77 'wininst': ('bdist_wininst', 78 "Windows executable installer"), 79 'zip': ('bdist_dumb', "ZIP file"), 80 'msi': ('bdist_msi', "Microsoft Installer") 84 81 } 85 82 86 83 87 def initialize_options 84 def initialize_options(self): 88 85 self.bdist_base = None 89 86 self.plat_name = None … … 91 88 self.dist_dir = None 92 89 self.skip_build = 0 90 self.group = None 91 self.owner = None 93 92 94 # initialize_options() 95 96 97 def finalize_options (self): 93 def finalize_options(self): 98 94 # have to finalize 'plat_name' before 'bdist_base' 99 95 if self.plat_name is None: … … 123 119 self.dist_dir = "dist" 124 120 125 # finalize_options() 126 127 def run (self): 128 121 def run(self): 129 122 # Figure out which sub-commands we need to run. 130 123 commands = [] … … 142 135 sub_cmd.format = self.formats[i] 143 136 137 # passing the owner and group names for tar archiving 138 if cmd_name == 'bdist_dumb': 139 sub_cmd.owner = self.owner 140 sub_cmd.group = self.group 141 144 142 # If we're going to need to run this command again, tell it to 145 143 # keep its temporary files around so subsequent runs go faster. … … 147 145 sub_cmd.keep_temp = 1 148 146 self.run_command(cmd_name) 149 150 # run()151 152 # class bdist -
python/trunk/Lib/distutils/command/bdist_dumb.py
r2 r391 5 5 $exec_prefix).""" 6 6 7 # This module should be kept compatible with Python 2.1. 8 9 __revision__ = "$Id: bdist_dumb.py 61000 2008-02-23 17:40:11Z christian.heimes $" 7 __revision__ = "$Id$" 10 8 11 9 import os 10 11 from sysconfig import get_python_version 12 13 from distutils.util import get_platform 12 14 from distutils.core import Command 13 from distutils.util import get_platform14 15 from distutils.dir_util import remove_tree, ensure_relative 15 from distutils.errors import * 16 from distutils.sysconfig import get_python_version 16 from distutils.errors import DistutilsPlatformError 17 17 from distutils import log 18 18 19 19 class bdist_dumb (Command): 20 20 21 description = "create a \"dumb\" built distribution"21 description = 'create a "dumb" built distribution' 22 22 23 23 user_options = [('bdist-dir=', 'd', … … 38 38 "build the archive using relative paths" 39 39 "(default: false)"), 40 ('owner=', 'u', 41 "Owner name used when creating a tar file" 42 " [default: current user]"), 43 ('group=', 'g', 44 "Group name used when creating a tar file" 45 " [default: current group]"), 40 46 ] 41 47 … … 53 59 self.keep_temp = 0 54 60 self.dist_dir = None 55 self.skip_build = 061 self.skip_build = None 56 62 self.relative = 0 63 self.owner = None 64 self.group = None 57 65 58 # initialize_options() 59 60 61 def finalize_options (self): 62 66 def finalize_options(self): 63 67 if self.bdist_dir is None: 64 68 bdist_base = self.get_finalized_command('bdist').bdist_base … … 75 79 self.set_undefined_options('bdist', 76 80 ('dist_dir', 'dist_dir'), 77 ('plat_name', 'plat_name')) 81 ('plat_name', 'plat_name'), 82 ('skip_build', 'skip_build')) 78 83 79 # finalize_options() 80 81 82 def run (self): 83 84 def run(self): 84 85 if not self.skip_build: 85 86 self.run_command('build') … … 120 121 # Make the archive 121 122 filename = self.make_archive(pseudoinstall_root, 122 self.format, root_dir=archive_root) 123 self.format, root_dir=archive_root, 124 owner=self.owner, group=self.group) 123 125 if self.distribution.has_ext_modules(): 124 126 pyversion = get_python_version() … … 130 132 if not self.keep_temp: 131 133 remove_tree(self.bdist_dir, dry_run=self.dry_run) 132 133 # run()134 135 # class bdist_dumb -
python/trunk/Lib/distutils/command/bdist_msi.py
r2 r391 1 1 # -*- coding: iso-8859-1 -*- 2 # Copyright (C) 2005, 2006 Martin v .Löwis2 # Copyright (C) 2005, 2006 Martin von Löwis 3 3 # Licensed to PSF under a Contributor Agreement. 4 4 # The bdist_wininst command proper … … 7 7 Implements the bdist_msi command. 8 8 """ 9 10 9 import sys, os 10 from sysconfig import get_python_version 11 11 12 from distutils.core import Command 12 13 from distutils.dir_util import remove_tree 13 from distutils.sysconfig import get_python_version14 14 from distutils.version import StrictVersion 15 15 from distutils.errors import DistutilsOptionError 16 from distutils import log 16 17 from distutils.util import get_platform 17 from distutils import log 18 18 19 import msilib 19 20 from msilib import schema, sequence, text … … 29 30 Dialog.__init__(self, *args) 30 31 ruler = self.h - 36 31 bmwidth = 152*ruler/32832 32 #if kw.get("bitmap", True): 33 33 # self.bitmap("Bitmap", 0, 0, bmwidth, ruler, "PythonWin") … … 118 118 'skip-build'] 119 119 120 all_versions = ['2.0', '2.1', '2.2', '2.3', '2.4', 121 '2.5', '2.6', '2.7', '2.8', '2.9', 122 '3.0', '3.1', '3.2', '3.3', '3.4', 123 '3.5', '3.6', '3.7', '3.8', '3.9'] 124 other_version = 'X' 125 120 126 def initialize_options (self): 121 127 self.bdist_dir = None … … 126 132 self.target_version = None 127 133 self.dist_dir = None 128 self.skip_build = 0134 self.skip_build = None 129 135 self.install_script = None 130 136 self.pre_install_script = None 137 self.versions = None 131 138 132 139 def finalize_options (self): 140 self.set_undefined_options('bdist', ('skip_build', 'skip_build')) 141 133 142 if self.bdist_dir is None: 134 143 bdist_base = self.get_finalized_command('bdist').bdist_base 135 144 self.bdist_dir = os.path.join(bdist_base, 'msi') 145 136 146 short_version = get_python_version() 147 if (not self.target_version) and self.distribution.has_ext_modules(): 148 self.target_version = short_version 149 137 150 if self.target_version: 151 self.versions = [self.target_version] 138 152 if not self.skip_build and self.distribution.has_ext_modules()\ 139 153 and self.target_version != short_version: 140 154 raise DistutilsOptionError, \ 141 "target version can only be %s, or the '--skip _build'" \155 "target version can only be %s, or the '--skip-build'" \ 142 156 " option must be specified" % (short_version,) 143 157 else: 144 self. target_version = short_version158 self.versions = list(self.all_versions) 145 159 146 160 self.set_undefined_options('bdist', … … 224 238 # it sorts together with the other Python packages 225 239 # in Add-Remove-Programs (APR) 226 product_name = "Python %s %s" % (self.target_version, 227 self.distribution.get_fullname()) 240 fullname = self.distribution.get_fullname() 241 if self.target_version: 242 product_name = "Python %s %s" % (self.target_version, fullname) 243 else: 244 product_name = "Python %s" % (fullname) 228 245 self.db = msilib.init_database(installer_name, schema, 229 246 product_name, msilib.gen_uuid(), … … 246 263 247 264 if hasattr(self.distribution, 'dist_files'): 248 self.distribution.dist_files.append(('bdist_msi', self.target_version, fullname)) 265 tup = 'bdist_msi', self.target_version or 'any', fullname 266 self.distribution.dist_files.append(tup) 249 267 250 268 if not self.keep_temp: … … 254 272 db = self.db 255 273 cab = msilib.CAB("distfiles") 256 f = Feature(db, "default", "Default Feature", "Everything", 1, directory="TARGETDIR")257 f.set_current()258 274 rootdir = os.path.abspath(self.bdist_dir) 275 259 276 root = Directory(db, cab, None, rootdir, "TARGETDIR", "SourceDir") 277 f = Feature(db, "Python", "Python", "Everything", 278 0, 1, directory="TARGETDIR") 279 280 items = [(f, root, '')] 281 for version in self.versions + [self.other_version]: 282 target = "TARGETDIR" + version 283 name = default = "Python" + version 284 desc = "Everything" 285 if version is self.other_version: 286 title = "Python from another location" 287 level = 2 288 else: 289 title = "Python %s from registry" % version 290 level = 1 291 f = Feature(db, name, title, desc, 1, level, directory=target) 292 dir = Directory(db, cab, root, rootdir, target, default) 293 items.append((f, dir, version)) 260 294 db.Commit() 261 todo = [root] 262 while todo: 263 dir = todo.pop() 264 for file in os.listdir(dir.absolute): 265 afile = os.path.join(dir.absolute, file) 266 if os.path.isdir(afile): 267 newdir = Directory(db, cab, dir, file, file, "%s|%s" % (dir.make_short(file), file)) 268 todo.append(newdir) 269 else: 270 key = dir.add_file(file) 271 if file==self.install_script: 272 if self.install_script_key: 273 raise DistutilsOptionError, "Multiple files with name %s" % file 274 self.install_script_key = '[#%s]' % key 275 295 296 seen = {} 297 for feature, dir, version in items: 298 todo = [dir] 299 while todo: 300 dir = todo.pop() 301 for file in os.listdir(dir.absolute): 302 afile = os.path.join(dir.absolute, file) 303 if os.path.isdir(afile): 304 short = "%s|%s" % (dir.make_short(file), file) 305 default = file + version 306 newdir = Directory(db, cab, dir, file, default, short) 307 todo.append(newdir) 308 else: 309 if not dir.component: 310 dir.start_component(dir.logical, feature, 0) 311 if afile not in seen: 312 key = seen[afile] = dir.add_file(file) 313 if file==self.install_script: 314 if self.install_script_key: 315 raise DistutilsOptionError( 316 "Multiple files with name %s" % file) 317 self.install_script_key = '[#%s]' % key 318 else: 319 key = seen[afile] 320 add_data(self.db, "DuplicateFile", 321 [(key + version, dir.component, key, None, dir.logical)]) 322 db.Commit() 276 323 cab.commit(db) 277 324 278 325 def add_find_python(self): 279 326 """Adds code to the installer to compute the location of Python. 280 Properties PYTHON.MACHINE, PYTHON.USER, PYTHONDIR and PYTHON will be set 281 in both the execute and UI sequences; PYTHONDIR will be set from 282 PYTHON.USER if defined, else from PYTHON.MACHINE. 283 PYTHON is PYTHONDIR\python.exe""" 284 install_path = r"SOFTWARE\Python\PythonCore\%s\InstallPath" % self.target_version 285 if msilib.Win64: 286 # type: msidbLocatorTypeRawValue + msidbLocatorType64bit 287 Type = 2+16 288 else: 289 Type = 2 290 add_data(self.db, "RegLocator", 291 [("python.machine", 2, install_path, None, Type), 292 ("python.user", 1, install_path, None, Type)]) 293 add_data(self.db, "AppSearch", 294 [("PYTHON.MACHINE", "python.machine"), 295 ("PYTHON.USER", "python.user")]) 296 add_data(self.db, "CustomAction", 297 [("PythonFromMachine", 51+256, "PYTHONDIR", "[PYTHON.MACHINE]"), 298 ("PythonFromUser", 51+256, "PYTHONDIR", "[PYTHON.USER]"), 299 ("PythonExe", 51+256, "PYTHON", "[PYTHONDIR]\\python.exe"), 300 ("InitialTargetDir", 51+256, "TARGETDIR", "[PYTHONDIR]")]) 301 add_data(self.db, "InstallExecuteSequence", 302 [("PythonFromMachine", "PYTHON.MACHINE", 401), 303 ("PythonFromUser", "PYTHON.USER", 402), 304 ("PythonExe", None, 403), 305 ("InitialTargetDir", 'TARGETDIR=""', 404), 306 ]) 307 add_data(self.db, "InstallUISequence", 308 [("PythonFromMachine", "PYTHON.MACHINE", 401), 309 ("PythonFromUser", "PYTHON.USER", 402), 310 ("PythonExe", None, 403), 311 ("InitialTargetDir", 'TARGETDIR=""', 404), 312 ]) 327 328 Properties PYTHON.MACHINE.X.Y and PYTHON.USER.X.Y will be set from the 329 registry for each version of Python. 330 331 Properties TARGETDIRX.Y will be set from PYTHON.USER.X.Y if defined, 332 else from PYTHON.MACHINE.X.Y. 333 334 Properties PYTHONX.Y will be set to TARGETDIRX.Y\\python.exe""" 335 336 start = 402 337 for ver in self.versions: 338 install_path = r"SOFTWARE\Python\PythonCore\%s\InstallPath" % ver 339 machine_reg = "python.machine." + ver 340 user_reg = "python.user." + ver 341 machine_prop = "PYTHON.MACHINE." + ver 342 user_prop = "PYTHON.USER." + ver 343 machine_action = "PythonFromMachine" + ver 344 user_action = "PythonFromUser" + ver 345 exe_action = "PythonExe" + ver 346 target_dir_prop = "TARGETDIR" + ver 347 exe_prop = "PYTHON" + ver 348 if msilib.Win64: 349 # type: msidbLocatorTypeRawValue + msidbLocatorType64bit 350 Type = 2+16 351 else: 352 Type = 2 353 add_data(self.db, "RegLocator", 354 [(machine_reg, 2, install_path, None, Type), 355 (user_reg, 1, install_path, None, Type)]) 356 add_data(self.db, "AppSearch", 357 [(machine_prop, machine_reg), 358 (user_prop, user_reg)]) 359 add_data(self.db, "CustomAction", 360 [(machine_action, 51+256, target_dir_prop, "[" + machine_prop + "]"), 361 (user_action, 51+256, target_dir_prop, "[" + user_prop + "]"), 362 (exe_action, 51+256, exe_prop, "[" + target_dir_prop + "]\\python.exe"), 363 ]) 364 add_data(self.db, "InstallExecuteSequence", 365 [(machine_action, machine_prop, start), 366 (user_action, user_prop, start + 1), 367 (exe_action, None, start + 2), 368 ]) 369 add_data(self.db, "InstallUISequence", 370 [(machine_action, machine_prop, start), 371 (user_action, user_prop, start + 1), 372 (exe_action, None, start + 2), 373 ]) 374 add_data(self.db, "Condition", 375 [("Python" + ver, 0, "NOT TARGETDIR" + ver)]) 376 start += 4 377 assert start < 500 313 378 314 379 def add_scripts(self): 315 380 if self.install_script: 316 add_data(self.db, "CustomAction", 317 [("install_script", 50, "PYTHON", self.install_script_key)]) 318 add_data(self.db, "InstallExecuteSequence", 319 [("install_script", "NOT Installed", 6800)]) 381 start = 6800 382 for ver in self.versions + [self.other_version]: 383 install_action = "install_script." + ver 384 exe_prop = "PYTHON" + ver 385 add_data(self.db, "CustomAction", 386 [(install_action, 50, exe_prop, self.install_script_key)]) 387 add_data(self.db, "InstallExecuteSequence", 388 [(install_action, "&Python%s=3" % ver, start)]) 389 start += 1 390 # XXX pre-install scripts are currently refused in finalize_options() 391 # but if this feature is completed, it will also need to add 392 # entries for each version as the above code does 320 393 if self.pre_install_script: 321 394 scriptfn = os.path.join(self.bdist_dir, "preinstall.bat") … … 352 425 modal = 3 # visible | modal 353 426 modeless = 1 # visible 354 track_disk_space = 32355 427 356 428 # UI customization properties … … 381 453 ("WhichUsersDlg", "Privileged and not Windows9x and not Installed", 141), 382 454 # In the user interface, assume all-users installation if privileged. 383 ("Select DirectoryDlg", "Not Installed", 1230),455 ("SelectFeaturesDlg", "Not Installed", 1230), 384 456 # XXX no support for resume installations yet 385 457 #("ResumeDlg", "Installed AND (RESUME OR Preselected)", 1240), … … 504 576 505 577 ##################################################################### 506 # Target directoryselection507 seldlg = PyDialog(db, "Select DirectoryDlg", x, y, w, h, modal, title,578 # Feature (Python directory) selection 579 seldlg = PyDialog(db, "SelectFeaturesDlg", x, y, w, h, modal, title, 508 580 "Next", "Next", "Cancel") 509 seldlg.title("Select Destination Directory")510 511 version = sys.version[:3]+" "512 seldlg.text("Hint", 15, 30, 300, 40, 3,513 "The destination directory should contain a Python %sinstallation" % version)581 seldlg.title("Select Python Installations") 582 583 seldlg.text("Hint", 15, 30, 300, 20, 3, 584 "Select the Python locations where %s should be installed." 585 % self.distribution.get_fullname()) 514 586 515 587 seldlg.back("< Back", None, active=0) 516 588 c = seldlg.next("Next >", "Cancel") 517 c.event("SetTargetPath", "TARGETDIR", ordering=1) 518 c.event("SpawnWaitDialog", "WaitForCostingDlg", ordering=2) 519 c.event("EndDialog", "Return", ordering=3) 520 521 c = seldlg.cancel("Cancel", "DirectoryCombo") 589 order = 1 590 c.event("[TARGETDIR]", "[SourceDir]", ordering=order) 591 for version in self.versions + [self.other_version]: 592 order += 1 593 c.event("[TARGETDIR]", "[TARGETDIR%s]" % version, 594 "FEATURE_SELECTED AND &Python%s=3" % version, 595 ordering=order) 596 c.event("SpawnWaitDialog", "WaitForCostingDlg", ordering=order + 1) 597 c.event("EndDialog", "Return", ordering=order + 2) 598 c = seldlg.cancel("Cancel", "Features") 522 599 c.event("SpawnDialog", "CancelDlg") 523 600 524 seldlg.control("DirectoryCombo", "DirectoryCombo", 15, 70, 272, 80, 393219, 525 "TARGETDIR", None, "DirectoryList", None) 526 seldlg.control("DirectoryList", "DirectoryList", 15, 90, 308, 136, 3, "TARGETDIR", 527 None, "PathEdit", None) 528 seldlg.control("PathEdit", "PathEdit", 15, 230, 306, 16, 3, "TARGETDIR", None, "Next", None) 529 c = seldlg.pushbutton("Up", 306, 70, 18, 18, 3, "Up", None) 530 c.event("DirectoryListUp", "0") 531 c = seldlg.pushbutton("NewDir", 324, 70, 30, 18, 3, "New", None) 532 c.event("DirectoryListNew", "0") 601 c = seldlg.control("Features", "SelectionTree", 15, 60, 300, 120, 3, 602 "FEATURE", None, "PathEdit", None) 603 c.event("[FEATURE_SELECTED]", "1") 604 ver = self.other_version 605 install_other_cond = "FEATURE_SELECTED AND &Python%s=3" % ver 606 dont_install_other_cond = "FEATURE_SELECTED AND &Python%s<>3" % ver 607 608 c = seldlg.text("Other", 15, 200, 300, 15, 3, 609 "Provide an alternate Python location") 610 c.condition("Enable", install_other_cond) 611 c.condition("Show", install_other_cond) 612 c.condition("Disable", dont_install_other_cond) 613 c.condition("Hide", dont_install_other_cond) 614 615 c = seldlg.control("PathEdit", "PathEdit", 15, 215, 300, 16, 1, 616 "TARGETDIR" + ver, None, "Next", None) 617 c.condition("Enable", install_other_cond) 618 c.condition("Show", install_other_cond) 619 c.condition("Disable", dont_install_other_cond) 620 c.condition("Hide", dont_install_other_cond) 533 621 534 622 ##################################################################### … … 646 734 def get_installer_filename(self, fullname): 647 735 # Factored out to allow overriding in subclasses 648 base_name = "%s.%s-py%s.msi" % (fullname, self.plat_name, 649 self.target_version) 736 if self.target_version: 737 base_name = "%s.%s-py%s.msi" % (fullname, self.plat_name, 738 self.target_version) 739 else: 740 base_name = "%s.%s.msi" % (fullname, self.plat_name) 650 741 installer_name = os.path.join(self.dist_dir, base_name) 651 742 return installer_name -
python/trunk/Lib/distutils/command/bdist_rpm.py
r10 r391 4 4 distributions).""" 5 5 6 # This module should be kept compatible with Python 2.1. 7 8 __revision__ = "$Id: bdist_rpm.py 61000 2008-02-23 17:40:11Z christian.heimes $" 9 10 import s ys, os, string11 from types import * 6 __revision__ = "$Id$" 7 8 import sys 9 import os 10 import string 11 12 12 from distutils.core import Command 13 13 from distutils.debug import DEBUG 14 from distutils.util import get_platform15 14 from distutils.file_util import write_file 16 from distutils.errors import *17 from distutils.sysconfig import get_python_version 15 from distutils.errors import (DistutilsOptionError, DistutilsPlatformError, 16 DistutilsFileError, DistutilsExecError) 18 17 from distutils import log 19 18 … … 126 125 ('force-arch=', None, 127 126 "Force an architecture onto the RPM build process"), 128 ] 127 128 ('quiet', 'q', 129 "Run the INSTALL phase of RPM building in quiet mode"), 130 ] 129 131 130 132 boolean_options = ['keep-temp', 'use-rpm-opt-flags', 'rpm3-mode', 131 'no-autoreq' ]133 'no-autoreq', 'quiet'] 132 134 133 135 negative_opt = {'no-keep-temp': 'keep-temp', … … 179 181 180 182 self.force_arch = None 183 self.quiet = 0 181 184 182 185 # initialize_options() … … 224 227 self.ensure_string('packager') 225 228 self.ensure_string_list('doc_files') 226 if type(self.doc_files) is ListType:229 if isinstance(self.doc_files, list): 227 230 for readme in ('README', 'README.txt'): 228 231 if os.path.exists(readme) and readme not in self.doc_files: … … 326 329 os.path.exists('/bin/rpmbuild'): 327 330 rpm_cmd = ['rpmbuild'] 331 328 332 if self.source_only: # what kind of RPMs? 329 333 rpm_cmd.append('-bs') … … 337 341 if not self.keep_temp: 338 342 rpm_cmd.append('--clean') 343 344 if self.quiet: 345 rpm_cmd.append('--quiet') 346 339 347 rpm_cmd.append(spec_path) 340 348 # Determine the binary rpm names that should be built out of this spec … … 351 359 352 360 out = os.popen(q_cmd) 353 binary_rpms = [] 354 source_rpm = None 355 while 1: 356 line = out.readline() 357 if not line: 358 break 359 l = string.split(string.strip(line)) 360 assert(len(l) == 2) 361 binary_rpms.append(l[1]) 362 # The source rpm is named after the first entry in the spec file 363 if source_rpm is None: 364 source_rpm = l[0] 365 366 status = out.close() 367 if status: 368 raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd)) 361 try: 362 binary_rpms = [] 363 source_rpm = None 364 while 1: 365 line = out.readline() 366 if not line: 367 break 368 l = string.split(string.strip(line)) 369 assert(len(l) == 2) 370 binary_rpms.append(l[1]) 371 # The source rpm is named after the first entry in the spec file 372 if source_rpm is None: 373 source_rpm = l[0] 374 375 status = out.close() 376 if status: 377 raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd)) 378 379 finally: 380 out.close() 369 381 370 382 self.spawn(rpm_cmd) 371 383 372 384 if not self.dry_run: 385 if self.distribution.has_ext_modules(): 386 pyversion = get_python_version() 387 else: 388 pyversion = 'any' 389 373 390 if not self.binary_only: 374 391 srpm = os.path.join(rpm_dir['SRPMS'], source_rpm) 375 392 assert(os.path.exists(srpm)) 376 393 self.move_file(srpm, self.dist_dir) 394 filename = os.path.join(self.dist_dir, source_rpm) 395 self.distribution.dist_files.append( 396 ('bdist_rpm', pyversion, filename)) 377 397 378 398 if not self.source_only: … … 381 401 if os.path.exists(rpm): 382 402 self.move_file(rpm, self.dist_dir) 403 filename = os.path.join(self.dist_dir, 404 os.path.basename(rpm)) 405 self.distribution.dist_files.append( 406 ('bdist_rpm', pyversion, filename)) 383 407 # run() 384 408 … … 441 465 ): 442 466 val = getattr(self, string.lower(field)) 443 if type(val) is ListType:467 if isinstance(val, list): 444 468 spec_file.append('%s: %s' % (field, string.join(val))) 445 469 elif val is not None: … … 492 516 # are just text that we drop in as-is. Hmmm. 493 517 518 install_cmd = ('%s install -O1 --root=$RPM_BUILD_ROOT ' 519 '--record=INSTALLED_FILES') % def_setup_call 520 494 521 script_options = [ 495 522 ('prep', 'prep_script', "%setup -n %{name}-%{unmangled_version}"), 496 523 ('build', 'build_script', def_build), 497 ('install', 'install_script', 498 ("%s install " 499 "--root=$RPM_BUILD_ROOT " 500 "--record=INSTALLED_FILES") % def_setup_call), 524 ('install', 'install_script', install_cmd), 501 525 ('clean', 'clean_script', "rm -rf $RPM_BUILD_ROOT"), 502 526 ('verifyscript', 'verify_script', None), -
python/trunk/Lib/distutils/command/bdist_wininst.py
r2 r391 4 4 exe-program.""" 5 5 6 # This module should be kept compatible with Python 2.1. 7 8 __revision__ = "$Id: bdist_wininst.py 71422 2009-04-09 22:48:19Z tarek.ziade $" 9 10 import sys, os, string 6 __revision__ = "$Id$" 7 8 import sys 9 import os 10 import string 11 12 from sysconfig import get_python_version 13 11 14 from distutils.core import Command 15 from distutils.dir_util import remove_tree 16 from distutils.errors import DistutilsOptionError, DistutilsPlatformError 17 from distutils import log 12 18 from distutils.util import get_platform 13 from distutils.dir_util import create_tree, remove_tree14 from distutils.errors import *15 from distutils.sysconfig import get_python_version16 from distutils import log17 19 18 20 class bdist_wininst (Command): … … 70 72 self.bitmap = None 71 73 self.title = None 72 self.skip_build = 074 self.skip_build = None 73 75 self.install_script = None 74 76 self.pre_install_script = None … … 79 81 80 82 def finalize_options (self): 83 self.set_undefined_options('bdist', ('skip_build', 'skip_build')) 84 81 85 if self.bdist_dir is None: 82 86 if self.skip_build and self.plat_name: … … 88 92 bdist_base = self.get_finalized_command('bdist').bdist_base 89 93 self.bdist_dir = os.path.join(bdist_base, 'wininst') 94 90 95 if not self.target_version: 91 96 self.target_version = "" 97 92 98 if not self.skip_build and self.distribution.has_ext_modules(): 93 99 short_version = get_python_version() 94 100 if self.target_version and self.target_version != short_version: 95 101 raise DistutilsOptionError, \ 96 "target version can only be %s, or the '--skip _build'" \102 "target version can only be %s, or the '--skip-build'" \ 97 103 " option must be specified" % (short_version,) 98 104 self.target_version = short_version … … 355 361 356 362 filename = os.path.join(directory, "wininst-%.1f%s.exe" % (bv, sfix)) 357 return open(filename, "rb").read() 363 f = open(filename, "rb") 364 try: 365 return f.read() 366 finally: 367 f.close() 358 368 # class bdist_wininst -
python/trunk/Lib/distutils/command/build.py
r2 r391 3 3 Implements the Distutils 'build' command.""" 4 4 5 # This module should be kept compatible with Python 2.1. 6 7 __revision__ = "$Id: build.py 62197 2008-04-07 01:53:39Z mark.hammond $" 5 __revision__ = "$Id$" 8 6 9 7 import sys, os 8 9 from distutils.util import get_platform 10 10 from distutils.core import Command 11 11 from distutils.errors import DistutilsOptionError 12 from distutils.util import get_platform13 12 14 15 def show_compilers (): 13 def show_compilers(): 16 14 from distutils.ccompiler import show_compilers 17 15 show_compilers() 18 16 19 20 class build (Command): 17 class build(Command): 21 18 22 19 description = "build everything needed to install" … … 56 53 ] 57 54 58 def initialize_options 55 def initialize_options(self): 59 56 self.build_base = 'build' 60 57 # these are decided only after 'build_base' has its final value … … 71 68 self.executable = None 72 69 73 def finalize_options (self): 74 70 def finalize_options(self): 75 71 if self.plat_name is None: 76 72 self.plat_name = get_platform() … … 121 117 if self.executable is None: 122 118 self.executable = os.path.normpath(sys.executable) 123 # finalize_options ()124 119 125 126 def run (self): 127 120 def run(self): 128 121 # Run all relevant sub-commands. This will be some subset of: 129 122 # - build_py - pure Python modules … … 133 126 for cmd_name in self.get_sub_commands(): 134 127 self.run_command(cmd_name) 135 136 128 137 129 # -- Predicates for the sub-command list --------------------------- … … 149 141 return self.distribution.has_scripts() 150 142 151 152 143 sub_commands = [('build_py', has_pure_modules), 153 144 ('build_clib', has_c_libraries), … … 155 146 ('build_scripts', has_scripts), 156 147 ] 157 158 # class build -
python/trunk/Lib/distutils/command/build_clib.py
r2 r391 5 5 module.""" 6 6 7 # This module should be kept compatible with Python 2.1. 8 9 __revision__ = "$Id: build_clib.py 37828 2004-11-10 22:23:15Z loewis $" 7 __revision__ = "$Id$" 10 8 11 9 … … 19 17 # cut 'n paste. Sigh. 20 18 21 import os, string 22 from types import * 19 import os 23 20 from distutils.core import Command 24 from distutils.errors import *21 from distutils.errors import DistutilsSetupError 25 22 from distutils.sysconfig import customize_compiler 26 23 from distutils import log 27 24 28 def show_compilers 25 def show_compilers(): 29 26 from distutils.ccompiler import show_compilers 30 27 show_compilers() 31 28 32 29 33 class build_clib 30 class build_clib(Command): 34 31 35 32 description = "build C/C++ libraries used by Python extensions" 36 33 37 34 user_options = [ 38 ('build-clib ', 'b',35 ('build-clib=', 'b', 39 36 "directory to build C/C++ libraries to"), 40 ('build-temp ', 't',37 ('build-temp=', 't', 41 38 "directory to put temporary build by-products"), 42 39 ('debug', 'g', … … 55 52 ] 56 53 57 def initialize_options 54 def initialize_options(self): 58 55 self.build_clib = None 59 56 self.build_temp = None … … 70 67 self.compiler = None 71 68 72 # initialize_options() 73 74 75 def finalize_options (self): 76 69 70 def finalize_options(self): 77 71 # This might be confusing: both build-clib and build-temp default 78 72 # to build-temp as defined by the "build" command. This is because … … 93 87 if self.include_dirs is None: 94 88 self.include_dirs = self.distribution.include_dirs or [] 95 if type(self.include_dirs) is StringType: 96 self.include_dirs = string.split(self.include_dirs, 97 os.pathsep) 89 if isinstance(self.include_dirs, str): 90 self.include_dirs = self.include_dirs.split(os.pathsep) 98 91 99 92 # XXX same as for build_ext -- what about 'self.define' and 100 93 # 'self.undef' ? 101 94 102 # finalize_options() 103 104 105 def run (self): 106 95 def run(self): 107 96 if not self.libraries: 108 97 return … … 127 116 self.build_libraries(self.libraries) 128 117 129 # run() 130 131 132 def check_library_list (self, libraries): 133 """Ensure that the list of libraries (presumably provided as a 134 command option 'libraries') is valid, i.e. it is a list of 135 2-tuples, where the tuples are (library_name, build_info_dict). 136 Raise DistutilsSetupError if the structure is invalid anywhere; 137 just returns otherwise.""" 138 139 # Yechh, blecch, ackk: this is ripped straight out of build_ext.py, 140 # with only names changed to protect the innocent! 141 142 if type(libraries) is not ListType: 118 119 def check_library_list(self, libraries): 120 """Ensure that the list of libraries is valid. 121 122 `library` is presumably provided as a command option 'libraries'. 123 This method checks that it is a list of 2-tuples, where the tuples 124 are (library_name, build_info_dict). 125 126 Raise DistutilsSetupError if the structure is invalid anywhere; 127 just returns otherwise. 128 """ 129 if not isinstance(libraries, list): 143 130 raise DistutilsSetupError, \ 144 131 "'libraries' option must be a list of tuples" 145 132 146 133 for lib in libraries: 147 if type(lib) is not TupleTypeand len(lib) != 2:134 if not isinstance(lib, tuple) and len(lib) != 2: 148 135 raise DistutilsSetupError, \ 149 136 "each element of 'libraries' must a 2-tuple" 150 137 151 if type(lib[0]) is not StringType: 138 name, build_info = lib 139 140 if not isinstance(name, str): 152 141 raise DistutilsSetupError, \ 153 142 "first element of each tuple in 'libraries' " + \ 154 143 "must be a string (the library name)" 155 if '/' in lib[0] or (os.sep != '/' and os.sep in lib[0]):144 if '/' in name or (os.sep != '/' and os.sep in name): 156 145 raise DistutilsSetupError, \ 157 146 ("bad library name '%s': " + … … 159 148 lib[0] 160 149 161 if type(lib[1]) is not DictionaryType:150 if not isinstance(build_info, dict): 162 151 raise DistutilsSetupError, \ 163 152 "second element of each tuple in 'libraries' " + \ 164 153 "must be a dictionary (build info)" 165 # for lib 166 167 # check_library_list () 168 169 170 def get_library_names (self): 154 155 def get_library_names(self): 171 156 # Assume the library list is valid -- 'check_library_list()' is 172 157 # called from 'finalize_options()', so it should be! 173 174 158 if not self.libraries: 175 159 return None … … 180 164 return lib_names 181 165 182 # get_library_names () 183 184 185 def get_source_files (self): 166 167 def get_source_files(self): 186 168 self.check_library_list(self.libraries) 187 169 filenames = [] 188 170 for (lib_name, build_info) in self.libraries: 189 171 sources = build_info.get('sources') 190 if (sources is None or 191 type(sources) not in (ListType, TupleType) ): 172 if sources is None or not isinstance(sources, (list, tuple)): 192 173 raise DistutilsSetupError, \ 193 174 ("in 'libraries' option (library '%s'), " … … 196 177 197 178 filenames.extend(sources) 198 199 179 return filenames 200 # get_source_files () 201 202 203 def build_libraries (self, libraries): 204 180 181 def build_libraries(self, libraries): 205 182 for (lib_name, build_info) in libraries: 206 183 sources = build_info.get('sources') 207 if sources is None or type(sources) not in (ListType, TupleType):184 if sources is None or not isinstance(sources, (list, tuple)): 208 185 raise DistutilsSetupError, \ 209 186 ("in 'libraries' option (library '%s'), " + … … 231 208 output_dir=self.build_clib, 232 209 debug=self.debug) 233 234 # for libraries235 236 # build_libraries ()237 238 # class build_lib -
python/trunk/Lib/distutils/command/build_ext.py
r2 r391 7 7 # This module should be kept compatible with Python 2.1. 8 8 9 __revision__ = "$Id : build_ext.py 75395 2009-10-13 21:17:34Z tarek.ziade$"9 __revision__ = "$Id$" 10 10 11 11 import sys, os, string, re … … 161 161 self.include_dirs.append(plat_py_include) 162 162 163 if isinstance(self.libraries, str): 164 self.libraries = [self.libraries] 163 self.ensure_string_list('libraries') 165 164 166 165 # Life is easier if we're not forever checking for None, so … … 208 207 elif MSVC_VERSION == 8: 209 208 self.library_dirs.append(os.path.join(sys.exec_prefix, 210 'PC', 'VS8.0' , 'win32release'))209 'PC', 'VS8.0')) 211 210 elif MSVC_VERSION == 7: 212 211 self.library_dirs.append(os.path.join(sys.exec_prefix, … … 233 232 self.library_dirs.append('.') 234 233 235 # for extensions under Linux or Solaris with a shared Python library,234 # For building extensions with a shared Python library, 236 235 # Python's library directory must be appended to library_dirs 237 sysconfig.get_config_var('Py_ENABLE_SHARED') 238 if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu') 239 or sys.platform.startswith('sunos')) 240 and sysconfig.get_config_var('Py_ENABLE_SHARED')): 236 # See Issues: #1600860, #4366 237 if (sysconfig.get_config_var('Py_ENABLE_SHARED')): 241 238 if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): 242 239 # building third party extensions … … 677 674 so_ext = get_config_var('SO') 678 675 if os.name == 'nt' and self.debug: 679 return apply(os.path.join,ext_path) + '_d' + so_ext676 return os.path.join(*ext_path) + '_d' + so_ext 680 677 return os.path.join(*ext_path) + so_ext 681 678 … … 754 751 # Don't use the default code below 755 752 return ext.libraries 756 753 elif sys.platform[:3] == 'aix': 754 # Don't use the default code below 755 return ext.libraries 757 756 else: 758 757 from distutils import sysconfig -
python/trunk/Lib/distutils/command/build_py.py
r2 r391 3 3 Implements the Distutils 'build_py' command.""" 4 4 5 # This module should be kept compatible with Python 2.1. 6 7 __revision__ = "$Id: build_py.py 77376 2010-01-08 23:27:23Z tarek.ziade $" 8 9 import string, os 10 from types import * 5 __revision__ = "$Id$" 6 7 import os 11 8 import sys 12 9 from glob import glob 13 10 14 11 from distutils.core import Command 15 from distutils.errors import *12 from distutils.errors import DistutilsOptionError, DistutilsFileError 16 13 from distutils.util import convert_path 17 14 from distutils import log 18 15 19 class build_py 16 class build_py(Command): 20 17 21 18 description = "\"build\" pure Python modules (copy to build directory)" … … 34 31 negative_opt = {'no-compile' : 'compile'} 35 32 36 37 def initialize_options (self): 33 def initialize_options(self): 38 34 self.build_lib = None 39 35 self.py_modules = None … … 45 41 self.force = None 46 42 47 def finalize_options 43 def finalize_options(self): 48 44 self.set_undefined_options('build', 49 45 ('build_lib', 'build_lib'), … … 63 59 # Ick, copied straight from install_lib.py (fancy_getopt needs a 64 60 # type system! Hell, *everything* needs a type system!!!) 65 if type(self.optimize) is not IntType:61 if not isinstance(self.optimize, int): 66 62 try: 67 63 self.optimize = int(self.optimize) 68 64 assert 0 <= self.optimize <= 2 69 65 except (ValueError, AssertionError): 70 raise DistutilsOptionError, "optimize must be 0, 1, or 2" 71 72 def run (self): 73 66 raise DistutilsOptionError("optimize must be 0, 1, or 2") 67 68 def run(self): 74 69 # XXX copy_file by default preserves atime and mtime. IMHO this is 75 70 # the right thing to do, but perhaps it should be an option -- in … … 101 96 self.byte_compile(self.get_outputs(include_bytecode=0)) 102 97 103 # run () 104 105 def get_data_files (self): 98 def get_data_files(self): 106 99 """Generate list of '(package,src_dir,build_dir,filenames)' tuples""" 107 100 data = [] … … 127 120 return data 128 121 129 def find_data_files 122 def find_data_files(self, package, src_dir): 130 123 """Return filenames for package's data files in 'src_dir'""" 131 124 globs = (self.package_data.get('', []) … … 139 132 return files 140 133 141 def build_package_data 134 def build_package_data(self): 142 135 """Copy data files into build directory""" 143 lastdir = None144 136 for package, src_dir, build_dir, filenames in self.data_files: 145 137 for filename in filenames: … … 149 141 preserve_mode=False) 150 142 151 def get_package_dir 143 def get_package_dir(self, package): 152 144 """Return the directory, relative to the top of the source 153 145 distribution, where package 'package' should be found 154 146 (at least according to the 'package_dir' option, if any).""" 155 147 156 path = string.split(package,'.')148 path = package.split('.') 157 149 158 150 if not self.package_dir: 159 151 if path: 160 return apply(os.path.join,path)152 return os.path.join(*path) 161 153 else: 162 154 return '' … … 165 157 while path: 166 158 try: 167 pdir = self.package_dir[ string.join(path, '.')]159 pdir = self.package_dir['.'.join(path)] 168 160 except KeyError: 169 161 tail.insert(0, path[-1]) … … 185 177 186 178 if tail: 187 return apply(os.path.join,tail)179 return os.path.join(*tail) 188 180 else: 189 181 return '' 190 182 191 # get_package_dir () 192 193 194 def check_package (self, package, package_dir): 195 183 def check_package(self, package, package_dir): 196 184 # Empty dir name means current directory, which we can probably 197 185 # assume exists. Also, os.path.exists and isdir don't know about … … 200 188 if package_dir != "": 201 189 if not os.path.exists(package_dir): 202 raise DistutilsFileError , \203 "package directory '%s' does not exist" % package_dir 190 raise DistutilsFileError( 191 "package directory '%s' does not exist" % package_dir) 204 192 if not os.path.isdir(package_dir): 205 raise DistutilsFileError , \206 ("supposed package directory '%s' exists, " +207 "but is not a directory" ) % package_dir193 raise DistutilsFileError( 194 "supposed package directory '%s' exists, " 195 "but is not a directory" % package_dir) 208 196 209 197 # Require __init__.py for all but the "root package" … … 220 208 return None 221 209 222 # check_package () 223 224 225 def check_module (self, module, module_file): 210 def check_module(self, module, module_file): 226 211 if not os.path.isfile(module_file): 227 212 log.warn("file %s (for module %s) not found", module_file, module) 228 return 0213 return False 229 214 else: 230 return 1 231 232 # check_module () 233 234 235 def find_package_modules (self, package, package_dir): 215 return True 216 217 def find_package_modules(self, package, package_dir): 236 218 self.check_package(package, package_dir) 237 219 module_files = glob(os.path.join(package_dir, "*.py")) … … 248 230 return modules 249 231 250 251 def find_modules (self): 232 def find_modules(self): 252 233 """Finds individually-specified Python modules, ie. those listed by 253 234 module name in 'self.py_modules'. Returns a list of tuples (package, … … 258 239 module. 259 240 """ 260 261 241 # Map package names to tuples of useful info about the package: 262 242 # (package_dir, checked) … … 274 254 # string or empty list, depending on context). Differences: 275 255 # - don't check for __init__.py in directory for empty package 276 277 256 for module in self.py_modules: 278 path = string.split(module,'.')279 package = string.join(path[0:-1], '.')257 path = module.split('.') 258 package = '.'.join(path[0:-1]) 280 259 module_base = path[-1] 281 260 … … 303 282 return modules 304 283 305 # find_modules () 306 307 308 def find_all_modules (self): 284 def find_all_modules(self): 309 285 """Compute the list of all modules that will be built, whether 310 286 they are specified one-module-at-a-time ('self.py_modules') or … … 312 288 (package, module, module_file), just like 'find_modules()' and 313 289 'find_package_modules()' do.""" 314 315 290 modules = [] 316 291 if self.py_modules: … … 321 296 m = self.find_package_modules(package, package_dir) 322 297 modules.extend(m) 323 324 298 return modules 325 299 326 # find_all_modules () 327 328 329 def get_source_files (self): 330 331 modules = self.find_all_modules() 332 filenames = [] 333 for module in modules: 334 filenames.append(module[-1]) 335 336 return filenames 337 338 339 def get_module_outfile (self, build_dir, package, module): 300 def get_source_files(self): 301 return [module[-1] for module in self.find_all_modules()] 302 303 def get_module_outfile(self, build_dir, package, module): 340 304 outfile_path = [build_dir] + list(package) + [module + ".py"] 341 305 return os.path.join(*outfile_path) 342 306 343 344 def get_outputs (self, include_bytecode=1): 307 def get_outputs(self, include_bytecode=1): 345 308 modules = self.find_all_modules() 346 309 outputs = [] 347 310 for (package, module, module_file) in modules: 348 package = string.split(package,'.')311 package = package.split('.') 349 312 filename = self.get_module_outfile(self.build_lib, package, module) 350 313 outputs.append(filename) … … 363 326 return outputs 364 327 365 366 def build_module (self, module, module_file, package): 367 if type(package) is StringType: 368 package = string.split(package, '.') 369 elif type(package) not in (ListType, TupleType): 370 raise TypeError, \ 371 "'package' must be a string (dot-separated), list, or tuple" 328 def build_module(self, module, module_file, package): 329 if isinstance(package, str): 330 package = package.split('.') 331 elif not isinstance(package, (list, tuple)): 332 raise TypeError( 333 "'package' must be a string (dot-separated), list, or tuple") 372 334 373 335 # Now put the module source file into the "build" area -- this is … … 379 341 return self.copy_file(module_file, outfile, preserve_mode=0) 380 342 381 382 def build_modules (self): 383 343 def build_modules(self): 384 344 modules = self.find_modules() 385 345 for (package, module, module_file) in modules: … … 391 351 self.build_module(module, module_file, package) 392 352 393 # build_modules () 394 395 396 def build_packages (self): 397 353 def build_packages(self): 398 354 for package in self.packages: 399 355 … … 416 372 self.build_module(module, module_file, package) 417 373 418 # build_packages () 419 420 421 def byte_compile (self, files): 374 def byte_compile(self, files): 422 375 if sys.dont_write_bytecode: 423 376 self.warn('byte-compiling is disabled, skipping.') … … 439 392 byte_compile(files, optimize=self.optimize, 440 393 force=self.force, prefix=prefix, dry_run=self.dry_run) 441 442 # class build_py -
python/trunk/Lib/distutils/command/build_scripts.py
r2 r391 3 3 Implements the Distutils 'build_scripts' command.""" 4 4 5 # This module should be kept compatible with Python 2.1. 6 7 __revision__ = "$Id: build_scripts.py 69599 2009-02-13 23:02:44Z tarek.ziade $" 5 __revision__ = "$Id$" 8 6 9 7 import os, re 10 8 from stat import ST_MODE 11 from distutils import sysconfig12 9 from distutils.core import Command 13 10 from distutils.dep_util import newer … … 60 57 line to refer to the current Python interpreter as we copy. 61 58 """ 59 _sysconfig = __import__('sysconfig') 62 60 self.mkpath(self.build_dir) 63 61 outfiles = [] … … 97 95 if not self.dry_run: 98 96 outf = open(outfile, "w") 99 if not sysconfig.python_build:97 if not _sysconfig.is_python_build(): 100 98 outf.write("#!%s%s\n" % 101 99 (self.executable, … … 104 102 outf.write("#!%s%s\n" % 105 103 (os.path.join( 106 sysconfig.get_config_var("BINDIR"),107 "python%s%s" % ( sysconfig.get_config_var("VERSION"),108 sysconfig.get_config_var("EXE"))),104 _sysconfig.get_config_var("BINDIR"), 105 "python%s%s" % (_sysconfig.get_config_var("VERSION"), 106 _sysconfig.get_config_var("EXE"))), 109 107 post_interp)) 110 108 outf.writelines(f.readlines()) -
python/trunk/Lib/distutils/command/clean.py
r2 r391 5 5 # contributed by Bastian Kleineidam <calvin@cs.uni-sb.de>, added 2000-03-18 6 6 7 # This module should be kept compatible with Python 2.1. 8 9 __revision__ = "$Id: clean.py 38532 2005-03-03 08:12:27Z loewis $" 7 __revision__ = "$Id$" 10 8 11 9 import os … … 14 12 from distutils import log 15 13 16 class clean 14 class clean(Command): 17 15 18 16 description = "clean up temporary files from 'build' command" -
python/trunk/Lib/distutils/command/config.py
r2 r391 10 10 """ 11 11 12 # This module should be kept compatible with Python 2.1. 13 14 __revision__ = "$Id: config.py 37828 2004-11-10 22:23:15Z loewis $" 15 16 import sys, os, string, re 17 from types import * 12 __revision__ = "$Id$" 13 14 import os 15 import re 16 18 17 from distutils.core import Command 19 18 from distutils.errors import DistutilsExecError … … 21 20 from distutils import log 22 21 23 LANG_EXT = {'c': '.c', 24 'c++': '.cxx'} 25 26 class config (Command): 22 LANG_EXT = {'c': '.c', 'c++': '.cxx'} 23 24 class config(Command): 27 25 28 26 description = "prepare to build" … … 54 52 # does nothing by default, these are empty. 55 53 56 def initialize_options 54 def initialize_options(self): 57 55 self.compiler = None 58 56 self.cc = None 59 57 self.include_dirs = None 60 #self.define = None61 #self.undef = None62 58 self.libraries = None 63 59 self.library_dirs = None … … 71 67 self.temp_files = [] 72 68 73 def finalize_options 69 def finalize_options(self): 74 70 if self.include_dirs is None: 75 71 self.include_dirs = self.distribution.include_dirs or [] 76 elif type(self.include_dirs) is StringType:77 self.include_dirs = s tring.split(self.include_dirs,os.pathsep)72 elif isinstance(self.include_dirs, str): 73 self.include_dirs = self.include_dirs.split(os.pathsep) 78 74 79 75 if self.libraries is None: 80 76 self.libraries = [] 81 elif type(self.libraries) is StringType:77 elif isinstance(self.libraries, str): 82 78 self.libraries = [self.libraries] 83 79 84 80 if self.library_dirs is None: 85 81 self.library_dirs = [] 86 elif type(self.library_dirs) is StringType: 87 self.library_dirs = string.split(self.library_dirs, os.pathsep) 88 89 90 def run (self): 82 elif isinstance(self.library_dirs, str): 83 self.library_dirs = self.library_dirs.split(os.pathsep) 84 85 def run(self): 91 86 pass 92 87 … … 96 91 # may use these freely. 97 92 98 def _check_compiler 93 def _check_compiler(self): 99 94 """Check that 'self.compiler' really is a CCompiler object; 100 95 if not, make it one. … … 115 110 116 111 117 def _gen_temp_sourcefile 112 def _gen_temp_sourcefile(self, body, headers, lang): 118 113 filename = "_configtest" + LANG_EXT[lang] 119 114 file = open(filename, "w") … … 128 123 return filename 129 124 130 def _preprocess 125 def _preprocess(self, body, headers, include_dirs, lang): 131 126 src = self._gen_temp_sourcefile(body, headers, lang) 132 127 out = "_configtest.i" … … 135 130 return (src, out) 136 131 137 def _compile 132 def _compile(self, body, headers, include_dirs, lang): 138 133 src = self._gen_temp_sourcefile(body, headers, lang) 139 134 if self.dump_source: … … 144 139 return (src, obj) 145 140 146 def _link (self, body, 147 headers, include_dirs, 148 libraries, library_dirs, lang): 141 def _link(self, body, headers, include_dirs, libraries, library_dirs, 142 lang): 149 143 (src, obj) = self._compile(body, headers, include_dirs, lang) 150 144 prog = os.path.splitext(os.path.basename(src))[0] … … 160 154 return (src, obj, prog) 161 155 162 def _clean 156 def _clean(self, *filenames): 163 157 if not filenames: 164 158 filenames = self.temp_files 165 159 self.temp_files = [] 166 log.info("removing: %s", string.join(filenames))160 log.info("removing: %s", ' '.join(filenames)) 167 161 for filename in filenames: 168 162 try: … … 182 176 # XXX need access to the header search path and maybe default macros. 183 177 184 def try_cpp 178 def try_cpp(self, body=None, headers=None, include_dirs=None, lang="c"): 185 179 """Construct a source file from 'body' (a string containing lines 186 180 of C/C++ code) and 'headers' (a list of header files to include) … … 200 194 return ok 201 195 202 def search_cpp (self, pattern, body=None,203 headers=None, include_dirs=None,lang="c"):196 def search_cpp(self, pattern, body=None, headers=None, include_dirs=None, 197 lang="c"): 204 198 """Construct a source file (just like 'try_cpp()'), run it through 205 199 the preprocessor, and return true if any line of the output matches … … 209 203 symbols the preprocessor and compiler set by default. 210 204 """ 211 212 self._check_compiler() 213 (src, out) = self._preprocess(body, headers, include_dirs, lang) 214 215 if type(pattern) is StringType: 205 self._check_compiler() 206 src, out = self._preprocess(body, headers, include_dirs, lang) 207 208 if isinstance(pattern, str): 216 209 pattern = re.compile(pattern) 217 210 … … 230 223 return match 231 224 232 def try_compile 225 def try_compile(self, body, headers=None, include_dirs=None, lang="c"): 233 226 """Try to compile a source file built from 'body' and 'headers'. 234 227 Return true on success, false otherwise. … … 246 239 return ok 247 240 248 def try_link (self, body, 249 headers=None, include_dirs=None, 250 libraries=None, library_dirs=None, 251 lang="c"): 241 def try_link(self, body, headers=None, include_dirs=None, libraries=None, 242 library_dirs=None, lang="c"): 252 243 """Try to compile and link a source file, built from 'body' and 253 244 'headers', to executable form. Return true on success, false … … 267 258 return ok 268 259 269 def try_run (self, body, 270 headers=None, include_dirs=None, 271 libraries=None, library_dirs=None, 272 lang="c"): 260 def try_run(self, body, headers=None, include_dirs=None, libraries=None, 261 library_dirs=None, lang="c"): 273 262 """Try to compile, link to an executable, and run a program 274 263 built from 'body' and 'headers'. Return true on success, false … … 294 283 # when implementing a real-world config command!) 295 284 296 def check_func (self, func, 297 headers=None, include_dirs=None, 298 libraries=None, library_dirs=None, 299 decl=0, call=0): 285 def check_func(self, func, headers=None, include_dirs=None, 286 libraries=None, library_dirs=None, decl=0, call=0): 300 287 301 288 """Determine if function 'func' is available by constructing a … … 323 310 body.append(" %s;" % func) 324 311 body.append("}") 325 body = string.join(body, "\n") + "\n"312 body = "\n".join(body) + "\n" 326 313 327 314 return self.try_link(body, headers, include_dirs, … … 330 317 # check_func () 331 318 332 def check_lib (self, library, library_dirs=None,333 headers=None,include_dirs=None, other_libraries=[]):319 def check_lib(self, library, library_dirs=None, headers=None, 320 include_dirs=None, other_libraries=[]): 334 321 """Determine if 'library' is available to be linked against, 335 322 without actually checking that any particular symbols are provided … … 345 332 [library]+other_libraries, library_dirs) 346 333 347 def check_header (self, header, include_dirs=None,348 library_dirs=None,lang="c"):334 def check_header(self, header, include_dirs=None, library_dirs=None, 335 lang="c"): 349 336 """Determine if the system header file named by 'header_file' 350 337 exists and can be found by the preprocessor; return true if so, … … 355 342 356 343 357 # class config 358 359 360 def dump_file (filename, head=None): 344 def dump_file(filename, head=None): 345 """Dumps a file content into log.info. 346 347 If head is not None, will be dumped before the file content. 348 """ 361 349 if head is None: 362 print filename + ":"350 log.info('%s' % filename) 363 351 else: 364 print head 365 352 log.info(head) 366 353 file = open(filename) 367 sys.stdout.write(file.read()) 368 file.close() 354 try: 355 log.info(file.read()) 356 finally: 357 file.close() -
python/trunk/Lib/distutils/command/install.py
r10 r391 7 7 # This module should be kept compatible with Python 2.1. 8 8 9 __revision__ = "$Id : install.py 62788 2008-05-06 22:41:46Z christian.heimes$"9 __revision__ = "$Id$" 10 10 11 11 import sys, os, string … … 70 70 'data' : '$userbase', 71 71 }, 72 'mac': {73 'purelib': '$base/Lib/site-packages',74 'platlib': '$base/Lib/site-packages',75 'headers': '$base/Include/$dist_name',76 'scripts': '$base/Scripts',77 'data' : '$base',78 },79 'mac_user': {80 'purelib': '$usersite',81 'platlib': '$usersite',82 'headers': '$userbase/$py_version_short/include/$dist_name',83 'scripts': '$userbase/bin',84 'data' : '$userbase',85 },86 72 'os2': { 87 73 'purelib': '$base/Lib/site-packages', … … 280 266 if self.user and (self.prefix or self.exec_prefix or self.home or 281 267 self.install_base or self.install_platbase): 282 raise DistutilsOptionError("can't combine user with with prefix/"283 "exec_prefix/home or install_(plat)base")268 raise DistutilsOptionError("can't combine user with prefix, " 269 "exec_prefix/home, or install_(plat)base") 284 270 285 271 # Next, stuff that's wrong (or dubious) only on certain platforms. -
python/trunk/Lib/distutils/command/install_data.py
r2 r391 6 6 # contributed by Bastian Kleineidam 7 7 8 # This module should be kept compatible with Python 2.1. 9 10 __revision__ = "$Id: install_data.py 37828 2004-11-10 22:23:15Z loewis $" 8 __revision__ = "$Id$" 11 9 12 10 import os 13 from types import StringType14 11 from distutils.core import Command 15 12 from distutils.util import change_root, convert_path 16 13 17 class install_data 14 class install_data(Command): 18 15 19 16 description = "install data files" … … 30 27 boolean_options = ['force'] 31 28 32 def initialize_options 29 def initialize_options(self): 33 30 self.install_dir = None 34 31 self.outfiles = [] 35 32 self.root = None 36 33 self.force = 0 37 38 34 self.data_files = self.distribution.data_files 39 35 self.warn_dir = 1 40 36 41 def finalize_options 37 def finalize_options(self): 42 38 self.set_undefined_options('install', 43 39 ('install_data', 'install_dir'), … … 46 42 ) 47 43 48 def run 44 def run(self): 49 45 self.mkpath(self.install_dir) 50 46 for f in self.data_files: 51 if type(f) is StringType:47 if isinstance(f, str): 52 48 # it's a simple file, so copy it 53 49 f = convert_path(f) … … 79 75 self.outfiles.append(out) 80 76 81 def get_inputs 77 def get_inputs(self): 82 78 return self.data_files or [] 83 79 84 def get_outputs 80 def get_outputs(self): 85 81 return self.outfiles -
python/trunk/Lib/distutils/command/install_headers.py
r2 r391 4 4 files to the Python include directory.""" 5 5 6 # This module should be kept compatible with Python 2.1. 7 8 __revision__ = "$Id: install_headers.py 61000 2008-02-23 17:40:11Z christian.heimes $" 6 __revision__ = "$Id$" 9 7 10 8 from distutils.core import Command 11 9 12 10 13 class install_headers (Command): 11 # XXX force is never used 12 class install_headers(Command): 14 13 15 14 description = "install C/C++ header files" … … 23 22 boolean_options = ['force'] 24 23 25 def initialize_options 24 def initialize_options(self): 26 25 self.install_dir = None 27 26 self.force = 0 28 27 self.outfiles = [] 29 28 30 def finalize_options 29 def finalize_options(self): 31 30 self.set_undefined_options('install', 32 31 ('install_headers', 'install_dir'), … … 34 33 35 34 36 def run 35 def run(self): 37 36 headers = self.distribution.headers 38 37 if not headers: … … 44 43 self.outfiles.append(out) 45 44 46 def get_inputs 45 def get_inputs(self): 47 46 return self.distribution.headers or [] 48 47 49 def get_outputs 48 def get_outputs(self): 50 49 return self.outfiles 51 50 -
python/trunk/Lib/distutils/command/install_lib.py
r2 r391 1 # This module should be kept compatible with Python 2.1. 2 3 __revision__ = "$Id: install_lib.py 77376 2010-01-08 23:27:23Z tarek.ziade $" 1 """distutils.command.install_lib 2 3 Implements the Distutils 'install_lib' command 4 (install all Python modules).""" 5 6 __revision__ = "$Id$" 4 7 5 8 import os 6 from types import IntType7 9 import sys 8 10 … … 17 19 PYTHON_SOURCE_EXTENSION = ".py" 18 20 19 class install_lib 21 class install_lib(Command): 20 22 21 23 description = "install all Python modules (extensions and pure Python)" … … 51 53 negative_opt = {'no-compile' : 'compile'} 52 54 53 54 def initialize_options (self): 55 def initialize_options(self): 55 56 # let the 'install' command dictate our installation directory 56 57 self.install_dir = None … … 61 62 self.skip_build = None 62 63 63 def finalize_options (self): 64 64 def finalize_options(self): 65 65 # Get all the information we need to install pure Python modules 66 66 # from the umbrella 'install' command -- build (source) directory, … … 80 80 self.optimize = 0 81 81 82 if type(self.optimize) is not IntType:82 if not isinstance(self.optimize, int): 83 83 try: 84 84 self.optimize = int(self.optimize) … … 88 88 raise DistutilsOptionError, "optimize must be 0, 1, or 2" 89 89 90 def run (self): 91 90 def run(self): 92 91 # Make sure we have built everything we need first 93 92 self.build() … … 102 101 self.byte_compile(outfiles) 103 102 104 # run ()105 106 107 103 # -- Top-level worker functions ------------------------------------ 108 104 # (called from 'run()') 109 105 110 def build 106 def build(self): 111 107 if not self.skip_build: 112 108 if self.distribution.has_pure_modules(): … … 115 111 self.run_command('build_ext') 116 112 117 def install 113 def install(self): 118 114 if os.path.isdir(self.build_dir): 119 115 outfiles = self.copy_tree(self.build_dir, self.install_dir) … … 124 120 return outfiles 125 121 126 def byte_compile 122 def byte_compile(self, files): 127 123 if sys.dont_write_bytecode: 128 124 self.warn('byte-compiling is disabled, skipping.') … … 149 145 # -- Utility methods ----------------------------------------------- 150 146 151 def _mutate_outputs (self, has_any, build_cmd, cmd_option, output_dir): 152 147 def _mutate_outputs(self, has_any, build_cmd, cmd_option, output_dir): 153 148 if not has_any: 154 149 return [] … … 165 160 return outputs 166 161 167 # _mutate_outputs () 168 169 def _bytecode_filenames (self, py_filenames): 162 def _bytecode_filenames(self, py_filenames): 170 163 bytecode_files = [] 171 164 for py_file in py_filenames: … … 187 180 # (called by outsiders) 188 181 189 def get_outputs 182 def get_outputs(self): 190 183 """Return the list of files that would be installed if this command 191 184 were actually run. Not affected by the "dry-run" flag or whether … … 208 201 return pure_outputs + bytecode_outputs + ext_outputs 209 202 210 # get_outputs () 211 212 def get_inputs (self): 203 def get_inputs(self): 213 204 """Get the list of files that are input to this command, ie. the 214 205 files that get installed as they are named in the build tree. … … 227 218 228 219 return inputs 229 230 # class install_lib -
python/trunk/Lib/distutils/command/install_scripts.py
r2 r391 6 6 # contributed by Bastian Kleineidam 7 7 8 # This module should be kept compatible with Python 2.1. 9 10 __revision__ = "$Id: install_scripts.py 37828 2004-11-10 22:23:15Z loewis $" 8 __revision__ = "$Id$" 11 9 12 10 import os -
python/trunk/Lib/distutils/command/register.py
r2 r391 6 6 # created 2002/10/21, Richard Jones 7 7 8 __revision__ = "$Id: register.py 77719 2010-01-24 00:57:20Z tarek.ziade $" 9 10 import os, string, urllib2, getpass, urlparse 11 import StringIO 8 __revision__ = "$Id$" 9 10 import urllib2 11 import getpass 12 import urlparse 13 from warnings import warn 12 14 13 15 from distutils.core import PyPIRCCommand 14 from distutils.errors import *15 16 from distutils import log 16 17 … … 21 22 ('list-classifiers', None, 22 23 'list the valid Trove classifiers'), 24 ('strict', None , 25 'Will stop the registering if the meta-data are not fully compliant') 23 26 ] 24 27 boolean_options = PyPIRCCommand.boolean_options + [ 25 'verify', 'list-classifiers'] 28 'verify', 'list-classifiers', 'strict'] 29 30 sub_commands = [('check', lambda self: True)] 26 31 27 32 def initialize_options(self): 28 33 PyPIRCCommand.initialize_options(self) 29 34 self.list_classifiers = 0 35 self.strict = 0 36 37 def finalize_options(self): 38 PyPIRCCommand.finalize_options(self) 39 # setting options for the `check` subcommand 40 check_options = {'strict': ('register', self.strict), 41 'restructuredtext': ('register', 1)} 42 self.distribution.command_options['check'] = check_options 30 43 31 44 def run(self): 32 45 self.finalize_options() 33 46 self._set_config() 34 self.check_metadata() 47 48 # Run sub commands 49 for cmd_name in self.get_sub_commands(): 50 self.run_command(cmd_name) 51 35 52 if self.dry_run: 36 53 self.verify_metadata() … … 41 58 42 59 def check_metadata(self): 43 """Ensure that all required elements of meta-data (name, version, 44 URL, (author and author_email) or (maintainer and 45 maintainer_email)) are supplied by the Distribution object; warn if 46 any are missing. 47 """ 48 metadata = self.distribution.metadata 49 50 missing = [] 51 for attr in ('name', 'version', 'url'): 52 if not (hasattr(metadata, attr) and getattr(metadata, attr)): 53 missing.append(attr) 54 55 if missing: 56 self.warn("missing required meta-data: " + 57 string.join(missing, ", ")) 58 59 if metadata.author: 60 if not metadata.author_email: 61 self.warn("missing meta-data: if 'author' supplied, " + 62 "'author_email' must be supplied too") 63 elif metadata.maintainer: 64 if not metadata.maintainer_email: 65 self.warn("missing meta-data: if 'maintainer' supplied, " + 66 "'maintainer_email' must be supplied too") 67 else: 68 self.warn("missing meta-data: either (author and author_email) " + 69 "or (maintainer and maintainer_email) " + 70 "must be supplied") 60 """Deprecated API.""" 61 warn("distutils.command.register.check_metadata is deprecated, \ 62 use the check command instead", PendingDeprecationWarning) 63 check = self.distribution.get_command_obj('check') 64 check.ensure_finalized() 65 check.strict = self.strict 66 check.restructuredtext = 1 67 check.run() 71 68 72 69 def _set_config(self): … … 91 88 ''' 92 89 response = urllib2.urlopen(self.repository+'?:action=list_classifiers') 93 print response.read()90 log.info(response.read()) 94 91 95 92 def verify_metadata(self): … … 98 95 # send the info to the server and report the result 99 96 (code, result) = self.post_to_server(self.build_post_data('verify')) 100 print 'Server response (%s): %s'%(code, result)97 log.info('Server response (%s): %s' % (code, result)) 101 98 102 99 … … 174 171 175 172 # possibly save the login 176 if not self.has_config and code == 200: 177 self.announce(('I can store your PyPI login so future ' 178 'submissions will be faster.'), log.INFO) 179 self.announce('(the login will be stored in %s)' % \ 180 self._get_rc_file(), log.INFO) 181 182 choice = 'X' 183 while choice.lower() not in 'yn': 184 choice = raw_input('Save your login (y/N)?') 185 if not choice: 186 choice = 'n' 187 if choice.lower() == 'y': 188 self._store_pypirc(username, password) 173 if code == 200: 174 if self.has_config: 175 # sharing the password in the distribution instance 176 # so the upload command can reuse it 177 self.distribution.password = password 178 else: 179 self.announce(('I can store your PyPI login so future ' 180 'submissions will be faster.'), log.INFO) 181 self.announce('(the login will be stored in %s)' % \ 182 self._get_rc_file(), log.INFO) 183 choice = 'X' 184 while choice.lower() not in 'yn': 185 choice = raw_input('Save your login (y/N)?') 186 if not choice: 187 choice = 'n' 188 if choice.lower() == 'y': 189 self._store_pypirc(username, password) 189 190 190 191 elif choice == '2': … … 207 208 code, result = self.post_to_server(data) 208 209 if code != 200: 209 print 'Server response (%s): %s'%(code, result)210 log.info('Server response (%s): %s' % (code, result)) 210 211 else: 211 print 'You will receive an email shortly.' 212 print 'Follow the instructions in it to complete registration.' 212 log.info('You will receive an email shortly.') 213 log.info(('Follow the instructions in it to ' 214 'complete registration.')) 213 215 elif choice == '3': 214 216 data = {':action': 'password_reset'} … … 217 219 data['email'] = raw_input('Your email address: ') 218 220 code, result = self.post_to_server(data) 219 print 'Server response (%s): %s'%(code, result)221 log.info('Server response (%s): %s' % (code, result)) 220 222 221 223 def build_post_data(self, action): … … 250 252 ''' Post a query to the server, and return a string response. 251 253 ''' 252 self.announce('Registering %s to %s' % (data['name'], 253 self.repository), log.INFO) 254 if 'name' in data: 255 self.announce('Registering %s to %s' % (data['name'], 256 self.repository), 257 log.INFO) 254 258 # Build up the MIME payload for the urllib2 POST data 255 259 boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' 256 260 sep_boundary = '\n--' + boundary 257 261 end_boundary = sep_boundary + '--' 258 body = StringIO.StringIO()262 chunks = [] 259 263 for key, value in data.items(): 260 264 # handle multiple entries for the same name … … 262 266 value = [value] 263 267 for value in value: 264 body.write(sep_boundary)265 body.write('\nContent-Disposition: form-data; name="%s"'%key)266 body.write("\n\n")267 body.write(value)268 chunks.append(sep_boundary) 269 chunks.append('\nContent-Disposition: form-data; name="%s"'%key) 270 chunks.append("\n\n") 271 chunks.append(value) 268 272 if value and value[-1] == '\r': 269 body.write('\n') # write an extra newline (lurve Macs) 270 body.write(end_boundary) 271 body.write("\n") 272 body = body.getvalue() 273 chunks.append('\n') # write an extra newline (lurve Macs) 274 chunks.append(end_boundary) 275 chunks.append("\n") 276 277 # chunks may be bytes (str) or unicode objects that we need to encode 278 body = [] 279 for chunk in chunks: 280 if isinstance(chunk, unicode): 281 body.append(chunk.encode('utf-8')) 282 else: 283 body.append(chunk) 284 285 body = ''.join(body) 273 286 274 287 # build the Request … … 297 310 result = 200, 'OK' 298 311 if self.show_response: 299 print '-'*75, data, '-'*75 312 dashes = '-' * 75 313 self.announce('%s%s%s' % (dashes, data, dashes)) 314 300 315 return result -
python/trunk/Lib/distutils/command/sdist.py
r2 r391 3 3 Implements the Distutils 'sdist' command (create a source distribution).""" 4 4 5 # This module should be kept compatible with Python 2.1. 6 7 __revision__ = "$Id: sdist.py 68968 2009-01-26 17:20:15Z tarek.ziade $" 8 9 import os, string 5 __revision__ = "$Id$" 6 7 import os 8 import string 10 9 import sys 11 from types import *12 10 from glob import glob 11 from warnings import warn 12 13 13 from distutils.core import Command 14 14 from distutils import dir_util, dep_util, file_util, archive_util 15 15 from distutils.text_file import TextFile 16 from distutils.errors import * 16 from distutils.errors import (DistutilsPlatformError, DistutilsOptionError, 17 DistutilsTemplateError) 17 18 from distutils.filelist import FileList 18 19 from distutils import log 19 20 21 def show_formats 20 from distutils.util import convert_path 21 22 def show_formats(): 22 23 """Print all possible values for the 'formats' option (used by 23 24 the "--help-formats" command-line option). … … 25 26 from distutils.fancy_getopt import FancyGetopt 26 27 from distutils.archive_util import ARCHIVE_FORMATS 27 formats =[]28 formats = [] 28 29 for format in ARCHIVE_FORMATS.keys(): 29 30 formats.append(("formats=" + format, None, 30 31 ARCHIVE_FORMATS[format][2])) 31 32 formats.sort() 32 pretty_printer = FancyGetopt(formats) 33 pretty_printer.print_help( 33 FancyGetopt(formats).print_help( 34 34 "List of available source distribution formats:") 35 35 36 class sdist 36 class sdist(Command): 37 37 38 38 description = "create a source distribution (tarball, zip file, etc.)" 39 40 def checking_metadata(self): 41 """Callable used for the check sub-command. 42 43 Placed here so user_options can view it""" 44 return self.metadata_check 39 45 40 46 user_options = [ … … 58 64 "(implies --force-manifest)"), 59 65 ('force-manifest', 'f', 60 "forcibly regenerate the manifest and carry on as usual"), 66 "forcibly regenerate the manifest and carry on as usual. " 67 "Deprecated: now the manifest is always regenerated."), 61 68 ('formats=', None, 62 69 "formats for source distribution (comma-separated list)"), … … 67 74 "directory to put the source distribution archive(s) in " 68 75 "[default: dist]"), 76 ('metadata-check', None, 77 "Ensure that all required elements of meta-data " 78 "are supplied. Warn if any missing. [default]"), 79 ('owner=', 'u', 80 "Owner name used when creating a tar file [default: current user]"), 81 ('group=', 'g', 82 "Group name used when creating a tar file [default: current group]"), 69 83 ] 70 84 71 85 boolean_options = ['use-defaults', 'prune', 72 86 'manifest-only', 'force-manifest', 73 'keep-temp' ]87 'keep-temp', 'metadata-check'] 74 88 75 89 help_options = [ … … 81 95 'no-prune': 'prune' } 82 96 83 default_format = { 'posix': 'gztar', 84 'nt': 'zip' } 85 86 def initialize_options (self): 97 default_format = {'posix': 'gztar', 98 'nt': 'zip' } 99 100 sub_commands = [('check', checking_metadata)] 101 102 def initialize_options(self): 87 103 # 'template' and 'manifest' are, respectively, the names of 88 104 # the manifest template and manifest file. … … 103 119 104 120 self.archive_files = None 105 106 107 def finalize_options (self): 121 self.metadata_check = 1 122 self.owner = None 123 self.group = None 124 125 def finalize_options(self): 108 126 if self.manifest is None: 109 127 self.manifest = "MANIFEST" … … 128 146 self.dist_dir = "dist" 129 147 130 131 def run (self): 132 148 def run(self): 133 149 # 'filelist' contains the list of files that will make up the 134 150 # manifest 135 151 self.filelist = FileList() 136 152 137 # Ensure that all required meta-data is given; warn if not (but138 # don't die, it's not *that* serious!)139 self.check_metadata()153 # Run sub commands 154 for cmd_name in self.get_sub_commands(): 155 self.run_command(cmd_name) 140 156 141 157 # Do whatever it takes to get the list of files to process … … 152 168 self.make_distribution() 153 169 154 155 def check_metadata (self): 156 """Ensure that all required elements of meta-data (name, version, 157 URL, (author and author_email) or (maintainer and 158 maintainer_email)) are supplied by the Distribution object; warn if 159 any are missing. 160 """ 161 metadata = self.distribution.metadata 162 163 missing = [] 164 for attr in ('name', 'version', 'url'): 165 if not (hasattr(metadata, attr) and getattr(metadata, attr)): 166 missing.append(attr) 167 168 if missing: 169 self.warn("missing required meta-data: " + 170 string.join(missing, ", ")) 171 172 if metadata.author: 173 if not metadata.author_email: 174 self.warn("missing meta-data: if 'author' supplied, " + 175 "'author_email' must be supplied too") 176 elif metadata.maintainer: 177 if not metadata.maintainer_email: 178 self.warn("missing meta-data: if 'maintainer' supplied, " + 179 "'maintainer_email' must be supplied too") 180 else: 181 self.warn("missing meta-data: either (author and author_email) " + 182 "or (maintainer and maintainer_email) " + 183 "must be supplied") 184 185 # check_metadata () 186 187 188 def get_file_list (self): 170 def check_metadata(self): 171 """Deprecated API.""" 172 warn("distutils.command.sdist.check_metadata is deprecated, \ 173 use the check command instead", PendingDeprecationWarning) 174 check = self.distribution.get_command_obj('check') 175 check.ensure_finalized() 176 check.run() 177 178 def get_file_list(self): 189 179 """Figure out the list of files to include in the source 190 180 distribution, and put it in 'self.filelist'. This might involve 191 181 reading the manifest template (and writing the manifest), or just 192 182 reading the manifest, or just using the default file set -- it all 193 depends on the user's options and the state of the filesystem. 194 """ 195 196 # If we have a manifest template, see if it's newer than the 197 # manifest; if so, we'll regenerate the manifest. 183 depends on the user's options. 184 """ 185 # new behavior when using a template: 186 # the file list is recalculated every time because 187 # even if MANIFEST.in or setup.py are not changed 188 # the user might have added some files in the tree that 189 # need to be included. 190 # 191 # This makes --force the default and only behavior with templates. 198 192 template_exists = os.path.isfile(self.template) 199 if template_exists: 200 template_newer = dep_util.newer(self.template, self.manifest) 201 202 # The contents of the manifest file almost certainly depend on the 203 # setup script as well as the manifest template -- so if the setup 204 # script is newer than the manifest, we'll regenerate the manifest 205 # from the template. (Well, not quite: if we already have a 206 # manifest, but there's no template -- which will happen if the 207 # developer elects to generate a manifest some other way -- then we 208 # can't regenerate the manifest, so we don't.) 209 self.debug_print("checking if %s newer than %s" % 210 (self.distribution.script_name, self.manifest)) 211 setup_newer = dep_util.newer(self.distribution.script_name, 212 self.manifest) 213 214 # cases: 215 # 1) no manifest, template exists: generate manifest 216 # (covered by 2a: no manifest == template newer) 217 # 2) manifest & template exist: 218 # 2a) template or setup script newer than manifest: 219 # regenerate manifest 220 # 2b) manifest newer than both: 221 # do nothing (unless --force or --manifest-only) 222 # 3) manifest exists, no template: 223 # do nothing (unless --force or --manifest-only) 224 # 4) no manifest, no template: generate w/ warning ("defaults only") 225 226 manifest_outofdate = (template_exists and 227 (template_newer or setup_newer)) 228 force_regen = self.force_manifest or self.manifest_only 229 manifest_exists = os.path.isfile(self.manifest) 230 neither_exists = (not template_exists and not manifest_exists) 231 232 # Regenerate the manifest if necessary (or if explicitly told to) 233 if manifest_outofdate or neither_exists or force_regen: 234 if not template_exists: 235 self.warn(("manifest template '%s' does not exist " + 236 "(using default file list)") % 237 self.template) 238 self.filelist.findall() 239 240 if self.use_defaults: 241 self.add_defaults() 242 if template_exists: 243 self.read_template() 244 if self.prune: 245 self.prune_file_list() 246 193 if not template_exists and self._manifest_is_not_generated(): 194 self.read_manifest() 247 195 self.filelist.sort() 248 196 self.filelist.remove_duplicates() 249 self.write_manifest() 250 251 # Don't regenerate the manifest, just read it in. 252 else: 253 self.read_manifest() 254 255 # get_file_list () 256 257 258 def add_defaults (self): 197 return 198 199 if not template_exists: 200 self.warn(("manifest template '%s' does not exist " + 201 "(using default file list)") % 202 self.template) 203 self.filelist.findall() 204 205 if self.use_defaults: 206 self.add_defaults() 207 208 if template_exists: 209 self.read_template() 210 211 if self.prune: 212 self.prune_file_list() 213 214 self.filelist.sort() 215 self.filelist.remove_duplicates() 216 self.write_manifest() 217 218 def add_defaults(self): 259 219 """Add all the default files to self.filelist: 260 220 - README or README.txt … … 262 222 - test/test*.py 263 223 - all pure Python modules mentioned in setup script 224 - all files pointed by package_data (build_py) 225 - all files defined in data_files. 226 - all files defined as scripts. 264 227 - all C sources listed as part of extensions or C libraries 265 228 in the setup script (doesn't catch C headers!) … … 270 233 standards = [('README', 'README.txt'), self.distribution.script_name] 271 234 for fn in standards: 272 if type(fn) is TupleType:235 if isinstance(fn, tuple): 273 236 alts = fn 274 237 got_it = 0 … … 294 257 self.filelist.extend(files) 295 258 259 # build_py is used to get: 260 # - python modules 261 # - files defined in package_data 262 build_py = self.get_finalized_command('build_py') 263 264 # getting python files 296 265 if self.distribution.has_pure_modules(): 297 build_py = self.get_finalized_command('build_py')298 266 self.filelist.extend(build_py.get_source_files()) 267 268 # getting package_data files 269 # (computed in build_py.data_files by build_py.finalize_options) 270 for pkg, src_dir, build_dir, filenames in build_py.data_files: 271 for filename in filenames: 272 self.filelist.append(os.path.join(src_dir, filename)) 273 274 # getting distribution.data_files 275 if self.distribution.has_data_files(): 276 for item in self.distribution.data_files: 277 if isinstance(item, str): # plain file 278 item = convert_path(item) 279 if os.path.isfile(item): 280 self.filelist.append(item) 281 else: # a (dirname, filenames) tuple 282 dirname, filenames = item 283 for f in filenames: 284 f = convert_path(f) 285 if os.path.isfile(f): 286 self.filelist.append(f) 299 287 300 288 if self.distribution.has_ext_modules(): … … 310 298 self.filelist.extend(build_scripts.get_source_files()) 311 299 312 # add_defaults () 313 314 315 def read_template (self): 300 def read_template(self): 316 301 """Read and parse manifest template file named by self.template. 317 302 … … 328 313 collapse_join=1) 329 314 330 while 1: 331 line = template.readline() 332 if line is None: # end of file 333 break 334 335 try: 336 self.filelist.process_template_line(line) 337 except DistutilsTemplateError, msg: 338 self.warn("%s, line %d: %s" % (template.filename, 339 template.current_line, 340 msg)) 341 342 # read_template () 343 344 345 def prune_file_list (self): 315 try: 316 while 1: 317 line = template.readline() 318 if line is None: # end of file 319 break 320 321 try: 322 self.filelist.process_template_line(line) 323 # the call above can raise a DistutilsTemplateError for 324 # malformed lines, or a ValueError from the lower-level 325 # convert_path function 326 except (DistutilsTemplateError, ValueError) as msg: 327 self.warn("%s, line %d: %s" % (template.filename, 328 template.current_line, 329 msg)) 330 finally: 331 template.close() 332 333 def prune_file_list(self): 346 334 """Prune off branches that might slip into the file list as created 347 335 by 'read_template()', but really don't belong there: … … 369 357 self.filelist.exclude_pattern(vcs_ptrn, is_regex=1) 370 358 371 def write_manifest 359 def write_manifest(self): 372 360 """Write the file list in 'self.filelist' (presumably as filled in 373 361 by 'add_defaults()' and 'read_template()') to the manifest file 374 362 named by 'self.manifest'. 375 363 """ 376 self.execute(file_util.write_file, 377 (self.manifest, self.filelist.files), 364 if self._manifest_is_not_generated(): 365 log.info("not writing to manually maintained " 366 "manifest file '%s'" % self.manifest) 367 return 368 369 content = self.filelist.files[:] 370 content.insert(0, '# file GENERATED by distutils, do NOT edit') 371 self.execute(file_util.write_file, (self.manifest, content), 378 372 "writing manifest file '%s'" % self.manifest) 379 373 380 # write_manifest () 381 382 383 def read_manifest (self): 374 def _manifest_is_not_generated(self): 375 # check for special comment used in 2.7.1 and higher 376 if not os.path.isfile(self.manifest): 377 return False 378 379 fp = open(self.manifest, 'rU') 380 try: 381 first_line = fp.readline() 382 finally: 383 fp.close() 384 return first_line != '# file GENERATED by distutils, do NOT edit\n' 385 386 def read_manifest(self): 384 387 """Read the manifest file (named by 'self.manifest') and use it to 385 388 fill in 'self.filelist', the list of files to include in the source … … 388 391 log.info("reading manifest file '%s'", self.manifest) 389 392 manifest = open(self.manifest) 390 while 1: 391 line = manifest.readline() 392 if line == '': # end of file 393 break 394 if line[-1] == '\n': 395 line = line[0:-1] 393 for line in manifest: 394 # ignore comments and blank lines 395 line = line.strip() 396 if line.startswith('#') or not line: 397 continue 396 398 self.filelist.append(line) 397 399 manifest.close() 398 400 399 # read_manifest () 400 401 402 def make_release_tree (self, base_dir, files): 401 def make_release_tree(self, base_dir, files): 403 402 """Create the directory tree that will become the source 404 403 distribution archive. All directories implied by the filenames in … … 442 441 self.distribution.metadata.write_pkg_info(base_dir) 443 442 444 # make_release_tree () 445 446 def make_distribution (self): 443 def make_distribution(self): 447 444 """Create the source distribution(s). First, we create the release 448 445 tree with 'make_release_tree()'; then, we create all required … … 464 461 465 462 for fmt in self.formats: 466 file = self.make_archive(base_name, fmt, base_dir=base_dir) 463 file = self.make_archive(base_name, fmt, base_dir=base_dir, 464 owner=self.owner, group=self.group) 467 465 archive_files.append(file) 468 466 self.distribution.dist_files.append(('sdist', '', file)) … … 473 471 dir_util.remove_tree(base_dir, dry_run=self.dry_run) 474 472 475 def get_archive_files 473 def get_archive_files(self): 476 474 """Return the list of archive files created when the command 477 475 was run, or None if the command hasn't run yet. 478 476 """ 479 477 return self.archive_files 480 481 # class sdist -
python/trunk/Lib/distutils/command/upload.py
r2 r391 2 2 3 3 Implements the Distutils 'upload' subcommand (upload package to PyPI).""" 4 import os 5 import socket 6 import platform 7 from urllib2 import urlopen, Request, HTTPError 8 from base64 import standard_b64encode 9 import urlparse 10 import cStringIO as StringIO 11 from hashlib import md5 4 12 5 from distutils.errors import *13 from distutils.errors import DistutilsOptionError 6 14 from distutils.core import PyPIRCCommand 7 15 from distutils.spawn import spawn 8 16 from distutils import log 9 from hashlib import md510 import os11 import socket12 import platform13 import httplib14 from base64 import standard_b64encode15 import urlparse16 import cStringIO as StringIO17 from ConfigParser import ConfigParser18 19 17 20 18 class upload(PyPIRCCommand): … … 51 49 self.realm = config['realm'] 52 50 51 # getting the password from the distribution 52 # if previously set by the register command 53 if not self.password and self.distribution.password: 54 self.password = self.distribution.password 55 53 56 def run(self): 54 57 if not self.distribution.dist_files: … … 58 61 59 62 def upload_file(self, command, pyversion, filename): 63 # Makes sure the repository URL is compliant 64 schema, netloc, url, params, query, fragments = \ 65 urlparse.urlparse(self.repository) 66 if params or query or fragments: 67 raise AssertionError("Incompatible url %s" % self.repository) 68 69 if schema not in ('http', 'https'): 70 raise AssertionError("unsupported schema " + schema) 71 60 72 # Sign if requested 61 73 if self.sign: … … 68 80 # Fill in the data - send all the meta-data in case we need to 69 81 # register a new release 70 content = open(filename,'rb').read() 82 f = open(filename,'rb') 83 try: 84 content = f.read() 85 finally: 86 f.close() 71 87 meta = self.distribution.metadata 72 88 data = { … … 126 142 for key, value in data.items(): 127 143 # handle multiple entries for the same name 128 if type(value) != type([]):144 if not isinstance(value, list): 129 145 value = [value] 130 146 for value in value: 131 if type(value) is tuple:147 if isinstance(value, tuple): 132 148 fn = ';filename="%s"' % value[0] 133 149 value = value[1] … … 149 165 150 166 # build the Request 151 # We can't use urllib2 since we need to send the Basic 152 # auth right with the first request 153 schema, netloc, url, params, query, fragments = \ 154 urlparse.urlparse(self.repository) 155 assert not params and not query and not fragments 156 if schema == 'http': 157 http = httplib.HTTPConnection(netloc) 158 elif schema == 'https': 159 http = httplib.HTTPSConnection(netloc) 160 else: 161 raise AssertionError, "unsupported schema "+schema 167 headers = {'Content-type': 168 'multipart/form-data; boundary=%s' % boundary, 169 'Content-length': str(len(body)), 170 'Authorization': auth} 162 171 163 data = '' 164 loglevel = log.INFO 172 request = Request(self.repository, data=body, 173 headers=headers) 174 # send the data 165 175 try: 166 http.connect() 167 http.putrequest("POST", url) 168 http.putheader('Content-type', 169 'multipart/form-data; boundary=%s'%boundary) 170 http.putheader('Content-length', str(len(body))) 171 http.putheader('Authorization', auth) 172 http.endheaders() 173 http.send(body) 176 result = urlopen(request) 177 status = result.getcode() 178 reason = result.msg 179 if self.show_response: 180 msg = '\n'.join(('-' * 75, r.read(), '-' * 75)) 181 self.announce(msg, log.INFO) 174 182 except socket.error, e: 175 183 self.announce(str(e), log.ERROR) 176 184 return 185 except HTTPError, e: 186 status = e.code 187 reason = e.msg 177 188 178 r = http.getresponse() 179 if r.status == 200: 180 self.announce('Server response (%s): %s' % (r.status, r.reason), 189 if status == 200: 190 self.announce('Server response (%s): %s' % (status, reason), 181 191 log.INFO) 182 192 else: 183 self.announce('Upload failed (%s): %s' % ( r.status, r.reason),193 self.announce('Upload failed (%s): %s' % (status, reason), 184 194 log.ERROR) 185 if self.show_response:186 print '-'*75, r.read(), '-'*75
Note:
See TracChangeset
for help on using the changeset viewer.