def write(self, target, path, confs=None): def as_jar(internal_target): jar, _, _, _ = self.get_db(internal_target).as_jar_with_version( internal_target) return jar # TODO(John Sirois): a dict is used here to de-dup codegen targets which have both the original # codegen target - say java_thrift_library - and the synthetic generated target (java_library) # Consider reworking codegen tasks to add removal of the original codegen targets when rewriting # the graph dependencies = OrderedDict() internal_codegen = {} for dep in target_internal_dependencies(target): jar = as_jar(dep) dependencies[(jar.org, jar.name)] = self.internaldep(jar, dep) if dep.is_codegen: internal_codegen[jar.name] = jar.name for jar in target.jar_dependencies: if jar.rev: dependencies[(jar.org, jar.name)] = self.jardep(jar) target_jar = self.internaldep( as_jar(target)).extend(dependencies=dependencies.values()) template_kwargs = self.templateargs(target_jar, confs) with safe_open(path, 'w') as output: template = pkgutil.get_data(__name__, self.template_relpath) Generator(template, **template_kwargs).write(output)
def _gen_goals_reference(self): """Generate the goals reference rst doc.""" phase_dict = {} phase_names = [] for phase, raw_goals in Phase.all(): goals = [] for g in raw_goals: # TODO(lahosken) generalize indent_docstring, use here doc = (g.task_type.__doc__ or "").replace("\n", " ").strip() goals.append(TemplateData(name=g.task_type.__name__, doc=doc)) phase_dict[phase.name] = TemplateData(phase=phase, goals=goals) phase_names.append(phase.name) phases = [ phase_dict[name] for name in sorted(phase_names, key=str.lower) ] template = resource_string( __name__, os.path.join(self._templates_dir, 'goals_reference.mustache')) filename = os.path.join(self._outdir, 'goals_reference.rst') self.context.log.info('Generating %s' % filename) with safe_open(filename, 'w') as outfile: generator = Generator(template, phases=phases) generator.write(outfile)
def build(self, targets, _): template_path = os.path.join(_TEMPLATE_BASEDIR, 'doc.mustache') template = pkgutil.get_data(__name__, template_path) for target in targets: assert is_doc(target), 'DocBuilder can only build DocTargets, given %s' % str(target) base_dir = os.path.dirname(target.address.buildfile.full_path) target_base = target.target_base print('building doc for %s' % str(target)) output_dir = os.path.normpath(os.path.join(self.root_dir, target.id)) if not os.path.exists(output_dir): os.makedirs(output_dir) for filename in target.sources: if filename.endswith('md'): if not HAS_MARKDOWN: print('Missing markdown, cannot process %s' % filename, file=sys.stderr) else: print('processing %s' % filename) html_filename = os.path.splitext(filename)[0] + '.html' output_filename = os.path.join(output_dir, os.path.basename(html_filename)) print('writing file to %s' % output_filename) with open(output_filename, 'w') as output: with open(os.path.join(target_base, filename), 'r') as md: contents = md.read() md_html = markdown.markdown(contents) generator = Generator(template, root_dir = self.root_dir, text = md_html) generator.write(output) for filename in target.resources: full_filepath = os.path.join(target_base, filename) target_file = os.path.join(output_dir, os.path.relpath(full_filepath, base_dir)) print('copying %s to %s' % (filename, target_file)) if not os.path.exists(os.path.dirname(target_file)): os.makedirs(os.path.dirname(target_file)) shutil.copy(full_filepath, target_file) return 0
def _generate(cls, root_dir, template, template_data, output_filename): with open(output_filename, 'w') as output: template_path = os.path.join(_TEMPLATE_BASEDIR, '%s.mk' % template) generator = Generator(pkgutil.get_data(__name__, template_path), root_dir=root_dir, lib=template_data) generator.write(output)
def _create_ivy_file(self, target, target_path): ivy_file = os.path.abspath(os.path.join(target_path, 'ivy.xml')) template_data = target._create_template_data() template_path = os.path.join('ivy_resolve', 'ivy.mustache') generator = Generator(pkgutil.get_data('twitter.pants.tasks', template_path), root_dir=self.root_dir, lib=template_data) with open(ivy_file, 'w') as outfile: generator.write(outfile) return ivy_file
def generate_ivysettings(self, publishedjars, publish_local=None): template_relpath = os.path.join('templates', 'jar_publish', 'ivysettings.mustache') template = pkgutil.get_data(__name__, template_relpath) with safe_open(os.path.join(self.outdir, 'ivysettings.xml'), 'w') as wrapper: generator = Generator(template, ivysettings=self.ivysettings, dir=self.outdir, cachedir=self.cachedir, published=[TemplateData(org=jar.org, name=jar.name) for jar in publishedjars], publish_local=publish_local) generator.write(wrapper) return wrapper.name
def execute(self, targets): self._gen_goals_reference() d = assemble() template = resource_string( __name__, os.path.join(self._templates_dir, 'page.mustache')) tocs = [ tocl(d), tags_tocl(d, ["java", "scala", "jvm", "anylang"], "JVM"), tags_tocl(d, ["python", "anylang"], "Python") ] defns = [d[t]["defn"] for t in sorted(d.keys(), key=str.lower)] filename = os.path.join(self._outdir, 'build_dictionary.rst') self.context.log.info('Generating %s' % filename) with safe_open(filename, 'w') as outfile: generator = Generator(template, tocs=tocs, defns=defns) generator.write(outfile)
def _generate_ivy(self, jars, excludes, ivyxml): org, name = self._ivy_utils.identify() template_data = TemplateData( org=org, module=name, version='latest.integration', publications=None, is_idl=False, dependencies=[self._generate_jar_template(jar) for jar in jars], excludes=[self._generate_exclude_template(exclude) for exclude in excludes] ) safe_mkdir(os.path.dirname(ivyxml)) with open(ivyxml, 'w') as output: generator = Generator(pkgutil.get_data(__name__, self._template_path), root_dir = get_buildroot(), lib = template_data) generator.write(output)
def generate_project(self, project): def is_test(source_set): # Non test targets that otherwise live in test target roots (say a java_library), must # be marked as test for IDEA to correctly link the targets with the test code that uses # them. Therefore we check the base instead of the is_test flag. return source_set.source_base in SourceSet.TEST_BASES def create_content_root(source_set): root_relative_path = os.path.join(source_set.source_base, source_set.path) \ if source_set.path else source_set.source_base sources = TemplateData(path=root_relative_path, package_prefix=source_set.path.replace( '/', '.') if source_set.path else None, is_test=is_test(source_set)) return TemplateData( path=root_relative_path, sources=[sources], exclude_paths=[ os.path.join(source_set.source_base, x) for x in source_set.excludes ], ) content_roots = [ create_content_root(source_set) for source_set in project.sources ] if project.has_python: content_roots.extend( create_content_root(source_set) for source_set in project.py_sources) scala = None if project.has_scala: scala = TemplateData( language_level=self.scala_language_level, maximum_heap_size=self.scala_maximum_heap_size, fsc=self.fsc, compiler_classpath=project.scala_compiler_classpath) configured_module = TemplateData( root_dir=get_buildroot(), path=self.module_filename, content_roots=content_roots, bash=self.bash, python=project.has_python, scala=scala, internal_jars=[cp_entry.jar for cp_entry in project.internal_jars], internal_source_jars=[ cp_entry.source_jar for cp_entry in project.internal_jars if cp_entry.source_jar ], external_jars=[cp_entry.jar for cp_entry in project.external_jars], external_javadoc_jars=[ cp_entry.javadoc_jar for cp_entry in project.external_jars if cp_entry.javadoc_jar ], external_source_jars=[ cp_entry.source_jar for cp_entry in project.external_jars if cp_entry.source_jar ], extra_components=[], ) outdir = os.path.abspath(self.intellij_output_dir) if not os.path.exists(outdir): os.makedirs(outdir) configured_project = TemplateData( root_dir=get_buildroot(), outdir=outdir, modules=[configured_module], java=TemplateData(encoding=self.java_encoding, maximum_heap_size=self.java_maximum_heap_size, jdk=self.java_jdk, language_level='JDK_1_%d' % self.java_language_level), resource_extensions=list(project.resource_extensions), scala=scala, checkstyle_suppression_files=','.join( project.checkstyle_suppression_files), checkstyle_classpath=';'.join(project.checkstyle_classpath), debug_port=project.debug_port, extra_components=[], ) existing_project_components = None existing_module_components = None if not self.nomerge: # Grab the existing components, which may include customized ones. existing_project_components = self._parse_xml_component_elements( self.project_filename) existing_module_components = self._parse_xml_component_elements( self.module_filename) # Generate (without merging in any extra components). safe_mkdir(os.path.abspath(self.intellij_output_dir)) ipr = self._generate_to_tempfile( Generator(pkgutil.get_data(__name__, self.project_template), project=configured_project)) iml = self._generate_to_tempfile( Generator(pkgutil.get_data(__name__, self.module_template), module=configured_module)) if not self.nomerge: # Get the names of the components we generated, and then delete the # generated files. Clunky, but performance is not an issue, and this # is an easy way to get those component names from the templates. extra_project_components = self._get_components_to_merge( existing_project_components, ipr) extra_module_components = self._get_components_to_merge( existing_module_components, iml) os.remove(ipr) os.remove(iml) # Generate again, with the extra components. ipr = self._generate_to_tempfile( Generator(pkgutil.get_data(__name__, self.project_template), project=configured_project.extend( extra_components=extra_project_components))) iml = self._generate_to_tempfile( Generator(pkgutil.get_data(__name__, self.module_template), module=configured_module.extend( extra_components=extra_module_components))) shutil.move(ipr, self.project_filename) shutil.move(iml, self.module_filename) print('\nGenerated project at %s%s' % (self.work_dir, os.sep)) return self.project_filename if self.open else None
def _generate_project_files(self, project, ivyfile, ivysettingsfile): def create_content_root(source_set): root_relative_path = os.path.join(source_set.source_base, source_set.path) return TemplateData( path=root_relative_path, sources=[ TemplateData( path=root_relative_path, package_prefix=source_set.path.replace('/', '.'), is_test=source_set.is_test, ) ], exclude_paths=[ os.path.join(source_set.source_base, x) for x in source_set.excludes ], ) configured_module = TemplateData( root_dir=self.root_dir, path=self.module_filename, content_roots=[ create_content_root(source_set) for source_set in project.sources ], has_bash=self.options.bash, has_python=project.has_python, has_scala=project.has_scala, has_tests=project.has_tests, has_ivy=True, ivyfile=ivyfile, ivysettingsfile=ivysettingsfile, extra_components=[], ) outdir = os.path.abspath(self.options.intellij_output_dir) if not os.path.exists(outdir): os.makedirs(outdir) configured_project = TemplateData( root_dir=self.root_dir, outdir=outdir, modules=[configured_module], java_encoding=self.options.java_encoding, resource_extensions=self._get_resource_extensions(project), has_scala=project.has_scala, scala=TemplateData( fsc=self.options.fsc) if project.has_scala else None, extra_checkstyle_suppression_files=project. extra_checkstyle_suppression_files, extra_components=[], ) if not self.options.nomerge: # Grab the existing components, which may include customized ones. existing_project_components = self._parse_xml_component_elements( self.project_filename) existing_module_components = self._parse_xml_component_elements( self.module_filename) # Generate (without merging in any extra components). ipr = self._generate_to_tempfile( Generator(pkgutil.get_data(__name__, self.project_template), project=configured_project)) iml = self._generate_to_tempfile( Generator(pkgutil.get_data(__name__, self.module_template), module=configured_module)) if not self.options.nomerge: # Get the names of the components we generated, and then delete the generated files. # Clunky, but performance is not an issue, and this is an easy way to get those component names # from the templates. extra_project_components = self._get_components_to_merge( existing_project_components, ipr) extra_module_components = self._get_components_to_merge( existing_module_components, iml) os.remove(ipr) os.remove(iml) # Generate again, with the extra components. ipr = self._generate_to_tempfile( Generator(pkgutil.get_data(__name__, self.project_template), project=configured_project.extend( extra_components=extra_project_components))) iml = self._generate_to_tempfile( Generator(pkgutil.get_data(__name__, self.module_template), module=configured_module.extend( extra_components=extra_module_components))) shutil.move(ipr, self.project_filename) shutil.move(iml, self.module_filename)
def apply_template(output_path, template_relpath, **template_data): with safe_open(output_path, 'w') as output: Generator(pkgutil.get_data(__name__, template_relpath), **template_data).write(output)
def generate_project(self, project): def linked_folder_id(path): return path.replace(os.path.sep, '.') def base_path(source_set): return os.path.join(source_set.root_dir, source_set.source_base) source_bases = {} def add_source_base(path, id): source_bases[path] = id for source_set in project.sources: add_source_base(base_path(source_set), linked_folder_id(source_set.source_base)) if project.has_python: for source_set in project.py_sources: add_source_base(base_path(source_set), linked_folder_id(source_set.source_base)) for source_set in project.py_libs: add_source_base(base_path(source_set), linked_folder_id(source_set.source_base)) def create_source_template(base, includes=None, excludes=None): return TemplateData( base=source_bases[base], includes=includes or [], excludes=excludes or [], joined_includes='|'.join(includes) if includes else '', joined_excludes='|'.join(excludes) if excludes else '', ) def create_sourcepath(base, sources): def normalize_path_pattern(path): return '%s/' % path if not path.endswith('/') else path includes = [ normalize_path_pattern(src_set.path) for src_set in sources if src_set.path ] excludes = [] for source_set in sources: excludes.extend( normalize_path_pattern(exclude) for exclude in source_set.excludes) return create_source_template(base, includes, excludes) pythonpaths = [] if project.has_python: for source_set in project.py_sources: pythonpaths.append( create_source_template(base_path(source_set))) for source_set in project.py_libs: lib_path = source_set.path if source_set.path.endswith( '.egg') else '%s/' % source_set.path pythonpaths.append( create_source_template(base_path(source_set), includes=[lib_path])) source_bases_list = [{ 'path': path, 'id': id } for (path, id) in source_bases.items()] configured_project = TemplateData( name=self.project_name, has_python=project.has_python, has_scala=project.has_scala and not project.skip_scala, source_bases=source_bases_list, pythonpaths=pythonpaths, debug_port=project.debug_port, ) outdir = os.path.abspath(os.path.join(self.work_dir, 'bin')) safe_mkdir(outdir) source_sets = defaultdict(OrderedSet) # base -> source_set for source_set in project.sources: source_sets[base_path(source_set)].add(source_set) sourcepaths = [ create_sourcepath(base, sources) for base, sources in source_sets.items() ] libs = [] def add_jarlibs(classpath_entries): for classpath_entry in classpath_entries: jar = classpath_entry.jar source_jar = classpath_entry.source_jar libs.append( TemplateData( jar=os.path.relpath(jar, self.cwd), source_jar=os.path.relpath(source_jar, self.cwd) if source_jar else None)) add_jarlibs(project.internal_jars) add_jarlibs(project.external_jars) configured_classpath = TemplateData( sourcepaths=sourcepaths, has_tests=project.has_tests, libs=libs, has_scala=project.has_scala, outdir=os.path.relpath(outdir, get_buildroot()), ) with safe_open(self.project_filename, 'w') as output: Generator(pkgutil.get_data(__name__, self.project_template), project=configured_project).write(output) with safe_open(self.classpath_filename, 'w') as output: Generator(pkgutil.get_data(__name__, self.classpath_template), classpath=configured_classpath).write(output) debug_filename = os.path.join( self.work_dir, 'Debug on port %d.launch' % project.debug_port) with safe_open(debug_filename, 'w') as output: Generator(pkgutil.get_data(__name__, self.debug_template), project=configured_project).write(output) for resource in _SETTINGS: with safe_open(os.path.join(self.cwd, '.settings', resource), 'w') as prefs: prefs.write( pkgutil.get_data( __name__, os.path.join('eclipse', 'files', resource))) factorypath = TemplateData( project_name=self.project_name, # The easiest way to make sure eclipse sees all annotation processors is to put all libs on # the apt factorypath - this does not seem to hurt eclipse performance in any noticeable way. jarpaths=[ "('%s', %s)" % (lib.jar, "'%s'" % lib.source_jar if lib.source_jar else 'None') for lib in libs ]) with open(self.apt_filename, 'w') as output: Generator(pkgutil.get_data(__name__, self.apt_template), factorypath=factorypath).write(output) if project.has_python: with safe_open(self.pydev_filename, 'w') as output: Generator(pkgutil.get_data(__name__, self.pydev_template), project=configured_project).write(output) else: if os.path.exists(self.pydev_filename): os.remove(self.pydev_filename) print('\nGenerated project at %s%s' % (self.work_dir, os.sep))
def generate_project(self, project): def create_content_root(source_set): root_relative_path = os.path.join(source_set.source_base, source_set.path) \ if source_set.path else source_set.source_base return TemplateData( path = root_relative_path, sources = [ TemplateData( path = root_relative_path, package_prefix = source_set.path.replace('/', '.') if source_set.path else None, is_test = source_set.is_test, ) ], exclude_paths = [ os.path.join(source_set.source_base, x) for x in source_set.excludes ], ) content_roots = [create_content_root(source_set) for source_set in project.sources] if project.has_python: content_roots.extend(create_content_root(source_set) for source_set in project.py_sources) configured_module = TemplateData( root_dir = get_buildroot(), path = self.module_filename, content_roots = content_roots, has_bash = self.bash, has_python = project.has_python, has_scala = project.has_scala, has_tests = project.has_tests, internal_jars = [cp_entry.jar for cp_entry in project.internal_jars], internal_source_jars = [cp_entry.source_jar for cp_entry in project.internal_jars if cp_entry.source_jar], external_jars = [cp_entry.jar for cp_entry in project.external_jars], external_source_jars = [cp_entry.source_jar for cp_entry in project.external_jars if cp_entry.source_jar], extra_components = [], ) outdir = os.path.abspath(self.intellij_output_dir) if not os.path.exists(outdir): os.makedirs(outdir) configured_project = TemplateData( root_dir = get_buildroot(), outdir = outdir, modules = [ configured_module ], java_encoding = self.java_encoding, resource_extensions = self._get_resource_extensions(project), has_scala = project.has_scala, scala_compiler_classpath = project.scala_compiler_classpath, scala = TemplateData(fsc = self.fsc) if project.has_scala else None, checkstyle_suppression_files = ','.join(project.checkstyle_suppression_files), checkstyle_classpath = ';'.join(project.checkstyle_classpath), debug_port=project.debug_port, extra_components = [], ) if not self.nomerge: # Grab the existing components, which may include customized ones. existing_project_components = self._parse_xml_component_elements(self.project_filename) existing_module_components = self._parse_xml_component_elements(self.module_filename) # Generate (without merging in any extra components). safe_mkdir(os.path.abspath(self.intellij_output_dir)) ipr = self._generate_to_tempfile( Generator(pkgutil.get_data(__name__, self.project_template), project = configured_project)) iml = self._generate_to_tempfile( Generator(pkgutil.get_data(__name__, self.module_template), module = configured_module)) if not self.nomerge: # Get the names of the components we generated, and then delete the # generated files. Clunky, but performance is not an issue, and this # is an easy way to get those component names from the templates. extra_project_components = self._get_components_to_merge(existing_project_components, ipr) extra_module_components = self._get_components_to_merge(existing_module_components, iml) os.remove(ipr) os.remove(iml) # Generate again, with the extra components. ipr = self._generate_to_tempfile(Generator(pkgutil.get_data(__name__, self.project_template), project = configured_project.extend(extra_components = extra_project_components))) iml = self._generate_to_tempfile(Generator(pkgutil.get_data(__name__, self.module_template), module = configured_module.extend(extra_components = extra_module_components))) shutil.move(ipr, self.project_filename) shutil.move(iml, self.module_filename) print('\nGenerated project at %s%s' % (self.work_dir, os.sep)) return self.project_filename if self.open else None
def _generate_project_files(self, project, ivyfile, ivysettingsfile): def create_sourcepath(base, sources): def normalize_path_pattern(path): return '%s/' % path if not path.endswith('/') else path includes = [ normalize_path_pattern(source_set.path) for source_set in sources ] excludes = [] for source_set in sources: excludes.extend( normalize_path_pattern(exclude) for exclude in source_set.excludes) return TemplateData( base=base, includes=includes, excludes=excludes, ) configured_project = TemplateData(name=self.project_name, has_python=project.has_python) ivyconfig = dict( ivyXmlPath=os.path.relpath(ivyfile, project.root_dir), confs='*', ivySettingsPath='file://%s' % ivysettingsfile, loadSettingsOnDemand='false', propertyFiles='', acceptedTypes='jar,bundle,ejb,maven-plugin', sourceTypes='source', javadocTypes='', sourceSuffixes='', javadocSuffixes='', alphaOrder='true', resolveInWorkspace='false', resolveBeforeLaunch='false', ) output_dir = os.path.join('target', 'eclipse') outdir = os.path.abspath(os.path.join(output_dir, 'bin')) if not os.path.exists(outdir): os.makedirs(outdir) source_sets = collections.defaultdict(OrderedSet) # base -> source_set for source_set in project.sources: source_sets[source_set.source_base].add(source_set) configured_classpath = TemplateData( sourcepaths=[ create_sourcepath(base, sources) for base, sources in source_sets.items() ], has_tests=project.has_tests, has_ivy=True, ivyconfig=urllib.urlencode(ivyconfig).replace('&', '&'), outdir=os.path.relpath(outdir, self.root_dir), ) with open(self.project_filename, 'w') as output: Generator(pkgutil.get_data(__name__, self.project_template), project=configured_project).write(output) with open(self.classpath_filename, 'w') as output: Generator(pkgutil.get_data(__name__, self.classpath_template), classpath=configured_classpath).write(output) if os.path.exists(self.apt_filename): os.remove(self.apt_filename) def has_apt(): apt_targets = [] def test_apt(t): if is_apt(t): apt_targets.append(t) for target in project.targets: target.walk(test_apt) if apt_targets: return True return False if has_apt(): libs_base_path = os.path.join(output_dir, 'libs') libdir = os.path.abspath(libs_base_path) if not os.path.exists(libdir): os.makedirs(libdir) print("Retrieving apt libs...") retrieve_result = subprocess.call([ 'java', '-jar', self.ivy_jar, '-warn', '-settings', ivysettingsfile, '-ivy', ivyfile, '-retrieve', '%s/%s/[conf]/[artifact].[ext]' % (self.root_dir, libs_base_path), '-types', 'jar', '-sync', '-symlink' ]) if retrieve_result != 0: print("Failed to retrieve apt libs.") return retrieve_result jarpaths = [] for path, _, filenames in os.walk(libdir): for filename in filenames: jarpaths.append(os.path.join(path, filename)) configured_factorypath = TemplateData(jarpaths=jarpaths) with open(self.apt_filename, 'w') as output: Generator(pkgutil.get_data(__name__, self.apt_template), factorypath=configured_factorypath).write(output) print("Generated apt config") if os.path.exists(self.pydev_filename): os.remove(self.pydev_filename) if project.has_python: with open(self.pydev_filename, 'w') as output: Generator(pkgutil.get_data(__name__, self.pydev_template), project=configured_project).write(output) return 0
def _generate_project_files(self, project, ivyfile, ivysettingsfile): def create_sourcepath(base, sources): def normalize_path_pattern(path): return '%s/' % path if not path.endswith('/') else path includes = [ normalize_path_pattern(source_set.path) for source_set in sources ] excludes = [] for source_set in sources: excludes.extend(normalize_path_pattern(exclude) for exclude in source_set.excludes) return TemplateData( base = base, includes = includes, excludes = excludes, ) configured_project = TemplateData( name = self.project_name, has_python = project.has_python ) ivyconfig = dict( ivyXmlPath = os.path.relpath(ivyfile, project.root_dir), confs = '*', ivySettingsPath = 'file://%s' % ivysettingsfile, loadSettingsOnDemand = 'false', propertyFiles = '', acceptedTypes = 'jar,bundle,ejb,maven-plugin', sourceTypes = 'source', javadocTypes = '', sourceSuffixes = '', javadocSuffixes = '', alphaOrder = 'true', resolveInWorkspace = 'false', resolveBeforeLaunch = 'false', ) outdir = os.path.abspath(self.options.eclipse_output_dir) if not os.path.exists(outdir): os.makedirs(outdir) source_sets = collections.defaultdict(OrderedSet) # base -> source_set for source_set in project.sources: source_sets[source_set.source_base].add(source_set) configured_classpath = TemplateData( sourcepaths = [ create_sourcepath(base, sources) for base, sources in source_sets.items() ], has_tests = project.has_tests, has_ivy = True, ivyconfig = urllib.urlencode(ivyconfig).replace('&', '&'), outdir = os.path.relpath(outdir, self.root_dir), ) with open(self.project_filename, 'w') as output: Generator(pkgutil.get_data(__name__, self.project_template), project = configured_project).write(output) with open(self.classpath_filename, 'w') as output: Generator(pkgutil.get_data(__name__, self.classpath_template), classpath = configured_classpath).write(output) if os.path.exists(self.pydev_filename): os.remove(self.pydev_filename) if project.has_python: with open(self.pydev_filename, 'w') as output: Generator(pkgutil.get_data(__name__, self.pydev_template), project = configured_project).write(output)