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 exec_doc(dependency): for dep_target in dependency.resolve(): # TODO: document how doc projects get nested # in pants_doc output if is_jvm(dep_target): self.execute_javadoc([dep_target], os.path.join(target_path, doc_target.id, dep_target.id)) if is_doc(dep_target) and not dep_target in targets: self.execute_pantsdoc([dep_target], os.path.join(target_path, doc_target.id, dep_target.id))
def _extract_java_sources_and_deps(self, targets): all_sources = [] all_deps = OrderedSet() for target in targets: if (not self.only_provides or is_exported(target)) and (not is_doc(target)): for source in target.sources: source_path = os.path.join(self.java_src_prefix, source) if os.path.exists(source_path): all_sources.append(source_path) else: print("skipping %s" % source_path) for jar_dep in target.jar_dependencies: if jar_dep.rev: all_deps.add(copy(jar_dep).intransitive()) return all_sources, all_deps
def _is_documentable(target): # TODO(John Sirois): support java_thrift_library, java_protobuf_library, pydoc and scaladoc return isinstance(target, JavaLibrary) or is_doc(target)