Andi Vajda wrote: > Does 'install' without 'build' invoke 'build' ? > If that's the case, then yeah, there is a problem and this should be > backed out. If not, then where is the problem ? 'install' without a > prior 'build' would make no sense, no ?
Yes, it does. Every step in the installation process knows about its dependencies. For example install depends amongst others on build, build depends on build_py and build_ext and so forth. Read the output of setup.py install carefully and you'll notice the "running spam" lines. $ sudo python2.5 setup.py install [sudo] password for heimes: running install running bdist_egg running egg_info writing JCC.egg-info/PKG-INFO writing top-level names to JCC.egg-info/top_level.txt writing dependency_links to JCC.egg-info/dependency_links.txt writing manifest file 'JCC.egg-info/SOURCES.txt' installing library code to build/bdist.linux-x86_64/egg running install_lib running build_py copying jcc/classes/org/apache/jcc/PythonVM.class -> build/lib.linux-x86_64-2.5/jcc/classes/org/apache/jcc copying jcc/classes/org/apache/jcc/PythonException.class -> build/lib.linux-x86_64-2.5/jcc/classes/org/apache/jcc running build_ext ... I've attached a patch that hooks into the build process. With the patch the config file is created right before the .py files are copied into the build directory. The MANIFEST.in file must be placed next to setup.py. It prevents jcc/config.py from getting placed in a source release. HTH Christian
Index: setup.py =================================================================== --- setup.py (Revision 752861) +++ setup.py (Arbeitskopie) @@ -108,6 +108,7 @@ if 'USE_DISTUTILS' in os.environ: raise ImportError from setuptools import setup, Extension + from setuptools.command.build_py import build_py as _build_py from pkg_resources import require with_setuptools = require('setuptools')[0].version @@ -162,59 +163,89 @@ raise ImportError, 'setuptools is required when using Python 2.3' else: from distutils.core import setup, Extension + from distutils.command.build_py import build_py as _build_py with_setuptools = None enable_shared = False +from distutils import log -def main(debug): - +def get_buildoptions(): + """Get build options from the environment + """ + _jcc_argsep = os.environ.get('JCC_ARGSEP', os.pathsep) + options = {} + options['enable_shared'] = enable_shared if 'JCC_INCLUDES' in os.environ: - _includes = os.environ['JCC_INCLUDES'].split(_jcc_argsep) + options['includes'] = os.environ['JCC_INCLUDES'].split(_jcc_argsep) else: - _includes = INCLUDES[platform] + options['includes'] = INCLUDES[platform] if 'JCC_CFLAGS' in os.environ: - _cflags = os.environ['JCC_CFLAGS'].split(_jcc_argsep) + options['cflags'] = os.environ['JCC_CFLAGS'].split(_jcc_argsep) else: - _cflags = CFLAGS[platform] + options['cflags'] = CFLAGS[platform] if 'JCC_DEBUG_CFLAGS' in os.environ: - _debug_cflags = os.environ['JCC_DEBUG_CFLAGS'].split(_jcc_argsep) + options['debug_cflags'] = os.environ['JCC_DEBUG_CFLAGS'].split(_jcc_argsep) else: - _debug_cflags = DEBUG_CFLAGS[platform] + options['debug_cflags'] = DEBUG_CFLAGS[platform] if 'JCC_LFLAGS' in os.environ: - _lflags = os.environ['JCC_LFLAGS'].split(_jcc_argsep) + options['lflags'] = os.environ['JCC_LFLAGS'].split(_jcc_argsep) else: - _lflags = LFLAGS[platform] + options['lflags'] = LFLAGS[platform] if 'JCC_JAVAC' in os.environ: - _javac = os.environ['JCC_JAVAC'].split(_jcc_argsep) + options['javac'] = os.environ['JCC_JAVAC'].split(_jcc_argsep) else: - _javac = JAVAC[platform] + options['javac'] = JAVAC[platform] + + return options - config = file(os.path.join(os.path.dirname(os.path.abspath(__file__)), - 'jcc', 'config.py'), 'w') - print >>config - print >>config, 'INCLUDES=%s' %(_includes) - print >>config, 'CFLAGS=%s' %(_cflags) - print >>config, 'DEBUG_CFLAGS=%s' %(_debug_cflags) - print >>config, 'LFLAGS=%s' %(_lflags) - print >>config, 'SHARED=%s' %(enable_shared) - print >>config - config.close() +class build_py(_build_py): + """Custom build_py command to create jcc.config + """ + jcc_options = None + jcc_config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), + 'jcc', 'config.py') + + def create_jcc_config(self): + log.info("Creating jcc.config file '%s'" % self.jcc_config_file) + try: + config = open(self.jcc_config_file, "w") + config.write("# This is an autogenerated file\n\n") + # keep it Python 2.3 compatible + items = self.jcc_options.items() + items.sort() + for key, value in items: + config.write("%s=%s\n" % (key.upper(), value)) + config.write("\n") + finally: + config.close() + + def run(self): + if (not os.path.exists(self.jcc_config_file) or + not "install" in self.distribution.commands): + self.create_jcc_config() + _build_py.run(self) + + +def main(debug): + options = get_buildoptions() + build_py.jcc_options = options + extensions = [] boot = '_jcc' - cflags = ['-DPYTHON'] + _cflags + cflags = ['-DPYTHON'] + options['cflags'] if debug: cflags += _debug_cflags - includes = _includes + [boot, 'jcc/sources'] - lflags = _lflags + includes = options['includes'] + [boot, 'jcc/sources'] + lflags = options['lflags'] if not debug: if platform == 'win32': pass @@ -263,7 +294,7 @@ extensions.append(Library('jcc', **kwds)) - args = _javac[:] + args = options['javac'][:] args.extend(('-d', 'jcc/classes')) args.append('java/org/apache/jcc/PythonVM.java') args.append('java/org/apache/jcc/PythonException.java') @@ -305,7 +336,8 @@ 'packages': ['jcc'], 'package_dir': {'jcc': 'jcc'}, 'package_data': {'jcc': package_data}, - 'ext_modules': extensions + 'ext_modules': extensions, + 'cmdclass': {'build_py': build_py}, } if with_setuptools: args['zip_safe'] = False
exclude jcc/config.py