Show More
@@ -1,80 +1,113 b'' | |||||
1 | # packagescan.py - Helper module for identifing used modules. |
|
1 | # packagescan.py - Helper module for identifing used modules. | |
2 | # Used for the py2exe distutil. |
|
2 | # Used for the py2exe distutil. | |
|
3 | # This module must be the first mercurial module imported in setup.py | |||
3 | # |
|
4 | # | |
4 | # Copyright 2005 Volker Kleinfeld <Volker.Kleinfeld@gmx.de> |
|
5 | # Copyright 2005 Volker Kleinfeld <Volker.Kleinfeld@gmx.de> | |
5 | # |
|
6 | # | |
6 | # This software may be used and distributed according to the terms |
|
7 | # This software may be used and distributed according to the terms | |
7 | # of the GNU General Public License, incorporated herein by reference. |
|
8 | # of the GNU General Public License, incorporated herein by reference. | |
8 | import glob |
|
9 | import glob | |
9 | import os |
|
10 | import os | |
10 | import sys |
|
11 | import sys | |
11 | import demandload |
|
|||
12 | import ihooks |
|
12 | import ihooks | |
|
13 | import types | |||
|
14 | import string | |||
|
15 | ||||
|
16 | # Install this module as fake demandload module | |||
|
17 | sys.modules['mercurial.demandload'] = sys.modules[__name__] | |||
13 |
|
18 | |||
14 |
|
|
19 | # Requiredmodules contains the modules imported by demandload. | |
|
20 | # Please note that demandload can be invoked before the | |||
|
21 | # mercurial.packagescan.scan method is invoked in case a mercurial | |||
|
22 | # module is imported. | |||
|
23 | requiredmodules = {} | |||
15 | def demandload(scope, modules): |
|
24 | def demandload(scope, modules): | |
16 |
""" fake demandload function that collects the required modules |
|
25 | """ fake demandload function that collects the required modules | |
|
26 | foo import foo | |||
|
27 | foo bar import foo, bar | |||
|
28 | foo.bar import foo.bar | |||
|
29 | foo:bar from foo import bar | |||
|
30 | foo:bar,quux from foo import bar, quux | |||
|
31 | foo.bar:quux from foo.bar import quux""" | |||
|
32 | ||||
17 | for m in modules.split(): |
|
33 | for m in modules.split(): | |
18 | mod = None |
|
34 | mod = None | |
19 | try: |
|
35 | try: | |
20 |
module, |
|
36 | module, fromlist = m.split(':') | |
21 |
|
|
37 | fromlist = fromlist.split(',') | |
22 | except: |
|
38 | except: | |
23 | module = m |
|
39 | module = m | |
24 |
|
|
40 | fromlist = [] | |
25 |
mod = __import__(module, scope, scope, |
|
41 | mod = __import__(module, scope, scope, fromlist) | |
26 | scope[module] = mod |
|
42 | if fromlist == []: | |
27 | requiredmodules[mod.__name__] = 1 |
|
43 | # mod is only the top package, but we need all packages | |
|
44 | comp = module.split('.') | |||
|
45 | i = 1 | |||
|
46 | mn = comp[0] | |||
|
47 | while True: | |||
|
48 | # mn and mod.__name__ might not be the same | |||
|
49 | scope[mn] = mod | |||
|
50 | requiredmodules[mod.__name__] = 1 | |||
|
51 | if len(comp) == i: break | |||
|
52 | mod = getattr(mod,comp[i]) | |||
|
53 | mn = string.join(comp[:i+1],'.') | |||
|
54 | i += 1 | |||
|
55 | else: | |||
|
56 | # mod is the last package in the component list | |||
|
57 | requiredmodules[mod.__name__] = 1 | |||
|
58 | for f in fromlist: | |||
|
59 | scope[f] = getattr(mod,f) | |||
|
60 | if type(scope[f]) == types.ModuleType: | |||
|
61 | requiredmodules[scope[f].__name__] = 1 | |||
28 |
|
62 | |||
29 |
def |
|
63 | def scan(libpath,packagename): | |
30 | """ helper for finding all required modules of package <packagename> """ |
|
64 | """ helper for finding all required modules of package <packagename> """ | |
31 | # Use the package in the build directory |
|
65 | # Use the package in the build directory | |
32 | libpath = os.path.abspath(libpath) |
|
66 | libpath = os.path.abspath(libpath) | |
33 | sys.path.insert(0,libpath) |
|
67 | sys.path.insert(0,libpath) | |
34 | packdir = os.path.join(libpath,packagename) |
|
68 | packdir = os.path.join(libpath,packagename) | |
35 | # A normal import would not find the package in |
|
69 | # A normal import would not find the package in | |
36 | # the build directory. ihook is used to force the import. |
|
70 | # the build directory. ihook is used to force the import. | |
37 | # After the package is imported the import scope for |
|
71 | # After the package is imported the import scope for | |
38 | # the following imports is settled. |
|
72 | # the following imports is settled. | |
39 | p = importfrom(packdir) |
|
73 | p = importfrom(packdir) | |
40 | globals()[packagename] = p |
|
74 | globals()[packagename] = p | |
41 | sys.modules[packagename] = p |
|
75 | sys.modules[packagename] = p | |
42 | # Fetch the python modules in the package |
|
76 | # Fetch the python modules in the package | |
43 | cwd = os.getcwd() |
|
77 | cwd = os.getcwd() | |
44 | os.chdir(packdir) |
|
78 | os.chdir(packdir) | |
45 | pymodulefiles = glob.glob('*.py') |
|
79 | pymodulefiles = glob.glob('*.py') | |
46 | extmodulefiles = glob.glob('*.pyd') |
|
80 | extmodulefiles = glob.glob('*.pyd') | |
47 | os.chdir(cwd) |
|
81 | os.chdir(cwd) | |
48 | # Install a fake demandload module |
|
|||
49 | sys.modules['mercurial.demandload'] = sys.modules['mercurial.packagescan'] |
|
|||
50 | # Import all python modules and by that run the fake demandload |
|
82 | # Import all python modules and by that run the fake demandload | |
51 | for m in pymodulefiles: |
|
83 | for m in pymodulefiles: | |
52 | if m == '__init__.py': continue |
|
84 | if m == '__init__.py': continue | |
53 | tmp = {} |
|
85 | tmp = {} | |
54 | mname,ext = os.path.splitext(m) |
|
86 | mname,ext = os.path.splitext(m) | |
55 | fullname = packagename+'.'+mname |
|
87 | fullname = packagename+'.'+mname | |
56 | __import__(fullname,tmp,tmp) |
|
88 | __import__(fullname,tmp,tmp) | |
57 | requiredmodules[fullname] = 1 |
|
89 | requiredmodules[fullname] = 1 | |
58 | # Import all extension modules and by that run the fake demandload |
|
90 | # Import all extension modules and by that run the fake demandload | |
59 | for m in extmodulefiles: |
|
91 | for m in extmodulefiles: | |
60 | tmp = {} |
|
92 | tmp = {} | |
61 | mname,ext = os.path.splitext(m) |
|
93 | mname,ext = os.path.splitext(m) | |
62 | fullname = packagename+'.'+mname |
|
94 | fullname = packagename+'.'+mname | |
63 | __import__(fullname,tmp,tmp) |
|
95 | __import__(fullname,tmp,tmp) | |
64 | requiredmodules[fullname] = 1 |
|
96 | requiredmodules[fullname] = 1 | |
65 | includes = requiredmodules.keys() |
|
97 | ||
66 | return includes |
|
98 | def getmodules(): | |
|
99 | return requiredmodules.keys() | |||
67 |
|
100 | |||
68 | def importfrom(filename): |
|
101 | def importfrom(filename): | |
69 | """ |
|
102 | """ | |
70 | import module/package from a named file and returns the module. |
|
103 | import module/package from a named file and returns the module. | |
71 | It does not check on sys.modules or includes the module in the scope. |
|
104 | It does not check on sys.modules or includes the module in the scope. | |
72 | """ |
|
105 | """ | |
73 | loader = ihooks.BasicModuleLoader() |
|
106 | loader = ihooks.BasicModuleLoader() | |
74 | path, file = os.path.split(filename) |
|
107 | path, file = os.path.split(filename) | |
75 | name, ext = os.path.splitext(file) |
|
108 | name, ext = os.path.splitext(file) | |
76 | m = loader.find_module_in_dir(name, path) |
|
109 | m = loader.find_module_in_dir(name, path) | |
77 | if not m: |
|
110 | if not m: | |
78 | raise ImportError, name |
|
111 | raise ImportError, name | |
79 | m = loader.load_module(name, m) |
|
112 | m = loader.load_module(name, m) | |
80 | return m |
|
113 | return m |
@@ -1,105 +1,104 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # |
|
2 | # | |
3 | # This is the mercurial setup script. |
|
3 | # This is the mercurial setup script. | |
4 | # |
|
4 | # | |
5 | # './setup.py install', or |
|
5 | # './setup.py install', or | |
6 | # './setup.py --help' for more options |
|
6 | # './setup.py --help' for more options | |
7 |
|
7 | |||
8 | import sys |
|
8 | import sys | |
9 | if not hasattr(sys, 'version_info') or sys.version_info < (2, 3): |
|
9 | if not hasattr(sys, 'version_info') or sys.version_info < (2, 3): | |
10 | raise SystemExit, "Mercurial requires python 2.3 or later." |
|
10 | raise SystemExit, "Mercurial requires python 2.3 or later." | |
11 |
|
11 | |||
12 | import glob |
|
12 | import glob | |
13 | from distutils.core import setup, Extension |
|
13 | from distutils.core import setup, Extension | |
14 | from distutils.command.install_data import install_data |
|
14 | from distutils.command.install_data import install_data | |
15 |
|
15 | |||
|
16 | # mercurial.packagescan must be the first mercurial module imported | |||
|
17 | import mercurial.packagescan | |||
16 | import mercurial.version |
|
18 | import mercurial.version | |
17 |
|
19 | |||
18 | # py2exe needs to be installed to work |
|
20 | # py2exe needs to be installed to work | |
19 | try: |
|
21 | try: | |
20 | import py2exe |
|
22 | import py2exe | |
21 |
|
23 | |||
22 | # Help py2exe to find win32com.shell |
|
24 | # Help py2exe to find win32com.shell | |
23 | try: |
|
25 | try: | |
24 | import modulefinder |
|
26 | import modulefinder | |
25 | import win32com |
|
27 | import win32com | |
26 | for p in win32com.__path__[1:]: # Take the path to win32comext |
|
28 | for p in win32com.__path__[1:]: # Take the path to win32comext | |
27 | modulefinder.AddPackagePath("win32com", p) |
|
29 | modulefinder.AddPackagePath("win32com", p) | |
28 | pn = "win32com.shell" |
|
30 | pn = "win32com.shell" | |
29 | __import__(pn) |
|
31 | __import__(pn) | |
30 | m = sys.modules[pn] |
|
32 | m = sys.modules[pn] | |
31 | for p in m.__path__[1:]: |
|
33 | for p in m.__path__[1:]: | |
32 | modulefinder.AddPackagePath(pn, p) |
|
34 | modulefinder.AddPackagePath(pn, p) | |
33 | except ImportError: |
|
35 | except ImportError: | |
34 | pass |
|
36 | pass | |
35 |
|
37 | |||
36 | # Due to the use of demandload py2exe is not finding the modules. |
|
38 | # Due to the use of demandload py2exe is not finding the modules. | |
37 | # packagescan.getmodules creates a list of modules included in |
|
39 | # packagescan.getmodules creates a list of modules included in | |
38 | # the mercurial package plus depdent modules. |
|
40 | # the mercurial package plus depdent modules. | |
39 | import mercurial.packagescan |
|
|||
40 | from py2exe.build_exe import py2exe as build_exe |
|
41 | from py2exe.build_exe import py2exe as build_exe | |
41 |
|
42 | |||
42 | class py2exe_for_demandload(build_exe): |
|
43 | class py2exe_for_demandload(build_exe): | |
43 | """ overwrites the py2exe command class for getting the build |
|
44 | """ overwrites the py2exe command class for getting the build | |
44 | directory and for setting the 'includes' option.""" |
|
45 | directory and for setting the 'includes' option.""" | |
45 | def initialize_options(self): |
|
46 | def initialize_options(self): | |
46 | self.build_lib = None |
|
47 | self.build_lib = None | |
47 | build_exe.initialize_options(self) |
|
48 | build_exe.initialize_options(self) | |
48 | def finalize_options(self): |
|
49 | def finalize_options(self): | |
49 | # Get the build directory, ie. where to search for modules. |
|
50 | # Get the build directory, ie. where to search for modules. | |
50 | self.set_undefined_options('build', |
|
51 | self.set_undefined_options('build', | |
51 | ('build_lib', 'build_lib')) |
|
52 | ('build_lib', 'build_lib')) | |
52 | # Sets the 'includes' option with the list of needed modules |
|
53 | # Sets the 'includes' option with the list of needed modules | |
53 | if not self.includes: |
|
54 | if not self.includes: | |
54 | self.includes = [] |
|
55 | self.includes = [] | |
55 | else: |
|
56 | else: | |
56 | self.includes = self.includes.split(',') |
|
57 | self.includes = self.includes.split(',') | |
57 |
|
|
58 | mercurial.packagescan.scan(self.build_lib,'mercurial') | |
58 | 'mercurial') |
|
59 | mercurial.packagescan.scan(self.build_lib,'mercurial/hgweb') | |
59 |
|
|
60 | mercurial.packagescan.scan(self.build_lib,'hgext') | |
60 | 'mercurial/hgweb') |
|
61 | self.includes += mercurial.packagescan.getmodules() | |
61 | self.includes += mercurial.packagescan.getmodules(self.build_lib, |
|
|||
62 | 'hgext') |
|
|||
63 | build_exe.finalize_options(self) |
|
62 | build_exe.finalize_options(self) | |
64 | except ImportError: |
|
63 | except ImportError: | |
65 | py2exe_for_demandload = None |
|
64 | py2exe_for_demandload = None | |
66 |
|
65 | |||
67 |
|
66 | |||
68 | # specify version string, otherwise 'hg identify' will be used: |
|
67 | # specify version string, otherwise 'hg identify' will be used: | |
69 | version = '' |
|
68 | version = '' | |
70 |
|
69 | |||
71 | class install_package_data(install_data): |
|
70 | class install_package_data(install_data): | |
72 | def finalize_options(self): |
|
71 | def finalize_options(self): | |
73 | self.set_undefined_options('install', |
|
72 | self.set_undefined_options('install', | |
74 | ('install_lib', 'install_dir')) |
|
73 | ('install_lib', 'install_dir')) | |
75 | install_data.finalize_options(self) |
|
74 | install_data.finalize_options(self) | |
76 |
|
75 | |||
77 | mercurial.version.remember_version(version) |
|
76 | mercurial.version.remember_version(version) | |
78 | cmdclass = {'install_data': install_package_data} |
|
77 | cmdclass = {'install_data': install_package_data} | |
79 | py2exe_opts = {} |
|
78 | py2exe_opts = {} | |
80 | if py2exe_for_demandload is not None: |
|
79 | if py2exe_for_demandload is not None: | |
81 | cmdclass['py2exe'] = py2exe_for_demandload |
|
80 | cmdclass['py2exe'] = py2exe_for_demandload | |
82 | py2exe_opts['console'] = ['hg'] |
|
81 | py2exe_opts['console'] = ['hg'] | |
83 | setup(name='mercurial', |
|
82 | setup(name='mercurial', | |
84 | version=mercurial.version.get_version(), |
|
83 | version=mercurial.version.get_version(), | |
85 | author='Matt Mackall', |
|
84 | author='Matt Mackall', | |
86 | author_email='mpm@selenic.com', |
|
85 | author_email='mpm@selenic.com', | |
87 | url='http://selenic.com/mercurial', |
|
86 | url='http://selenic.com/mercurial', | |
88 | description='Scalable distributed SCM', |
|
87 | description='Scalable distributed SCM', | |
89 | license='GNU GPL', |
|
88 | license='GNU GPL', | |
90 | packages=['mercurial', 'mercurial.hgweb', 'hgext'], |
|
89 | packages=['mercurial', 'mercurial.hgweb', 'hgext'], | |
91 | ext_modules=[Extension('mercurial.mpatch', ['mercurial/mpatch.c']), |
|
90 | ext_modules=[Extension('mercurial.mpatch', ['mercurial/mpatch.c']), | |
92 | Extension('mercurial.bdiff', ['mercurial/bdiff.c'])], |
|
91 | Extension('mercurial.bdiff', ['mercurial/bdiff.c'])], | |
93 | data_files=[('mercurial/templates', |
|
92 | data_files=[('mercurial/templates', | |
94 | ['templates/map'] + |
|
93 | ['templates/map'] + | |
95 | glob.glob('templates/map-*') + |
|
94 | glob.glob('templates/map-*') + | |
96 | glob.glob('templates/*.tmpl')), |
|
95 | glob.glob('templates/*.tmpl')), | |
97 | ('mercurial/templates/static', |
|
96 | ('mercurial/templates/static', | |
98 | glob.glob('templates/static/*'))], |
|
97 | glob.glob('templates/static/*'))], | |
99 | cmdclass=cmdclass, |
|
98 | cmdclass=cmdclass, | |
100 | scripts=['hg', 'hgmerge'], |
|
99 | scripts=['hg', 'hgmerge'], | |
101 | options=dict(bdist_mpkg=dict(zipdist=True, |
|
100 | options=dict(bdist_mpkg=dict(zipdist=True, | |
102 | license='COPYING', |
|
101 | license='COPYING', | |
103 | readme='contrib/macosx/Readme.html', |
|
102 | readme='contrib/macosx/Readme.html', | |
104 | welcome='contrib/macosx/Welcome.html')), |
|
103 | welcome='contrib/macosx/Welcome.html')), | |
105 | **py2exe_opts) |
|
104 | **py2exe_opts) |
General Comments 0
You need to be logged in to leave comments.
Login now