Remove deprecated autofill of extra configs.

This commit is contained in:
Waylan Limberg
2017-09-28 16:14:55 -04:00
parent a95c35458f
commit f90c44a20d
3 changed files with 22 additions and 109 deletions

View File

@@ -433,26 +433,34 @@ class Theme(BaseConfigOption):
config[key_name] = theme.Theme(**theme_config)
class Extras(OptionallyRequired):
class Pages(OptionallyRequired):
"""
Extras Config Option
Pages Config Option
Validate the extra configs are a list and populate them with a set of files
if not provided.
Validate the pages config. Automatically add all markdown files if empty.
"""
def __init__(self, file_match=None, **kwargs):
super(Extras, self).__init__(**kwargs)
self.file_match = file_match
def __init__(self, **kwargs):
super(Pages, self).__init__(**kwargs)
self.file_match = utils.is_markdown_file
def run_validation(self, value):
if isinstance(value, list):
return value
else:
if not isinstance(value, list):
raise ValidationError(
"Expected a list, got {0}".format(type(value)))
if len(value) == 0:
return
config_types = set(type(l) for l in value)
if config_types.issubset({utils.text_type, dict, str}):
return value
raise ValidationError("Invalid pages config. {0} {1}".format(
config_types, {utils.text_type, dict}
))
def walk_docs_dir(self, docs_dir):
if self.file_match is None:
@@ -474,56 +482,6 @@ class Extras(OptionallyRequired):
if self.file_match(relpath):
yield relpath
def post_validation(self, config, key_name):
if config[key_name] is not None:
return
extras = []
for filename in self.walk_docs_dir(config['docs_dir']):
extras.append(filename)
config[key_name] = extras
if not extras:
return
self.warnings.append((
'The following files have been automatically included in the '
'documentation build and will be added to the HTML: {0}. This '
'behavior is deprecated. In version 1.0 and later they will '
"need to be explicitly listed in the '{1}' config setting."
).format(','.join(extras), key_name))
class Pages(Extras):
"""
Pages Config Option
Validate the pages config. Automatically add all markdown files if empty.
"""
def __init__(self, **kwargs):
super(Pages, self).__init__(utils.is_markdown_file, **kwargs)
def run_validation(self, value):
if not isinstance(value, list):
raise ValidationError(
"Expected a list, got {0}".format(type(value)))
if len(value) == 0:
return
config_types = set(type(l) for l in value)
if config_types.issubset({utils.text_type, dict, str}):
return value
raise ValidationError("Invalid pages config. {0} {1}".format(
config_types, {utils.text_type, dict}
))
def post_validation(self, config, key_name):
if config[key_name] is not None:

View File

@@ -78,15 +78,13 @@ DEFAULT_SCHEMA = (
('edit_uri', config_options.Type(utils.string_types)),
# Specify which css or javascript files from the docs directory should be
# additionally included in the site. Default, List of all .css and .js
# files in the docs dir.
('extra_css', config_options.Extras(file_match=utils.is_css_file)),
('extra_javascript', config_options.Extras(
file_match=utils.is_javascript_file)),
# additionally included in the site.
('extra_css', config_options.Type(list, default=[])),
('extra_javascript', config_options.Type(list, default=[])),
# Similar to the above, but each template (HTML or XML) will be build with
# Jinja2 and the global context.
('extra_templates', config_options.Extras()),
('extra_templates', config_options.Type(list, default=[])),
# PyMarkdown extension names.
('markdown_extensions', config_options.MarkdownExtensions(

View File

@@ -1,7 +1,6 @@
from __future__ import unicode_literals
import os
import tempfile
import unittest
import mkdocs
@@ -412,48 +411,6 @@ class ThemeTest(unittest.TestCase):
option.validate, config)
class ExtrasTest(unittest.TestCase):
def test_provided(self):
option = config_options.Extras(utils.is_markdown_file)
value = option.validate([])
self.assertEqual([], value)
option.post_validation({'extra_stuff': []}, 'extra_stuff')
def test_empty(self):
option = config_options.Extras(utils.is_template_file)
value = option.validate(None)
self.assertEqual(None, value)
def test_invalid(self):
option = config_options.Extras(utils.is_html_file)
self.assertRaises(config_options.ValidationError,
option.validate, {})
def test_walk(self):
option = config_options.Extras(utils.is_markdown_file)
tmp_dir = tempfile.mkdtemp()
f1 = os.path.join(tmp_dir, 'file1.md')
f2 = os.path.join(tmp_dir, 'file2.md')
open(f1, 'a').close()
# symlink isn't available on Python 2 on Windows.
if hasattr(os, 'symlink'):
os.symlink('/path/that/doesnt/exist', f2)
files = list(option.walk_docs_dir(tmp_dir))
self.assertEqual(['file1.md', ], files)
class PagesTest(unittest.TestCase):
def test_old_format(self):