def command(self): if self.options.list_templates: return self.list_templates() asked_tmpls = self.options.templates or ['basic_package'] templates = [] for tmpl_name in asked_tmpls: self.extend_templates(templates, tmpl_name) if self.options.list_variables: return self.list_variables(templates) if self.verbose: print 'Selected and implied templates:' max_tmpl_name = max([len(tmpl_name) for tmpl_name, tmpl in templates]) for tmpl_name, tmpl in templates: print ' %s%s %s' % ( tmpl_name, ' '*(max_tmpl_name-len(tmpl_name)), tmpl.summary) print if not self.args: if self.interactive: dist_name = self.challenge('Enter project name') else: raise BadCommand('You must provide a PACKAGE_NAME') else: dist_name = self.args[0].lstrip(os.path.sep) templates = [tmpl for name, tmpl in templates] output_dir = os.path.join(self.options.output_dir, dist_name) pkg_name = self._bad_chars_re.sub('', dist_name.lower()) vars = {'project': dist_name, 'package': pkg_name, 'egg': pluginlib.egg_name(dist_name), } vars.update(self.parse_vars(self.args[1:])) if self.options.config and os.path.exists(self.options.config): for key, value in self.read_vars(self.options.config).items(): vars.setdefault(key, value) if self.verbose: # @@: > 1? self.display_vars(vars) if self.options.inspect_files: self.inspect_files( output_dir, templates, vars) return if not os.path.exists(output_dir): # We want to avoid asking questions in copydir if the path # doesn't exist yet copydir.all_answer = 'y' if self.options.svn_repository: self.setup_svn_repository(output_dir, dist_name) # First we want to make sure all the templates get a chance to # set their variables, all at once, with the most specialized # template going first (the last template is the most # specialized)... for template in templates[::-1]: vars = template.check_vars(vars, self) # Gather all the templates egg_plugins into one var egg_plugins = set() for template in templates: egg_plugins.update(template.egg_plugins) egg_plugins = list(egg_plugins) egg_plugins.sort() vars['egg_plugins'] = egg_plugins for template in templates: self.create_template( template, output_dir, vars) found_setup_py = False paster_plugins_mtime = None if os.path.exists(os.path.join(output_dir, 'setup.py')): # Grab paster_plugins.txt's mtime; used to determine if the # egg_info command wrote to it try: egg_info_dir = pluginlib.egg_info_dir(output_dir, dist_name) except IOError: egg_info_dir = None if egg_info_dir is not None: plugins_path = os.path.join(egg_info_dir, 'paster_plugins.txt') if os.path.exists(plugins_path): paster_plugins_mtime = os.path.getmtime(plugins_path) self.run_command(sys.executable, 'setup.py', 'egg_info', cwd=output_dir, # This shouldn't be necessary, but a bug in setuptools 0.6c3 is causing a (not entirely fatal) problem that I don't want to fix right now: expect_returncode=True) found_setup_py = True elif self.verbose > 1: print 'No setup.py (cannot run egg_info)' package_dir = vars.get('package_dir', None) if package_dir: output_dir = os.path.join(output_dir, package_dir) # With no setup.py this doesn't make sense: if found_setup_py: # Only write paster_plugins.txt if it wasn't written by # egg_info (the correct way). leaving us to do it is # deprecated and you'll get warned egg_info_dir = pluginlib.egg_info_dir(output_dir, dist_name) plugins_path = os.path.join(egg_info_dir, 'paster_plugins.txt') if len(egg_plugins) and (not os.path.exists(plugins_path) or \ os.path.getmtime(plugins_path) == paster_plugins_mtime): if self.verbose: print >> sys.stderr, \ ('Manually creating paster_plugins.txt (deprecated! ' 'pass a paster_plugins keyword to setup() instead)') for plugin in egg_plugins: if self.verbose: print 'Adding %s to paster_plugins.txt' % plugin if not self.simulate: pluginlib.add_plugin(egg_info_dir, plugin) if self.options.svn_repository: self.add_svn_repository(vars, output_dir) if self.options.config: write_vars = vars.copy() del write_vars['project'] del write_vars['package'] self.write_vars(self.options.config, write_vars)
def command(self): if self.options.list_templates: return self.list_templates() asked_tmpls = self.options.templates or ['basic_package'] templates = [] for tmpl_name in asked_tmpls: self.extend_templates(templates, tmpl_name) if self.options.list_variables: return self.list_variables(templates) if self.verbose: print 'Selected and implied templates:' max_tmpl_name = max([len(tmpl_name) for tmpl_name, tmpl in templates]) for tmpl_name, tmpl in templates: print ' %s%s %s' % ( tmpl_name, ' '*(max_tmpl_name-len(tmpl_name)), tmpl.summary) print if not self.args: if self.interactive: dist_name = self.challenge('Enter project name') else: raise BadCommand('You must provide a PACKAGE_NAME') else: dist_name = self.args[0].lstrip(os.path.sep) templates = [tmpl for name, tmpl in templates] output_dir = os.path.join(self.options.output_dir, dist_name) pkg_name = self._bad_chars_re.sub('', dist_name.lower()) vars = {'project': dist_name, 'package': pkg_name, 'egg': pluginlib.egg_name(dist_name), } vars.update(self.parse_vars(self.args[1:])) if self.options.config and os.path.exists(self.options.config): for key, value in self.read_vars(self.options.config).items(): vars.setdefault(key, value) if self.verbose: # @@: > 1? self.display_vars(vars) if self.options.inspect_files: self.inspect_files( output_dir, templates, vars) return if not os.path.exists(output_dir): # We want to avoid asking questions in copydir if the path # doesn't exist yet copydir.all_answer = 'y' if self.options.svn_repository: self.setup_svn_repository(output_dir, dist_name) # First we want to make sure all the templates get a chance to # set their variables, all at once, with the most specialized # template going first (the last template is the most # specialized)... for template in templates[::-1]: vars = template.check_vars(vars, self) for template in templates: self.create_template( template, output_dir, vars) found_setup_py = False if os.path.exists(os.path.join(output_dir, 'setup.py')): self.run_command(sys.executable, 'setup.py', 'egg_info', cwd=output_dir, # This shouldn't be necessary, but a bug in setuptools 0.6c3 is causing a (not entirely fatal) problem that I don't want to fix right now: expect_returncode=True) found_setup_py = True elif self.verbose > 1: print 'No setup.py (cannot run egg_info)' package_dir = vars.get('package_dir', None) if package_dir: output_dir = os.path.join(output_dir, package_dir) # With no setup.py this doesn't make sense: if found_setup_py: egg_info_dir = pluginlib.egg_info_dir(output_dir, dist_name) for template in templates: for spec in template.egg_plugins: if self.verbose: print 'Adding %s to paster_plugins.txt' % spec if not self.simulate: pluginlib.add_plugin(egg_info_dir, spec) if not self.simulate: # We'll include this by default, but you can remove # it later if you want: pluginlib.add_plugin(egg_info_dir, 'PasteScript') if self.options.svn_repository: self.add_svn_repository(vars, output_dir) if self.options.config: write_vars = vars.copy() del write_vars['project'] del write_vars['package'] self.write_vars(self.options.config, write_vars)
def command(self): if self.options.list_templates: return self.list_templates() asked_tmpls = self.options.templates or ['basic_package'] templates = [] for tmpl_name in asked_tmpls: self.extend_templates(templates, tmpl_name) if self.options.list_variables: return self.list_variables(templates) if self.verbose: print 'Selected and implied templates:' max_tmpl_name = max( [len(tmpl_name) for tmpl_name, tmpl in templates]) for tmpl_name, tmpl in templates: print ' %s%s %s' % (tmpl_name, ' ' * (max_tmpl_name - len(tmpl_name)), tmpl.summary) print if not self.args: if self.interactive: dist_name = self.challenge('Enter project name') else: raise BadCommand('You must provide a PACKAGE_NAME') else: dist_name = self.args[0].lstrip(os.path.sep) templates = [tmpl for name, tmpl in templates] output_dir = os.path.join(self.options.output_dir, dist_name) pkg_name = self._bad_chars_re.sub('', dist_name.lower()) vars = { 'project': dist_name, 'package': pkg_name, 'egg': pluginlib.egg_name(dist_name), } vars.update(self.parse_vars(self.args[1:])) if self.options.config and os.path.exists(self.options.config): for key, value in self.read_vars(self.options.config).items(): vars.setdefault(key, value) if self.verbose: # @@: > 1? self.display_vars(vars) if self.options.inspect_files: self.inspect_files(output_dir, templates, vars) return if not os.path.exists(output_dir): # We want to avoid asking questions in copydir if the path # doesn't exist yet copydir.all_answer = 'y' if self.options.svn_repository: self.setup_svn_repository(output_dir, dist_name) # First we want to make sure all the templates get a chance to # set their variables, all at once, with the most specialized # template going first (the last template is the most # specialized)... for template in templates[::-1]: vars = template.check_vars(vars, self) # Gather all the templates egg_plugins into one var egg_plugins = set() for template in templates: egg_plugins.update(template.egg_plugins) egg_plugins = list(egg_plugins) egg_plugins.sort() vars['egg_plugins'] = egg_plugins for template in templates: self.create_template(template, output_dir, vars) found_setup_py = False paster_plugins_mtime = None if os.path.exists(os.path.join(output_dir, 'setup.py')): # Grab paster_plugins.txt's mtime; used to determine if the # egg_info command wrote to it try: egg_info_dir = pluginlib.egg_info_dir(output_dir, dist_name) except IOError: egg_info_dir = None if egg_info_dir is not None: plugins_path = os.path.join(egg_info_dir, 'paster_plugins.txt') if os.path.exists(plugins_path): paster_plugins_mtime = os.path.getmtime(plugins_path) self.run_command( sys.executable, 'setup.py', 'egg_info', cwd=output_dir, # This shouldn't be necessary, but a bug in setuptools 0.6c3 is causing a (not entirely fatal) problem that I don't want to fix right now: expect_returncode=True) found_setup_py = True elif self.verbose > 1: print 'No setup.py (cannot run egg_info)' package_dir = vars.get('package_dir', None) if package_dir: output_dir = os.path.join(output_dir, package_dir) # With no setup.py this doesn't make sense: if found_setup_py: # Only write paster_plugins.txt if it wasn't written by # egg_info (the correct way). leaving us to do it is # deprecated and you'll get warned egg_info_dir = pluginlib.egg_info_dir(output_dir, dist_name) plugins_path = os.path.join(egg_info_dir, 'paster_plugins.txt') if len(egg_plugins) and (not os.path.exists(plugins_path) or \ os.path.getmtime(plugins_path) == paster_plugins_mtime): if self.verbose: print >> sys.stderr, \ ('Manually creating paster_plugins.txt (deprecated! ' 'pass a paster_plugins keyword to setup() instead)') for plugin in egg_plugins: if self.verbose: print 'Adding %s to paster_plugins.txt' % plugin if not self.simulate: pluginlib.add_plugin(egg_info_dir, plugin) if self.options.svn_repository: self.add_svn_repository(vars, output_dir) if self.options.config: write_vars = vars.copy() del write_vars['project'] del write_vars['package'] self.write_vars(self.options.config, write_vars)