def setUp(self): import abjad app = self.Namespace() config = self.Namespace() self.app = app self.app.config = config self.app.config.abjadbook_ignored_documents = () self.app.builder = self.Namespace() self.app.builder.warn = print self.app.builder.current_docname = 'test' self.app.builder.status_iterator = lambda iterable, x, y, z: iter(iterable) self.app.builder.thumbnails = FilenameUniqDict() self.app.builder.outdir = os.path.dirname(os.path.abspath(__file__)) self.app.builder.imagedir = '_images' self.app.builder.imgpath = posixpath.join('..', '_images') self.app.builder.srcdir = os.path.join( abjad.__path__[0], 'docs', 'source', ) self.app.body = [] self.images_directory = os.path.join( self.app.builder.outdir, self.app.builder.imagedir, ) self.abjadbook_images_directory = os.path.join( self.images_directory, 'abjadbook', ) if os.path.exists(self.images_directory): shutil.rmtree(self.images_directory)
def on_builder_inited(app): app.builder.thumbnails = FilenameUniqDict() app.builder.imagedir = '_images' stylesheets_directory = os.path.join( app.builder.srcdir, '_stylesheets', ) image_directory = os.path.join( app.builder.outdir, app.builder.imagedir, 'abjadbook', ) if not os.path.exists(image_directory): os.makedirs(image_directory) if not os.path.exists(stylesheets_directory): os.makedirs(stylesheets_directory) default_stylesheet = os.path.join(stylesheets_directory, 'default.ly') if not os.path.exists(default_stylesheet): with open(default_stylesheet, 'w') as file_pointer: file_pointer.write('') for file_name in os.listdir(stylesheets_directory): if os.path.splitext(file_name)[-1] not in ('.ly', '.ily'): continue source_file_path = os.path.join( stylesheets_directory, file_name, ) shutil.copy(source_file_path, image_directory)
def initialize_videos_directive(app): """ Initializes the video directives. """ global DEFAULT_CONFIG config = copy.deepcopy(DEFAULT_CONFIG) config.update(app.config.videos_config) app.config.videos_config = config app.env.videos = FilenameUniqDict()
def initialize_simpleimages_directive(app): """ Initializes the image directives. """ global DEFAULT_CONFIG config = copy.deepcopy(DEFAULT_CONFIG) config.update(app.config.simpleimages_config) app.config.simpleimages_config = config app.env.images_mapping = FilenameUniqDict()
def initialize_videos_directive(app): """ Initializes the video directives. """ global DEFAULT_CONFIG config = copy.deepcopy(DEFAULT_CONFIG) config.update(app.config.videos_config) app.config.videos_config = config # ensuredir(os.path.join(app.env.srcdir, config['cache_path'])) # app.info("Initiated video directive: cache='{}'".format(config['cache_path'])) app.env.videos = FilenameUniqDict()
def on_builder_inited(app): app.env.thumbnails = FilenameUniqDict( ) # separate so Sphinx doesn't purge it install_lightbox_static_files(app) (pathlib.Path(app.builder.outdir) / "_images").mkdir(exist_ok=True)
def image_sphinx_app(sphinx_app, get_module_dir): sphinx_app.env.srcdir = get_module_dir sphinx_app.env.images = FilenameUniqDict() yield sphinx_app
def __init__(self, app): # type: (Sphinx) -> None self.app = app self.doctreedir = app.doctreedir self.srcdir = app.srcdir # type: unicode self.config = app.config # type: Config # the method of doctree versioning; see set_versioning_method self.versioning_condition = None # type: Union[bool, Callable] self.versioning_compare = None # type: bool # all the registered domains, set by the application self.domains = {} # the docutils settings for building self.settings = default_settings.copy() self.settings['env'] = self # the function to write warning messages with self._warnfunc = None # type: Callable # this is to invalidate old pickles self.version = ENV_VERSION # type: int # All "docnames" here are /-separated and relative and exclude # the source suffix. self.found_docs = set() # type: Set[unicode] # contains all existing docnames self.all_docs = {} # type: Dict[unicode, float] # docname -> mtime at the time of reading # contains all read docnames self.dependencies = defaultdict( set) # type: Dict[unicode, Set[unicode]] # docname -> set of dependent file # names, relative to documentation root self.included = set() # type: Set[unicode] # docnames included from other documents self.reread_always = set() # type: Set[unicode] # docnames to re-read unconditionally on # next build # File metadata self.metadata = defaultdict( dict) # type: Dict[unicode, Dict[unicode, Any]] # docname -> dict of metadata items # TOC inventory self.titles = {} # type: Dict[unicode, nodes.Node] # docname -> title node self.longtitles = {} # type: Dict[unicode, nodes.Node] # docname -> title node; only different if # set differently with title directive self.tocs = {} # type: Dict[unicode, nodes.Node] # docname -> table of contents nodetree self.toc_num_entries = {} # type: Dict[unicode, int] # docname -> number of real entries # used to determine when to show the TOC # in a sidebar (don't show if it's only one item) self.toc_secnumbers = { } # type: Dict[unicode, Dict[unicode, Tuple[int, ...]]] # docname -> dict of sectionid -> number self.toc_fignumbers = { } # type: Dict[unicode, Dict[unicode, Dict[unicode, Tuple[int, ...]]]] # NOQA # docname -> dict of figtype -> # dict of figureid -> number self.toctree_includes = {} # type: Dict[unicode, List[unicode]] # docname -> list of toctree includefiles self.files_to_rebuild = {} # type: Dict[unicode, Set[unicode]] # docname -> set of files # (containing its TOCs) to rebuild too self.glob_toctrees = set() # type: Set[unicode] # docnames that have :glob: toctrees self.numbered_toctrees = set() # type: Set[unicode] # docnames that have :numbered: toctrees # domain-specific inventories, here to be pickled self.domaindata = {} # type: Dict[unicode, Dict] # domainname -> domain-specific dict # Other inventories self.indexentries = { } # type: Dict[unicode, List[Tuple[unicode, unicode, unicode, unicode, unicode]]] # NOQA # docname -> list of # (type, unicode, target, aliasname) self.versionchanges = { } # type: Dict[unicode, List[Tuple[unicode, unicode, int, unicode, unicode, unicode]]] # NOQA # version -> list of (type, docname, # lineno, module, descname, content) # these map absolute path -> (docnames, unique filename) self.images = FilenameUniqDict() # type: FilenameUniqDict self.dlfiles = FilenameUniqDict() # type: FilenameUniqDict # the original URI for images self.original_image_uri = {} # type: Dict[unicode, unicode] # temporary data storage while reading a document self.temp_data = {} # type: Dict[unicode, Any] # context for cross-references (e.g. current module or class) # this is similar to temp_data, but will for example be copied to # attributes of "any" cross references self.ref_context = {} # type: Dict[unicode, Any]
def __init__(self, app: "Sphinx" = None): self.app = None # type: Sphinx self.doctreedir = None # type: str self.srcdir = None # type: str self.config = None # type: Config self.config_status = None # type: int self.config_status_extra = None # type: str self.events = None # type: EventManager self.project = None # type: Project self.version = None # type: Dict[str, str] # the method of doctree versioning; see set_versioning_method self.versioning_condition = None # type: Union[bool, Callable] self.versioning_compare = None # type: bool # all the registered domains, set by the application self.domains = {} # the docutils settings for building self.settings = default_settings.copy() self.settings['env'] = self # All "docnames" here are /-separated and relative and exclude # the source suffix. self.all_docs = {} # type: Dict[str, float] # docname -> mtime at the time of reading # contains all read docnames self.dependencies = defaultdict(set) # type: Dict[str, Set[str]] # docname -> set of dependent file # names, relative to documentation root self.included = defaultdict(set) # type: Dict[str, Set[str]] # docname -> set of included file # docnames included from other documents self.reread_always = set() # type: Set[str] # docnames to re-read unconditionally on # next build # File metadata self.metadata = defaultdict(dict) # type: Dict[str, Dict[str, Any]] # docname -> dict of metadata items # TOC inventory self.titles = {} # type: Dict[str, nodes.title] # docname -> title node self.longtitles = {} # type: Dict[str, nodes.title] # docname -> title node; only different if # set differently with title directive self.tocs = {} # type: Dict[str, nodes.bullet_list] # docname -> table of contents nodetree self.toc_num_entries = {} # type: Dict[str, int] # docname -> number of real entries # used to determine when to show the TOC # in a sidebar (don't show if it's only one item) self.toc_secnumbers = {} # type: Dict[str, Dict[str, Tuple[int, ...]]] # docname -> dict of sectionid -> number self.toc_fignumbers = { } # type: Dict[str, Dict[str, Dict[str, Tuple[int, ...]]]] # docname -> dict of figtype -> # dict of figureid -> number self.toctree_includes = {} # type: Dict[str, List[str]] # docname -> list of toctree includefiles self.files_to_rebuild = {} # type: Dict[str, Set[str]] # docname -> set of files # (containing its TOCs) to rebuild too self.glob_toctrees = set() # type: Set[str] # docnames that have :glob: toctrees self.numbered_toctrees = set() # type: Set[str] # docnames that have :numbered: toctrees # domain-specific inventories, here to be pickled self.domaindata = {} # type: Dict[str, Dict] # domainname -> domain-specific dict # these map absolute path -> (docnames, unique filename) self.images = FilenameUniqDict() # type: FilenameUniqDict self.dlfiles = DownloadFiles() # type: DownloadFiles # filename -> (set of docnames, destination) # the original URI for images self.original_image_uri = {} # type: Dict[str, str] # temporary data storage while reading a document self.temp_data = {} # type: Dict[str, Any] # context for cross-references (e.g. current module or class) # this is similar to temp_data, but will for example be copied to # attributes of "any" cross references self.ref_context = {} # type: Dict[str, Any] # set up environment if app: self.setup(app)