• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python environment.BuildEnvironment类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sphinx.environment.BuildEnvironment的典型用法代码示例。如果您正苦于以下问题:Python BuildEnvironment类的具体用法?Python BuildEnvironment怎么用?Python BuildEnvironment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了BuildEnvironment类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _init_env

    def _init_env(self, freshenv):
        if freshenv:
            self.env = BuildEnvironment(self.srcdir, self.doctreedir,
                                        self.config)
            self.env.find_files(self.config)
            for domain in self.domains.keys():
                self.env.domains[domain] = self.domains[domain](self.env)
        else:
            try:
                self.info(bold('loading pickled environment... '), nonl=True)
                self.env = BuildEnvironment.frompickle(self.config,
                    path.join(self.doctreedir, ENV_PICKLE_FILENAME))
                self.env.domains = {}
                for domain in self.domains.keys():
                    # this can raise if the data version doesn't fit
                    self.env.domains[domain] = self.domains[domain](self.env)
                self.info('done')
            except Exception as err:
                if type(err) is IOError and err.errno == ENOENT:
                    self.info('not yet created')
                else:
                    self.info('failed: %s' % err)
                return self._init_env(freshenv=True)

        self.env.set_warnfunc(self.warn)
开发者ID:Scalr,项目名称:sphinx,代码行数:25,代码来源:application.py


示例2: read_process

 def read_process(docs):
     # type: (List[unicode]) -> unicode
     self.env.app = self.app
     for docname in docs:
         self.read_doc(docname)
     # allow pickling self to send it back
     return BuildEnvironment.dumps(self.env)
开发者ID:papadeltasierra,项目名称:sphinx,代码行数:7,代码来源:__init__.py


示例3: _init_env

 def _init_env(self, freshenv):
     # type: (bool) -> None
     if freshenv:
         self.env = BuildEnvironment(self)
         self.env.find_files(self.config, self.builder)
         for domain in self.registry.create_domains(self.env):
             self.env.domains[domain.name] = domain
     else:
         try:
             logger.info(bold(__('loading pickled environment... ')), nonl=True)
             filename = path.join(self.doctreedir, ENV_PICKLE_FILENAME)
             self.env = BuildEnvironment.frompickle(filename, self)
             self.env.domains = {}
             for domain in self.registry.create_domains(self.env):
                 # this can raise if the data version doesn't fit
                 self.env.domains[domain.name] = domain
             logger.info(__('done'))
         except Exception as err:
             if isinstance(err, IOError) and err.errno == ENOENT:
                 logger.info(__('not yet created'))
             else:
                 logger.info(__('failed: %s'), err)
             self._init_env(freshenv=True)
开发者ID:marcosptf,项目名称:fedora,代码行数:23,代码来源:application.py


示例4: _init_env

 def _init_env(self, freshenv):
     # type: (bool) -> None
     filename = path.join(self.doctreedir, ENV_PICKLE_FILENAME)
     if freshenv or not os.path.exists(filename):
         self.env = BuildEnvironment(self)
         self.env.find_files(self.config, self.builder)
         for domain in self.registry.create_domains(self.env):
             self.env.domains[domain.name] = domain
     else:
         try:
             logger.info(bold(__('loading pickled environment... ')), nonl=True)
             self.env = BuildEnvironment.frompickle(filename, self)
             needed, reason = self.env.need_refresh(self)
             if needed:
                 raise IOError(reason)
             self.env.domains = {}
             for domain in self.registry.create_domains(self.env):
                 # this can raise if the data version doesn't fit
                 self.env.domains[domain.name] = domain
             logger.info(__('done'))
         except Exception as err:
             logger.info(__('failed: %s'), err)
             self._init_env(freshenv=True)
开发者ID:AWhetter,项目名称:sphinx,代码行数:23,代码来源:application.py


示例5: _init_env

 def _init_env(self, freshenv):
     # type: (bool) -> None
     filename = path.join(self.doctreedir, ENV_PICKLE_FILENAME)
     if freshenv or not os.path.exists(filename):
         self.env = BuildEnvironment()
         self.env.setup(self)
         self.env.find_files(self.config, self.builder)
     else:
         try:
             with progress_message(__('loading pickled environment')):
                 with open(filename, 'rb') as f:
                     self.env = pickle.load(f)
                     self.env.setup(self)
         except Exception as err:
             logger.info(__('failed: %s'), err)
             self._init_env(freshenv=True)
开发者ID:lmregus,项目名称:Portfolio,代码行数:16,代码来源:application.py


示例6: get_sphinx_environment

    def get_sphinx_environment(self):
        """
        Returns the Sphinx environment for this project.
        """
        from sphinx.environment import BuildEnvironment
        class Foo(object):
            pass
        config = Foo()
        config.values = []

        env_pickle = os.path.join(self._doctrees_dir(), 'environment.pickle')
        try:
            env = BuildEnvironment.frompickle(config, env_pickle)
            logger.debug("Opened Sphinx environment: %s", env_pickle)
            return env
        except IOError as err:
            logger.debug("Failed to open Sphinx environment: %s", err)
            pass
开发者ID:ppurka,项目名称:sagelib,代码行数:18,代码来源:builder.py


示例7: Sphinx


#.........这里部分代码省略.........
            raise VersionRequirementError(
                'This project needs at least Sphinx v%s and therefore cannot '
                'be built with this version.' % self.config.needs_sphinx)

        # set up translation infrastructure
        self._init_i18n()
        # set up the build environment
        self._init_env(freshenv)
        # set up the builder
        self._init_builder(buildername)

    def _init_i18n(self):
        """Load translated strings from the configured localedirs if enabled in
        the configuration.
        """
        if self.config.language is not None:
            self.info(bold('loading translations [%s]... ' %
                           self.config.language), nonl=True)
            locale_dirs = [None, path.join(package_dir, 'locale')] + \
                [path.join(self.srcdir, x) for x in self.config.locale_dirs]
        else:
            locale_dirs = []
        self.translator, has_translation = locale.init(locale_dirs,
                                                       self.config.language)
        if self.config.language is not None:
            if has_translation or self.config.language == 'en':
                # "en" never needs to be translated
                self.info('done')
            else:
                self.info('not available for built-in messages')

    def _init_env(self, freshenv):
        if freshenv:
            self.env = BuildEnvironment(self.srcdir, self.doctreedir,
                                        self.config)
            self.env.find_files(self.config)
            for domain in self.domains.keys():
                self.env.domains[domain] = self.domains[domain](self.env)
        else:
            try:
                self.info(bold('loading pickled environment... '), nonl=True)
                self.env = BuildEnvironment.frompickle(self.config,
                    path.join(self.doctreedir, ENV_PICKLE_FILENAME))
                self.env.domains = {}
                for domain in self.domains.keys():
                    # this can raise if the data version doesn't fit
                    self.env.domains[domain] = self.domains[domain](self.env)
                self.info('done')
            except Exception as err:
                if type(err) is IOError and err.errno == ENOENT:
                    self.info('not yet created')
                else:
                    self.info('failed: %s' % err)
                return self._init_env(freshenv=True)

        self.env.set_warnfunc(self.warn)

    def _init_builder(self, buildername):
        if buildername is None:
            print('No builder selected, using default: html', file=self._status)
            buildername = 'html'
        if buildername not in self.builderclasses:
            raise SphinxError('Builder name %s not registered' % buildername)

        builderclass = self.builderclasses[buildername]
        if isinstance(builderclass, tuple):
开发者ID:Scalr,项目名称:sphinx,代码行数:67,代码来源:application.py


示例8: Sphinx


#.........这里部分代码省略.........
                        "loaded version (%s)." % (extname, needs_ver, has_ver)
                    )

        # set up translation infrastructure
        self._init_i18n()
        # check all configuration values for permissible types
        self.config.check_types(self.warn)
        # set up the build environment
        self._init_env(freshenv)
        # set up the builder
        self._init_builder(buildername)

    def _init_i18n(self):
        """Load translated strings from the configured localedirs if enabled in
        the configuration.
        """
        if self.config.language is not None:
            self.info(bold("loading translations [%s]... " % self.config.language), nonl=True)
            locale_dirs = [None, path.join(package_dir, "locale")] + [
                path.join(self.srcdir, x) for x in self.config.locale_dirs
            ]
        else:
            locale_dirs = []
        self.translator, has_translation = locale.init(locale_dirs, self.config.language)
        if self.config.language is not None:
            if has_translation or self.config.language == "en":
                # "en" never needs to be translated
                self.info("done")
            else:
                self.info("not available for built-in messages")

    def _init_env(self, freshenv):
        if freshenv:
            self.env = BuildEnvironment(self.srcdir, self.doctreedir, self.config)
            self.env.find_files(self.config)
            for domain in self.domains.keys():
                self.env.domains[domain] = self.domains[domain](self.env)
        else:
            try:
                self.info(bold("loading pickled environment... "), nonl=True)
                self.env = BuildEnvironment.frompickle(self.config, path.join(self.doctreedir, ENV_PICKLE_FILENAME))
                self.env.domains = {}
                for domain in self.domains.keys():
                    # this can raise if the data version doesn't fit
                    self.env.domains[domain] = self.domains[domain](self.env)
                self.info("done")
            except Exception as err:
                if isinstance(err, IOError) and err.errno == ENOENT:
                    self.info("not yet created")
                else:
                    self.info("failed: %s" % err)
                return self._init_env(freshenv=True)

        self.env.set_warnfunc(self.warn)

    def _init_builder(self, buildername):
        if buildername is None:
            print("No builder selected, using default: html", file=self._status)
            buildername = "html"
        if buildername not in self.builderclasses:
            raise SphinxError("Builder name %s not registered" % buildername)

        builderclass = self.builderclasses[buildername]
        if isinstance(builderclass, tuple):
            # builtin builder
            mod, cls = builderclass
开发者ID:861008761,项目名称:standard_flask_web,代码行数:67,代码来源:application.py


示例9: merge

 def merge(docs, otherenv):
     # type: (List[unicode], unicode) -> None
     env = BuildEnvironment.loads(otherenv)
     self.env.merge_info_from(docs, env, self.app)
开发者ID:papadeltasierra,项目名称:sphinx,代码行数:4,代码来源:__init__.py


示例10: __init__

 def __init__(self, *args, **kwargs):
     self.main_tocs = {}
     BuildEnvironment.__init__(self, *args, **kwargs)
开发者ID:ambrice,项目名称:eclim,代码行数:3,代码来源:environment.py


示例11: Sphinx


#.........这里部分代码省略.........
        else:
            self._status = status
            self.quiet = False

        if warning is None:
            self._warning = StringIO()
        else:
            self._warning = warning
        self._warncount = 0
        self.warningiserror = warningiserror

        self._events = events.copy()

        # say hello to the world
        self.info(bold('Running Sphinx v%s' % sphinx.__version__))

        # status code for command-line application
        self.statuscode = 0

        # read config
        self.tags = Tags(tags)
        self.config = Config(confdir, CONFIG_FILENAME,
                             confoverrides or {}, self.tags)
        self.config.check_unicode(self.warn)

        # set confdir to srcdir if -C given (!= no confdir); a few pieces
        # of code expect a confdir to be set
        if self.confdir is None:
            self.confdir = self.srcdir

        # backwards compatibility: activate old C markup
        self.setup_extension('sphinx.ext.oldcmarkup')
        # load all user-given extension modules
        for extension in self.config.extensions:
            self.setup_extension(extension)
        # the config file itself can be an extension
        if self.config.setup:
            self.config.setup(self)

        # now that we know all config values, collect them from conf.py
        self.config.init_values()

        # check the Sphinx version if requested
        if self.config.needs_sphinx and \
           self.config.needs_sphinx > sphinx.__version__[:3]:
            raise VersionRequirementError(
                'This project needs at least Sphinx v%s and therefore cannot '
                'be built with this version.' % self.config.needs_sphinx)

        # set up translation infrastructure
        self._init_i18n()
        # set up the build environment
        self._init_env(freshenv)
        # set up the builder
        self._init_builder(buildername)

    def _init_i18n(self):
        """Load translated strings from the configured localedirs if enabled in
        the configuration.
        """
        if self.config.language is not None:
            self.info(bold('loading translations [%s]... ' %
                           self.config.language), nonl=True)
            locale_dirs = [None, path.join(package_dir, 'locale')] + \
                [path.join(self.srcdir, x) for x in self.config.locale_dirs]
        else:
            locale_dirs = []
        self.translator, has_translation = locale.init(locale_dirs,
                                                       self.config.language)
        if self.config.language is not None:
            if has_translation:
                self.info('done')
            else:
                self.info('locale not available')

    def _init_env(self, freshenv):
        if freshenv:
            self.env = BuildEnvironment(self.srcdir, self.doctreedir,
                                        self.config)
            self.env.find_files(self.config)
            for domain in self.domains.keys():
                self.env.domains[domain] = self.domains[domain](self.env)
        else:
            try:
                self.info(bold('loading pickled environment... '), nonl=True)
                self.env = BuildEnvironment.frompickle(self.config,
                    path.join(self.doctreedir, ENV_PICKLE_FILENAME))
                self.env.domains = {}
                for domain in self.domains.keys():
                    # this can raise if the data version doesn't fit
                    self.env.domains[domain] = self.domains[domain](self.env)
                self.info('done')
            except Exception, err:
                if type(err) is IOError and err.errno == ENOENT:
                    self.info('not yet created')
                else:
                    self.info('failed: %s' % err)
                return self._init_env(freshenv=True)

        self.env.set_warnfunc(self.warn)
开发者ID:aras0,项目名称:porownywarka-ofert,代码行数:101,代码来源:application.py


示例12: Sphinx

class Sphinx(object):

    def __init__(self, srcdir, confdir, outdir, doctreedir, buildername,
                 confoverrides=None, status=sys.stdout, warning=sys.stderr,
                 freshenv=False, warningiserror=False, tags=None, verbosity=0,
                 parallel=0):
        # type: (unicode, unicode, unicode, unicode, unicode, Dict, IO, IO, bool, bool, List[unicode], int, int) -> None  # NOQA
        self.verbosity = verbosity
        self.extensions = {}                    # type: Dict[unicode, Extension]
        self._setting_up_extension = ['?']      # type: List[unicode]
        self.builder = None                     # type: Builder
        self.env = None                         # type: BuildEnvironment
        self.registry = SphinxComponentRegistry()
        self.enumerable_nodes = {}              # type: Dict[nodes.Node, Tuple[unicode, Callable]]  # NOQA
        self.post_transforms = []               # type: List[Transform]
        self.html_themes = {}                   # type: Dict[unicode, unicode]

        self.srcdir = srcdir
        self.confdir = confdir
        self.outdir = outdir
        self.doctreedir = doctreedir

        self.parallel = parallel

        if status is None:
            self._status = cStringIO()      # type: IO
            self.quiet = True
        else:
            self._status = status
            self.quiet = False

        if warning is None:
            self._warning = cStringIO()     # type: IO
        else:
            self._warning = warning
        self._warncount = 0
        self.warningiserror = warningiserror
        logging.setup(self, self._status, self._warning)

        self.events = EventManager()

        # keep last few messages for traceback
        # This will be filled by sphinx.util.logging.LastMessagesWriter
        self.messagelog = deque(maxlen=10)  # type: deque

        # say hello to the world
        logger.info(bold('Running Sphinx v%s' % sphinx.__display_version__))

        # status code for command-line application
        self.statuscode = 0

        if not path.isdir(outdir):
            logger.info('making output directory...')
            os.makedirs(outdir)

        # read config
        self.tags = Tags(tags)
        self.config = Config(confdir, CONFIG_FILENAME,
                             confoverrides or {}, self.tags)
        self.config.check_unicode()
        # defer checking types until i18n has been initialized

        # initialize some limited config variables before initialize i18n and loading
        # extensions
        self.config.pre_init_values()

        # set up translation infrastructure
        self._init_i18n()

        # check the Sphinx version if requested
        if self.config.needs_sphinx and self.config.needs_sphinx > sphinx.__display_version__:
            raise VersionRequirementError(
                __('This project needs at least Sphinx v%s and therefore cannot '
                   'be built with this version.') % self.config.needs_sphinx)

        # set confdir to srcdir if -C given (!= no confdir); a few pieces
        # of code expect a confdir to be set
        if self.confdir is None:
            self.confdir = self.srcdir

        # load all built-in extension modules
        for extension in builtin_extensions:
            self.setup_extension(extension)

        # load all user-given extension modules
        for extension in self.config.extensions:
            self.setup_extension(extension)

        # preload builder module (before init config values)
        self.preload_builder(buildername)

        # the config file itself can be an extension
        if self.config.setup:
            self._setting_up_extension = ['conf.py']
            # py31 doesn't have 'callable' function for below check
            if hasattr(self.config.setup, '__call__'):
                self.config.setup(self)
            else:
                raise ConfigError(
                    __("'setup' as currently defined in conf.py isn't a Python callable. "
#.........这里部分代码省略.........
开发者ID:marcosptf,项目名称:fedora,代码行数:101,代码来源:application.py


示例13: __init__

    def __init__(self, filename, encoding="utf8", raise_exception=False):
        """
        create an instance of a blog post from a file or a string

        @param      filename            filename or string
        @param      encoding            encoding
        @param      raise_exception     to raise an exception when the blog cannot be parsed

        The constructor creates the following members:

        * title
        * date
        * keywords
        * categories
        * _filename
        * _raw
        * rst_obj: the object generated by docutils (@see cl BlogPostDirective)
        * pub: Publisher

        .. versionchanged:: 1.3
            Parameter *raise_exception* was added to catch the standard error.
            The constructor aims at getting the text of a blog post, not
            interpreting it. The code used to throw warnings or errors due to
            unreferenced nodes.

        """
        if os.path.exists(filename):
            with open(filename, "r", encoding=encoding) as f:
                try:
                    content = f.read()
                except UnicodeDecodeError as e:
                    raise Exception(
                        'unable to read filename (encoding issue):\n  File "{0}", line 1'.format(filename)) from e
            self._filename = filename
        else:
            content = filename
            self._filename = None

        self._raw = content

        overrides = {}
        overrides['input_encoding'] = encoding
        overrides["out_blogpostlist"] = []
        overrides["blog_background"] = False
        overrides["sharepost"] = None

        overrides.update({'doctitle_xform': True,
                          'initial_header_level': 2,
                          'warning_stream': StringIO(),
                          'out_blogpostlist': [],
                          'out_runpythonlist': [],
                          })

        config = Config(None, None, overrides=overrides, tags=None)
        config.blog_background = False
        config.sharepost = None
        env = BuildEnvironment(None, None, config=config)
        env.temp_data["docname"] = "string"
        overrides["env"] = env

        errst = sys.stderr
        keeperr = StringIO()
        sys.stderr = keeperr

        output, pub = publish_programmatically(
            source_class=docio.StringInput,
            source=content,
            source_path=None,
            destination_class=docio.StringOutput,
            destination=None,
            destination_path=None,
            reader=None,
            reader_name='standalone',
            parser=None,
            parser_name='restructuredtext',
            writer=None,
            writer_name='null',
            settings=None,
            settings_spec=None,
            settings_overrides=overrides,
            config_section=None,
            enable_exit_status=None)

        sys.stderr = errst
        all_err = keeperr.getvalue()
        if len(all_err) > 0:
            if raise_exception:
                raise BlogPostParseError("unable to parse a blogpost:\nERR:\n{0}\nFILE\n{1}\nCONTENT\n{2}".format(
                    all_err, self._filename, content))
            else:
                # we assume we just need the content, raising a warnings
                # might make some process fail later
                # warnings.warn("Raw rst was caught but unable to fully parse a blogpost:\nERR:\n{0}\nFILE\n{1}\nCONTENT\n{2}".format(
                #     all_err, self._filename, content))
                pass

        # document = pub.writer.document
        objects = pub.settings.out_blogpostlist

        if len(objects) != 1:
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


示例14: setup_module

def setup_module():
    global app, env
    app = TestApp(srcdir='(temp)')
    env = BuildEnvironment(app.srcdir, app.doctreedir, app.config)
    env.set_warnfunc(warnings.append)
开发者ID:BackupGGCode,项目名称:sphinx,代码行数:5,代码来源:test_env.py


示例15: __init__

class Sphinx:
    """The main application class and extensibility interface.

    :ivar srcdir: Directory containing source.
    :ivar confdir: Directory containing ``conf.py``.
    :ivar doctreedir: Directory for storing pickled doctrees.
    :ivar outdir: Directory for storing build documents.
    """

    def __init__(self, srcdir, confdir, outdir, doctreedir, buildername,
                 confoverrides=None, status=sys.stdout, warning=sys.stderr,
                 freshenv=False, warningiserror=False, tags=None, verbosity=0,
                 parallel=0, keep_going=False):
        # type: (str, str, str, str, str, Dict, IO, IO, bool, bool, List[str], int, int, bool) -> None  # NOQA
        self.phase = BuildPhase.INITIALIZATION
        self.verbosity = verbosity
        self.extensions = {}                    # type: Dict[str, Extension]
        self.builder = None                     # type: Builder
        self.env = None                         # type: BuildEnvironment
        self.project = None                     # type: Project
        self.registry = SphinxComponentRegistry()
        self.html_themes = {}                   # type: Dict[str, str]

        # validate provided directories
        self.srcdir = abspath(srcdir)
        self.outdir = abspath(outdir)
        self.doctreedir = abspath(doctreedir)
        self.confdir = confdir
        if self.confdir:  # confdir is optional
            self.confdir = abspath(self.confdir)
            if not path.isfile(path.join(self.confdir, 'conf.py')):
                raise ApplicationError(__("config directory doesn't contain a "
                                          "conf.py file (%s)") % confdir)

        if not path.isdir(self.srcdir):
            raise ApplicationError(__('Cannot find source directory (%s)') %
                                   self.srcdir)

        if self.srcdir == self.outdir:
            raise ApplicationError(__('Source directory and destination '
                                      'directory cannot be identical'))

        self.parallel = parallel

        if status is None:
            self._status = StringIO()      # type: IO
            self.quiet = True
        else:
            self._status = status
            self.quiet = False

        if warning is None:
            self._warning = StringIO()     # type: IO
        else:
            self._warning = warning
        self._warncount = 0
        self.keep_going = warningiserror and keep_going
        if self.keep_going:
            self.warningiserror = False
        else:
            self.warningiserror = warningiserror
        logging.setup(self, self._status, self._warning)

        self.events = EventManager()

        # keep last few messages for traceback
        # This will be filled by sphinx.util.logging.LastMessagesWriter
        self.messagelog = deque(maxlen=10)  # type: deque

        # say hello to the world
        logger.info(bold(__('Running Sphinx v%s') % sphinx.__display_version__))

        # status code for command-line application
        self.statuscode = 0

        # read config
        self.tags = Tags(tags)
        if self.confdir is None:
            self.config = Config({}, confoverrides or {})
        else:
            self.config = Config.read(self.confdir, confoverrides or {}, self.tags)

        # initialize some limited config variables before initialize i18n and loading
        # extensions
        self.config.pre_init_values()

        # set up translation infrastructure
        self._init_i18n()

        # check the Sphinx version if requested
        if self.config.needs_sphinx and self.config.needs_sphinx > sphinx.__display_version__:
            raise VersionRequirementError(
                __('This project needs at least Sphinx v%s and therefore cannot '
                   'be built with this version.') % self.config.needs_sphinx)

        # set confdir to srcdir if -C given (!= no confdir); a few pieces
        # of code expect a confdir to be set
        if self.confdir is None:
            self.confdir = self.srcdir

#.........这里部分代码省略.........
开发者ID:lmregus,项目名称:Portfolio,代码行数:101,代码来源:application.py


示例16: Sphinx

class Sphinx(object):

    def __init__(self, srcdir, confdir, outdir, doctreedir, buildername,
                 confoverrides=None, status=sys.stdout, warning=sys.stderr,
                 freshenv=False, warningiserror=False, tags=None, verbosity=0,
                 parallel=0):
        # type: (unicode, unicode, unicode, unicode, unicode, Dict, IO, IO, bool, bool, unicode, int, int) -> None  # NOQA
        self.verbosity = verbosity
        self.next_listener_id = 0
        self._extensions = {}                   # type: Dict[unicode, Any]
        self._extension_metadata = {}           # type: Dict[unicode, Dict[unicode, Any]]
        self._additional_source_parsers = {}    # type: Dict[unicode, Parser]
        self._listeners = {}                    # type: Dict[unicode, Dict[int, Callable]]
        self._setting_up_extension = ['?']      # type: List[unicode]
        self.domains = {}                       # type: Dict[unicode, Type[Domain]]
        self.buildername = buildername
        self.builderclasses = {}                # type: Dict[unicode, Type[Builder]]
        self.builder = None                     # type: Builder
        self.env = None                         # type: BuildEnvironment
        self.enumerable_nodes = {}              # type: Dict[nodes.Node, Tuple[unicode, Callable]]  # NOQA

        self.srcdir = srcdir
        self.confdir = confdir
        self.outdir = outdir
        self.doctreedir = doctreedir

        self.parallel = parallel

        if status is None:
            self._status = cStringIO()      # type: IO
            self.quiet = True
        else:
            self._status = status
            self.quiet = False

        if warning is None:
            self._warning = cStringIO()     # type: IO
        else:
            self._warning = warning
        self._warncount = 0
        self.warningiserror = warningiserror

        self._events = events.copy()
        self._translators = {}              # type: Dict[unicode, nodes.GenericNodeVisitor]

        # keep last few messages for traceback
        self.messagelog = deque(maxlen=10)  # type: deque

        # say hello to the world
        self.info(bold('Running Sphinx v%s' % sphinx.__display_version__))

        # status code for command-line application
        self.statuscode = 0

        if not path.isdir(outdir):
            self.info('making output directory...')
            os.makedirs(outdir)

        # read config
        self.tags = Tags(tags)
        self.config = Config(confdir, CONFIG_FILENAME,
                             confoverrides or {}, self.tags)
        self.config.check_unicode(self.warn)
        # defer checking types until i18n has been initialized

        # initialize some limited config variables before loading extensions
        self.config.pre_init_values(self.warn)

        # check the Sphinx version if requested
        if self.config.needs_sphinx and self.config.needs_sphinx > sphinx.__display_version__:
            raise VersionRequirementError(
                'This project needs at least Sphinx v%s and therefore cannot '
                'be built with this version.' % self.config.needs_sphinx)

        # force preload html_translator_class
        if self.config.html_translator_class:
            translator_class = self.import_object(self.config.html_translator_class,
                                                  'html_translator_class setting')
            self.set_translator('html', translator_class)

        # set confdir to srcdir if -C given (!= no confdir); a few pieces
        # of code expect a confdir to be set
        if self.confdir is None:
            self.confdir = self.srcdir

        # load all built-in extension modules
        for extension in builtin_extensions:
            self.setup_extension(extension)

        # extension loading support for alabaster theme
        # self.config.html_theme is not set from conf.py at here
        # for now, sphinx always load a 'alabaster' extension.
        if 'alabaster' not in self.config.extensions:
            self.config.extensions.append('alabaster')

        # load all user-given extension modules
        for extension in self.config.extensions:
            self.setup_extension(extension)
        # the config file itself can be an extension
        if self.config.setup:
#.........这里部分代码省略.........
开发者ID:Felix-neko,项目名称:sphinx,代码行数:101,代码来源:application.py


示例17: rst2html


#.........这里部分代码省略.........
        setup_plot(mockapp)
        setup_only(mockapp)

        # titles
        title_names.append("todoext_node")
        title_names.append("todo_node")
        title_names.append("mathdef_node")
        title_names.append("blocref_node")
        title_names.append("faqref_node")
        title_names.append("nbref_node")
        title_names.append("exref_node")
    else:
        writer_name = 'html'
        mockapp = MockSphinxApp(None)

    if writer is None and directives is not None and len(directives) > 0:
        raise NotImplementedError(
            "the writer must not be null if custom directives will be added, check the documentation of the fucntion")

    if directives is not None:
        for tu in directives:
            if len(tu) != 5:
                raise ValueError(
                    "directives is a list of tuple with 5 elements, check the documentation")
            name, cl, node, f1, f2 = tu
            doc_directives.register_directive(name, cl)
            # not necessary
            # nodes._add_node_class_names([node.__name__])
            writer.connect_directive_node(node.__name__, f1, f2)

    settings_overrides = default_settings.copy()
    settings_overrides.update({k: v[0]
                               for k, v in mockapp.new_options.items()})

    # next
    defopt = default_sphinx_options(**options)
    settings_overrides.update(defopt)
    warning_stringio = defopt["warning_stream"]
    _nbeq[1] = warning_stringio

    config = mockapp.config
    config.init_values(fLOG)
    config.blog_background = False
    config.sharepost = None

    writer.add_configuration_options(mockapp.new_options)
    for k in {'outdir', 'imagedir', 'confdir', 'doctreedir'}:
        setattr(writer.builder, k, settings_overrides[k])

    env = BuildEnvironment(None, None, config=config)
    env.temp_data["docname"] = "string"
    mockapp.builder.env.temp_data["docname"] = "string"
    settings_overrides["env"] = env

    lang = languages.get_language(language)
    for name in title_names:
        if name not in lang.labels:
            lang.labels[name] = TITLES[language][name]

    for k, v in sorted(settings_overrides.items()):
        fLOG("[rst2html] {0}={1}{2}".format(
            k, v, " --- added" if hasattr(config, k) else ""))
    for k, v in sorted(settings_overrides.items()):
        if hasattr(writer.builder.config, k) and writer.builder.config[k] != v:
            writer.builder.config[k] = v

    # something is screwing with sphinx or docutils, it is due to
    # direct call to nbconvert or sphinx
    # raise an exception for unknown role pending_xref
    output, pub = core.publish_programmatically(source=s, source_path=None,
                                                destination_path=None, writer=writer,
                                                writer_name=writer_name,
                                                settings_overrides=settings_overrides,
                                                source_class=StringInput,
                                                destination_class=StringOutput,
                                                destination=None,
                                                reader=None, reader_name='standalone',
                                                parser=None, parser_name='restructuredtext',
                                                settings=None, settings_spec=None,
                                                config_section=None,
                                                enable_exit_status=False)

    doctree = pub.document
    mockapp.emit('doctree-read', doctree)
    parts = pub.writer.parts

    warnval = settings_overrides["warning_stream"].getvalue()
    if warnval is not None and len(warnval) > 0:
        if warnings_log:
            fLOG(warnval)
        else:
            warnings.warn(warnval)

    if not keep_warnings:
        exp = re.sub(
            '(<div class="system-message">(.|\\n)*?</div>)', "", parts["whole"])
    else:
        exp = parts["whole"]

    return exp
开发者ID:,项目名称:,代码行数:101,代码来源:



注:本文中的sphinx.environment.BuildEnvironment类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python autodoc.add_documenter函数代码示例发布时间:2022-05-27
下一篇:
Python python.PyModulelevel类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap