def __dump_deps_file(self, project): dest = self.config.get('deps_file_dest', None) target = self.config.get('deps_file_target') if dest is None: info("Not dumping deps file") return info("Dumping deps file to %s with target %s" % (dest, target)) destdir = os.path.dirname(dest) if not os.path.exists(destdir): os.makedirs(destdir) empty_targets = [] with open(dest, 'w', encoding='utf-8') as _: _.write(u'%s: ' % target) for dep in self.config.get_dependencies(): empty_targets.append(dep) _.write(u'%s ' % dep.replace(' ', '\\ ')) self.__dump_project_deps_file(project, _, empty_targets) for empty_target in empty_targets: _.write(u'\n\n%s:' % empty_target)
def __persist(self): if self.dry: return info('Persisting database and private files', 'persisting') self.database.persist()
def __dump_deps_file(self): dest = self.config.get('deps_file_dest') target = self.config.get('deps_file_target') if dest is None: info("Not dumping deps file") return info("Dumping deps file to %s with target %s" % (dest, target)) destdir = os.path.dirname(dest) if not os.path.exists(destdir): os.makedirs(destdir) empty_targets = [] with io.open(dest, 'w', encoding='utf-8') as _: _.write(u'%s: ' % target) if self.config: for dep in self.config.get_dependencies(): empty_targets.append(dep) _.write(u'%s ' % dep) if self.doc_tree: for page in self.doc_tree.get_pages().values(): if not page.generated: empty_targets.append(page.source_file) _.write(u'%s ' % page.source_file) for empty_target in empty_targets: _.write(u'\n\n%s:' % empty_target)
def gather_gtk_doc_links(): global GATHERED_GTKDOC_LINKS if GATHERED_GTKDOC_LINKS: return GATHERED_GTKDOC_LINKS = True # XDG_DATA_DIRS is preference-ordered, we reverse so that preferred # links override less-preferred ones for datadir in reversed([XDG_DATA_HOME] + XDG_DATA_DIRS): for path in (os.path.join(datadir, 'devhelp', 'books'), os.path.join(datadir, 'gtk-doc', 'html')): if not os.path.exists(path): info("no gtk doc to gather links from in %s" % path) continue for node in os.listdir(path): dir_ = os.path.join(path, node) if os.path.isdir(dir_): if not parse_devhelp_index(dir_): try: parse_sgml_index(dir_) except IOError: pass
def setup(self): """ Banana banana """ configurable_classes = all_subclasses(Configurable) configured = set() for subclass in configurable_classes: if subclass.parse_config not in configured: subclass.parse_config(self, self.config) configured.add(subclass.parse_config) self.__parse_config() self.doc_tree = DocTree(self.get_private_folder(), self.include_paths) for extension in self.extensions.values(): info('Setting up %s' % extension.extension_name) extension.setup() self.doc_database.flush() sitemap = SitemapParser().parse(self.sitemap_path) self.doc_tree.parse_sitemap(self.change_tracker, sitemap) info("Resolving symbols", 'resolution') self.doc_tree.resolve_symbols(self.doc_database, self.link_resolver) self.doc_database.flush()
def __get_extra_extension_classes(paths): """ Banana banana """ extra_classes = [] wset = pkg_resources.WorkingSet([]) distributions, _ = wset.find_plugins(pkg_resources.Environment(paths)) for dist in distributions: sys.path.append(dist.location) wset.add(dist) for entry_point in wset.iter_entry_points(group='hotdoc.extensions', name='get_extension_classes'): try: activation_function = entry_point.load() classes = activation_function() # pylint: disable=broad-except except Exception as exc: info("Failed to load %s %s" % (entry_point.module_name, exc)) debug(traceback.format_exc()) continue for klass in classes: extra_classes.append(klass) return extra_classes
def _split_repo_url(repo_url): sub_path = '' addr = urllib.parse.urlparse(repo_url) # Avoid blocking on password prompts env = os.environ.copy() env['GIT_ASKPASS'] = '******' while True: try: args = ['git', 'ls-remote', repo_url] info('Checking if {} is a git repo'.format(' '.join(args)), domain='git-uploader') subprocess.check_output(args, env=env, stderr=subprocess.STDOUT) return repo_url, sub_path except subprocess.CalledProcessError as e: info('No; {}'.format(e.output.decode('utf-8')), domain='git-uploader') sub_path = os.path.join(os.path.basename(addr.path), sub_path) addr = urllib.parse.ParseResult(addr.scheme, addr.netloc, os.path.dirname(addr.path), addr.params, addr.query, addr.fragment) if repo_url == addr.geturl(): break repo_url = addr.geturl() return None, None
def format_page(self, page, link_resolver, output, extensions): """ Banana banana """ info('formatting %s' % page.source_file, 'formatting') extension = extensions[page.extension_name] extension.format_page(page, link_resolver, output)
def format_page(self, page, link_resolver, output, extensions): """ Banana banana """ info('formatting %s' % page.source_file, 'formatting') extension = extensions[page.extension_name] extension.format_page(page, link_resolver, output)
def __dump_deps_file(self): dest = self.config.get('deps_file_dest') target = self.config.get('deps_file_target') if dest is None: info("Not dumping deps file") return info("Dumping deps file to %s with target %s" % (dest, target)) destdir = os.path.dirname(dest) if not os.path.exists(destdir): os.makedirs(destdir) empty_targets = [] with io.open(dest, 'w', encoding='utf-8') as _: _.write(u'%s: ' % target) if self.config: for dep in self.config.get_dependencies(): empty_targets.append(dep) _.write(u'%s ' % dep) if self.doc_tree: for page in self.doc_tree.get_pages().values(): if not page.generated: empty_targets.append(page.source_file) _.write(u'%s ' % page.source_file) for empty_target in empty_targets: _.write(u'\n\n%s:' % empty_target)
def setup(self): """ Banana banana """ configurable_classes = all_subclasses(Configurable) configured = set() for subclass in configurable_classes: if subclass.parse_config not in configured: subclass.parse_config(self, self.config) configured.add(subclass.parse_config) self.__parse_config() self.doc_tree = DocTree(self.get_private_folder(), self.include_paths) for extension in self.extensions.values(): info('Setting up %s' % extension.extension_name) extension.setup() self.doc_database.flush() sitemap = SitemapParser().parse(self.sitemap_path) self.doc_tree.parse_sitemap(self.change_tracker, sitemap) info("Resolving symbols", 'resolution') self.doc_tree.resolve_symbols(self.doc_database, self.link_resolver) self.doc_database.flush()
def __persist(self): if self.dry: return info('Persisting database and private files', 'persisting') self.database.persist() self.__dump_deps_file(self.project)
def finalize(self): """ Banana banana """ self.formatted_signal.clear() if self.doc_database is not None: info('Closing database') self.doc_database.close()
def finalize(self): """ Banana banana """ self.formatted_signal.clear() if self.doc_database is not None: info('Closing database') self.doc_database.close()
def info(self, message, domain=None): """ Shortcut function for `utils.loggable.info` Args: message: see `utils.loggable.info` domain: see `utils.loggable.info` """ if domain is None: domain = self.extension_name info(message, domain)
def info(self, message, domain=None): """ Shortcut function for `utils.loggable.info` Args: message: see `utils.loggable.info` domain: see `utils.loggable.info` """ if domain is None: domain = self.extension_name info(message, domain)
def __persist(self, project): if self.dry: return info('Persisting database and private files', 'persisting') project.persist() self.database.persist() with open(os.path.join(self.private_folder, 'change_tracker.p'), 'wb') as _: _.write(pickle.dumps(self.change_tracker)) self.__dump_deps_file(project)
def get_extension_classes(sort, extra_extension_paths=None): """ Banana banana """ all_classes = {} deps_map = {} for entry_point in pkg_resources.iter_entry_points( group='hotdoc.extensions', name='get_extension_classes'): if entry_point.module_name == 'hotdoc_c_extension.extensions': continue try: activation_function = entry_point.load() classes = activation_function() # pylint: disable=broad-except except Exception as exc: info("Failed to load %s" % entry_point.module_name, exc) debug(traceback.format_exc()) continue for klass in classes: all_classes[klass.extension_name] = klass if extra_extension_paths: for klass in __get_extra_extension_classes(extra_extension_paths): all_classes[klass.extension_name] = klass klass_list = list(all_classes.values()) if not sort: return klass_list for i, klass in enumerate(klass_list): deps = klass.get_dependencies() topodeps = set() for dep in deps: if dep.dependency_name not in all_classes: if dep.optional: continue else: error( "setup-issue", "Missing dependency %s for %s" % (dep.dependency_name, klass.extension_name)) if dep.is_upstream: topodeps.add(klass_list.index( all_classes[dep.dependency_name])) deps_map[i] = topodeps sorted_class_indices = toposort_flatten(deps_map) sorted_classes = [klass_list[i] for i in sorted_class_indices] return sorted_classes
def gather_gtk_doc_links(): gtkdoc_dir = os.path.join(DATADIR, "gtk-doc", "html") if not os.path.exists(gtkdoc_dir): info("no gtk doc to gather links from in %s" % gtkdoc_dir) return for node in os.listdir(gtkdoc_dir): dir_ = os.path.join(gtkdoc_dir, node) if os.path.isdir(dir_): if not parse_devhelp_index(dir_): try: parse_sgml_index(dir_) except IOError: pass
def format(self, link_resolver, output, extensions): """Banana banana """ info('Formatting documentation tree', 'formatting') self.__setup_folder(output) link_resolver.get_link_signal.connect(self.__get_link_cb) # Page.formatting_signal.connect(self.__formatting_page_cb) # Link.resolving_link_signal.connect(self.__link_referenced_cb) for page in self.walk(): self.format_page(page, link_resolver, output, extensions) link_resolver.get_link_signal.disconnect(self.__get_link_cb) self.__create_navigation_script(output, extensions)
def format(self, link_resolver, output, extensions): """Banana banana """ info('Formatting documentation tree', 'formatting') self.__setup_folder(output) link_resolver.get_link_signal.connect(self.__get_link_cb) # Page.formatting_signal.connect(self.__formatting_page_cb) # Link.resolving_link_signal.connect(self.__link_referenced_cb) for page in self.walk(): self.format_page(page, link_resolver, output, extensions) link_resolver.get_link_signal.disconnect(self.__get_link_cb) self.__create_navigation_script(output, extensions)
def __create_change_tracker(self): try: self.change_tracker = \ pickle.load(open(os.path.join(self.get_private_folder(), 'change_tracker.p'), 'rb')) if self.change_tracker.hard_dependencies_are_stale(): raise IOError self.incremental = True info("Building incrementally") # pylint: disable=broad-except except Exception: info("Building from scratch") shutil.rmtree(self.get_private_folder(), ignore_errors=True) if self.output: shutil.rmtree(self.output, ignore_errors=True) self.change_tracker = ChangeTracker()
def persist(self): """ Banana banana """ if self.__dry: return info('Persisting database and private files', 'persisting') self.doc_tree.persist() self.doc_database.persist() pickle.dump(self.change_tracker, open(os.path.join(self.get_private_folder(), 'change_tracker.p'), 'wb')) self.__dump_deps_file()
def setup(self) -> None: super().setup() if not self._data_file: info('Meson refman extension DISABLED') return raw = Path(self._data_file).read_text(encoding='utf-8') self._data = loads(raw) # Register formater for ext in self.project.extensions.values(): ext = T.cast(Extension, ext) ext.formatter.formatting_page_signal.connect( self._formatting_page_cb) info('Meson refman extension LOADED')
def __create_change_tracker(self): try: self.change_tracker = \ pickle.load(open(os.path.join(self.get_private_folder(), 'change_tracker.p'), 'rb')) if self.change_tracker.hard_dependencies_are_stale(): raise IOError self.incremental = True info("Building incrementally") # pylint: disable=broad-except except Exception: info("Building from scratch") shutil.rmtree(self.get_private_folder(), ignore_errors=True) if self.output: shutil.rmtree(self.output, ignore_errors=True) self.change_tracker = ChangeTracker()
def persist(self): """ Banana banana """ if self.__dry: return info('Persisting database and private files', 'persisting') self.doc_tree.persist() self.doc_database.persist() pickle.dump( self.change_tracker, open(os.path.join(self.get_private_folder(), 'change_tracker.p'), 'wb')) self.__dump_deps_file()
def parse_config(doc_repo, config): """Banana banana """ html_theme = config.get('html_theme', 'default') if html_theme == 'default': default_theme = os.path.join(HERE, '..', 'default_theme-%s' % THEME_VERSION) html_theme = os.path.abspath(default_theme) info("Using default theme") else: html_theme = config.get_path('html_theme') info("Using theme located at %s" % html_theme) HtmlFormatter.theme_path = html_theme HtmlFormatter.add_anchors = bool(config.get("html_add_anchors")) HtmlFormatter.number_headings = bool( config.get("html_number_headings"))
def __create_change_tracker(self, disable_incremental): if not disable_incremental: try: with open(os.path.join(self.private_folder, 'change_tracker.p'), 'rb') as _: self.change_tracker = pickle.loads(_.read()) if self.change_tracker.hard_dependencies_are_stale(): raise IOError self.incremental = True info("Building incrementally") # pylint: disable=broad-except except Exception: pass if not self.incremental: info("Building from scratch") shutil.rmtree(self.private_folder, ignore_errors=True) self.change_tracker = ChangeTracker()
def parse_config(doc_repo, config): """Banana banana """ html_theme = config.get('html_theme', 'default') if html_theme == 'default': default_theme = os.path.join(HERE, '..', 'default_theme-%s' % THEME_VERSION) html_theme = os.path.abspath(default_theme) info("Using default theme") else: html_theme = config.get_path('html_theme') info("Using theme located at %s" % html_theme) HtmlFormatter.theme_path = html_theme HtmlFormatter.extra_theme_path = config.get_path('html_extra_theme') HtmlFormatter.add_anchors = bool(config.get("html_add_anchors")) HtmlFormatter.number_headings = bool( config.get("html_number_headings"))
def parse_config(self, config): self.c_sources = config.get_sources('gst_c') self.cache_file = config.get('gst_cache_file') self.plugin = config.get('gst_plugin_name') self.list_plugins_page = config.get('gst_list_plugins_page', None) info('Parsing config!') self.cache = {} if self.cache_file: self.cache = GstExtension.__caches.get(self.cache_file) if not self.cache: try: with open(self.cache_file) as _: self.cache = json.load(_) except FileNotFoundError: pass if self.cache is None: self.cache = {} GstExtension.__caches[self.cache_file] = self.cache super().parse_config(config)
def setup(self): """ Banana banana """ info('Setting up %s' % self.project_name, 'project') for extension in list(self.extensions.values()): info('Setting up %s' % extension.extension_name) extension.setup() sitemap = SitemapParser().parse(self.sitemap_path) self.tree.build(sitemap, self.extensions) info("Resolving symbols", 'resolution') self.tree.resolve_symbols(self.app.database, self.app.link_resolver)
def setup(self): """ Banana banana """ info('Setting up %s' % self.project_name, 'project') self.app.database.comment_updated_signal.connect( self.__comment_updated_cb) for extension in list(self.extensions.values()): info('Setting up %s' % extension.extension_name) extension.setup() self.app.database.comment_updated_signal.disconnect( self.__comment_updated_cb) sitemap = SitemapParser().parse(self.sitemap_path) self.tree.parse_sitemap(sitemap) self.page_map.update({p: self for p in self.tree.get_pages().values()}) info("Resolving symbols", 'resolution') self.tree.resolve_symbols(self.app.database, self.app.link_resolver)
def finalize(self): if self.database is not None: info('Closing database') self.database.close() self.project.finalize()