Example #1
0
    def pre(rel_source):
        """To be executed in a Click sub command.

        Needed because if this code is in cli() it will be executed when the user runs: <command> <sub command> --help

        :param tuple rel_source: Possible relative paths (to git root) of Sphinx directory containing conf.py.
        """
        # Setup logging.
        if not NO_EXECUTE:
            setup_logging(verbose=config.verbose, colors=not config.no_colors)
        log = logging.getLogger(__name__)

        # Change current working directory.
        if config.chdir:
            os.chdir(config.chdir)
            log.debug('Working directory: %s', os.getcwd())
        else:
            config.update(dict(chdir=os.getcwd()), overwrite=True)

        # Get and verify git root.
        try:
            config.update(
                dict(git_root=get_root(config.git_root or os.getcwd())),
                overwrite=True)
        except GitError as exc:
            log.error(exc.message)
            log.error(exc.output)
            raise HandledError

        # Look for local config.
        if config.no_local_conf:
            config.update(dict(local_conf=None), overwrite=True)
        elif not config.local_conf:
            candidates = [
                p for p in (os.path.join(s, 'conf.py') for s in rel_source)
                if os.path.isfile(p)
            ]
            if candidates:
                config.update(dict(local_conf=candidates[0]), overwrite=True)
            else:
                log.debug("Didn't find a conf.py in any REL_SOURCE.")
        elif os.path.basename(config.local_conf) != 'conf.py':
            log.error('Path "%s" must end with conf.py.', config.local_conf)
            raise HandledError
    def pre(rel_source):
        """To be executed in a Click sub command.

        Needed because if this code is in cli() it will be executed when the user runs: <command> <sub command> --help

        :param tuple rel_source: Possible relative paths (to git root) of Sphinx directory containing conf.py.
        """
        # Setup logging.
        if not NO_EXECUTE:
            setup_logging(verbose=config.verbose, colors=not config.no_colors)
        log = logging.getLogger(__name__)

        # Change current working directory.
        if config.chdir:
            os.chdir(config.chdir)
            log.debug('Working directory: %s', os.getcwd())
        else:
            config.update(dict(chdir=os.getcwd()), overwrite=True)

        # Get and verify git root.
        try:
            config.update(dict(git_root=get_root(config.git_root or os.getcwd())), overwrite=True)
        except GitError as exc:
            log.error(exc.message)
            log.error(exc.output)
            raise HandledError

        # Look for local config.
        if config.no_local_conf:
            config.update(dict(local_conf=None), overwrite=True)
        elif not config.local_conf:
            candidates = [p for p in (os.path.join(s, 'conf.py') for s in rel_source) if os.path.isfile(p)]
            if candidates:
                config.update(dict(local_conf=candidates[0]), overwrite=True)
            else:
                log.debug("Didn't find a conf.py in any REL_SOURCE.")
        elif os.path.basename(config.local_conf) != 'conf.py':
            log.error('Path "%s" must end with conf.py.', config.local_conf)
            raise HandledError
Example #3
0
def test(tmpdir, local_empty):
    """Test function.

    :param tmpdir: pytest fixture.
    :param local_empty: conftest fixture.
    """
    # Test failure.
    with pytest.raises(GitError):
        get_root(str(tmpdir))

    # Test root.
    if IS_WINDOWS:
        assert get_root(str(local_empty)).lower() == str(local_empty).lower()
    else:
        assert get_root(str(local_empty)) == str(local_empty)

    # Test subdir.
    subdir = local_empty.ensure_dir('subdir')
    if IS_WINDOWS:
        assert get_root(str(subdir)).lower() == str(local_empty).lower()
    else:
        assert get_root(str(subdir)) == str(local_empty)