Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}],
extra={
'search': {
'language': 'en,ru' if lang == 'ru' else 'en'
},
'stable_releases': args.stable_releases,
'version_prefix': args.version_prefix
}
)
mkdocs_build.build(cfg)
if not args.skip_single_page:
build_single_page_version(lang, args, cfg)
except exceptions.ConfigurationError as e:
raise SystemExit('\n' + str(e))
def serve_command(dev_addr, livereload, **kwargs):
"""Run the builtin development server"""
logging.getLogger('tornado').setLevel(logging.WARNING)
try:
serve.serve(
dev_addr=dev_addr,
livereload=livereload,
**kwargs
)
except (exceptions.ConfigurationError, OSError) as e: # pragma: no cover
# Avoid ugly, unhelpful traceback
raise SystemExit('\n' + str(e))
def deploy(args):
"""
Deploy to Github Pages
Args:
args (argparse.Namespace): A Namespace object contaning all the command line arguments
Raises:
exceptions.ConfigurationError
"""
try:
cfg = config.load_config(config_file=args.config_file, remote_branch=args.remote_branch, remote_name=args.remote_name)
gh_deploy.gh_deploy(cfg, message=args.message, force=args.force, ignore_version=args.ignore_version)
except exceptions.ConfigurationError as e:
raise SystemExit('\n' + str(e))
def build_command(clean, **kwargs):
"""Build the MkDocs documentation"""
try:
build.build(config.load_config(**kwargs), dirty=not clean)
except exceptions.ConfigurationError as e: # pragma: no cover
# Avoid ugly, unhelpful traceback
raise SystemExit('\n' + str(e))
def get_themes():
""" Return a dict of all installed themes as (name, entry point) pairs. """
themes = {}
builtins = pkg_resources.get_entry_map(dist='mkdocs', group='mkdocs.themes')
for theme in pkg_resources.iter_entry_points(group='mkdocs.themes'):
if theme.name in builtins and theme.dist.key != 'mkdocs':
raise exceptions.ConfigurationError(
"The theme {} is a builtin theme but {} provides a theme "
"with the same name".format(theme.name, theme.dist.key))
elif theme.name in themes:
multiple_packages = [themes[theme.name].dist.key, theme.dist.key]
log.warning("The theme %s is provided by the Python packages "
"'%s'. The one in %s will be used.",
theme.name, ','.join(multiple_packages), theme.dist.key)
themes[theme.name] = theme
return themes
log.warning("Ignoring empty line in the pages config.")
raise StopIteration
next_cat_or_title, subpages_or_path = next(iter(config_line.items()))
if isinstance(subpages_or_path, utils.string_types):
path = subpages_or_path
for sub in _follow(path, url_context, config, header=header, title=next_cat_or_title):
yield sub
raise StopIteration
elif not isinstance(subpages_or_path, list):
msg = ("Line in 'page' config is of type {0}, list or string "
"expected for sub pages. Config: {1}"
).format(type(config_line), config_line)
raise exceptions.ConfigurationError(msg)
next_header = Header(title=next_cat_or_title, children=[])
if header:
next_header.ancestors = [header]
header.children.append(next_header)
yield next_header
subpages = subpages_or_path
for subpage in subpages:
for sub in _follow(subpage, url_context, config, next_header):
yield sub
def _mkdocs_config(config: dict) -> mkdocs_config.Config:
config_instance = mkdocs_config.Config(schema=mkdocs_config.DEFAULT_SCHEMA)
config_instance.load_dict(config)
errors, warnings = config_instance.validate()
if errors:
print(errors)
raise _mkdocs_exceptions.ConfigurationError(
f"Aborted with {len(errors)} Configuration Errors!"
)
elif config.get("strict", False) and warnings: # pragma: no cover
print(warnings)
raise _mkdocs_exceptions.ConfigurationError(
f"Aborted with {len(warnings)} Configuration Warnings in 'strict' mode!"
)
config_instance.config_file_path = config["config_file_path"]
return config_instance
if isinstance(config_line, utils.string_types):
path = os.path.normpath(config_line)
page = Page(title, path, url_context, config)
if header:
page.ancestors = header.ancestors + [header, ]
header.children.append(page)
yield page
raise StopIteration
elif not isinstance(config_line, dict):
msg = ("Line in 'page' config is of type {0}, dict or string "
"expected. Config: {1}").format(type(config_line), config_line)
raise exceptions.ConfigurationError(msg)
if len(config_line) > 1:
raise exceptions.ConfigurationError(
"Page configs should be in the format 'name: markdown.md'. The "
"config contains an invalid entry: {0}".format(config_line))
elif len(config_line) == 0:
log.warning("Ignoring empty line in the pages config.")
raise StopIteration
next_cat_or_title, subpages_or_path = next(iter(config_line.items()))
if isinstance(subpages_or_path, utils.string_types):
path = subpages_or_path
for sub in _follow(path, url_context, config, header=header, title=next_cat_or_title):
yield sub
raise StopIteration
for config_name, warning in warnings:
log.warning("Config value: '%s'. Warning: %s", config_name, warning)
for config_name, error in errors:
log.error("Config value: '%s'. Error: %s", config_name, error)
for key, value in cfg.items():
log.debug("Config value: '%s' = %r", key, value)
if len(errors) > 0:
raise exceptions.ConfigurationError(
"Aborted with {} Configuration Errors!".format(len(errors))
)
elif cfg['strict'] and len(warnings) > 0:
raise exceptions.ConfigurationError(
"Aborted with {} Configuration Warnings in 'strict' mode!".format(len(warnings))
)
return cfg
def _mkdocs_config(config: dict) -> mkdocs_config.Config:
config_instance = mkdocs_config.Config(schema=mkdocs_config.DEFAULT_SCHEMA)
config_instance.load_dict(config)
errors, warnings = config_instance.validate()
if errors:
print(errors)
raise _mkdocs_exceptions.ConfigurationError(
f"Aborted with {len(errors)} Configuration Errors!"
)
elif config.get("strict", False) and warnings: # pragma: no cover
print(warnings)
raise _mkdocs_exceptions.ConfigurationError(
f"Aborted with {len(warnings)} Configuration Warnings in 'strict' mode!"
)
config_instance.config_file_path = config["config_file_path"]
return config_instance