# HG changeset patch # User Volker Kleinfeld # Date 1148054068 25200 # Node ID c58a403aa830b798564e4ad88eec8236000301f7 # Parent 4be9a79b49b177f5c44c4f32b22999ff5583880a setup.py: install packagescan before any mercurial modules is imported Further the installation of packagescan over demandload is moved to the packagescan module. I added as well few more comments in the packagescan module to avoid the wrong use of package scan in the future. Reason: mercurial.packagescan acts as fake mercurial.demandload during a py2exe run. Unfortunatly the import of mercurial.version in setup.py is done before mercurial.packagescan is installed. This results in few imports without mercurial.packagescan in charge and therefore not all dependend modules are detected when running mercurial.packagescan.getmodules later e.g. winerror is missed. diff -r 4be9a79b49b1 -r c58a403aa830 mercurial/packagescan.py --- a/mercurial/packagescan.py Wed May 17 13:21:36 2006 -0500 +++ b/mercurial/packagescan.py Fri May 19 08:54:28 2006 -0700 @@ -1,5 +1,6 @@ # packagescan.py - Helper module for identifing used modules. # Used for the py2exe distutil. +# This module must be the first mercurial module imported in setup.py # # Copyright 2005 Volker Kleinfeld # @@ -8,10 +9,16 @@ import glob import os import sys -import demandload import ihooks -requiredmodules = {} # Will contain the modules imported by demandload +# Install this module as fake demandload module +sys.modules['mercurial.demandload'] = sys.modules[__name__] + +# Requiredmodules contains the modules imported by demandload. +# Please note that demandload can be invoked before the +# mercurial.packagescan.scan method is invoked in case a mercurial +# module is imported. +requiredmodules = {} def demandload(scope, modules): """ fake demandload function that collects the required modules """ for m in modules.split(): @@ -26,7 +33,7 @@ scope[module] = mod requiredmodules[mod.__name__] = 1 -def getmodules(libpath,packagename): +def scan(libpath,packagename): """ helper for finding all required modules of package """ # Use the package in the build directory libpath = os.path.abspath(libpath) @@ -45,8 +52,6 @@ pymodulefiles = glob.glob('*.py') extmodulefiles = glob.glob('*.pyd') os.chdir(cwd) - # Install a fake demandload module - sys.modules['mercurial.demandload'] = sys.modules['mercurial.packagescan'] # Import all python modules and by that run the fake demandload for m in pymodulefiles: if m == '__init__.py': continue @@ -62,8 +67,9 @@ fullname = packagename+'.'+mname __import__(fullname,tmp,tmp) requiredmodules[fullname] = 1 - includes = requiredmodules.keys() - return includes + +def getmodules(): + return requiredmodules.keys() def importfrom(filename): """ diff -r 4be9a79b49b1 -r c58a403aa830 setup.py --- a/setup.py Wed May 17 13:21:36 2006 -0500 +++ b/setup.py Fri May 19 08:54:28 2006 -0700 @@ -13,6 +13,8 @@ from distutils.core import setup, Extension from distutils.command.install_data import install_data +# mercurial.packagescan must be the first mercurial module imported +import mercurial.packagescan import mercurial.version # py2exe needs to be installed to work @@ -36,7 +38,6 @@ # Due to the use of demandload py2exe is not finding the modules. # packagescan.getmodules creates a list of modules included in # the mercurial package plus depdent modules. - import mercurial.packagescan from py2exe.build_exe import py2exe as build_exe class py2exe_for_demandload(build_exe): @@ -54,10 +55,9 @@ self.includes = [] else: self.includes = self.includes.split(',') - self.includes += mercurial.packagescan.getmodules(self.build_lib, - 'mercurial') - self.includes += mercurial.packagescan.getmodules(self.build_lib, - 'hgext') + mercurial.packagescan.scan(self.build_lib,'mercurial') + mercurial.packagescan.scan(self.build_lib,'hgext') + self.includes += mercurial.packagescan.getmodules() build_exe.finalize_options(self) except ImportError: py2exe_for_demandload = None