From 6aa0e4346de498ada234f772163579e677cfd10b Mon Sep 17 00:00:00 2001 From: Ondrej Grover Date: Wed, 14 May 2014 14:30:21 +0200 Subject: [PATCH] Add {PAGE,ARTICLE}_PATHS to {ARTICLE,PAGE}_EXCLUDES automatically This makes it easier for someone to change PAGE_PATHS without the need to change ARTICLE_EXCLUDES accordingly. --- docs/settings.rst | 6 ++++-- pelican/settings.py | 16 ++++++++++++++-- pelican/tests/test_settings.py | 5 ++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/settings.rst b/docs/settings.rst index 34245ff4..fd5f488b 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -112,9 +112,11 @@ Setting name (followed by default value, if any) and content path is not specified via an argument to the ``pelican`` command, Pelican will use the current working directory. ``PAGE_PATHS = ['pages']`` A list of directories to look at for pages, relative to ``PATH``. -``PAGE_EXCLUDES = ()`` A list of directories to exclude when looking for pages. +``PAGE_EXCLUDES = []`` A list of directories to exclude when looking for pages in addition + to ``ARTICLE_PATHS``. ``ARTICLE_PATHS = ['']`` A list of directories to look at for articles, relative to ``PATH``. -``ARTICLE_EXCLUDES = ('pages',)`` A list of directories to exclude when looking for articles. +``ARTICLE_EXCLUDES = []`` A list of directories to exclude when looking for articles in addition + to ``PAGE_PATHS``. ``OUTPUT_SOURCES = False`` Set to True if you want to copy the articles and pages in their original format (e.g. Markdown or reStructuredText) to the specified ``OUTPUT_PATH``. diff --git a/pelican/settings.py b/pelican/settings.py index c93050ad..69ade05f 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -30,9 +30,9 @@ DEFAULT_THEME = os.path.join(os.path.dirname(os.path.abspath(__file__)), DEFAULT_CONFIG = { 'PATH': os.curdir, 'ARTICLE_PATHS': [''], - 'ARTICLE_EXCLUDES': ('pages',), + 'ARTICLE_EXCLUDES': [], 'PAGE_PATHS': ['pages'], - 'PAGE_EXCLUDES': (), + 'PAGE_EXCLUDES': [], 'THEME': DEFAULT_THEME, 'OUTPUT_PATH': 'output', 'READERS': {}, @@ -348,6 +348,18 @@ def configure_settings(settings): % PATH_KEY) settings[PATH_KEY] = DEFAULT_CONFIG[PATH_KEY] + # Add {PAGE,ARTICLE}_PATHS to {ARTICLE,PAGE}_EXCLUDES + mutually_exclusive = ('ARTICLE', 'PAGE') + for type_1, type_2 in [mutually_exclusive, mutually_exclusive[::-1]]: + try: + includes = settings[type_1 + '_PATHS'] + excludes = settings[type_2 + '_EXCLUDES'] + for path in includes: + if path not in excludes: + excludes.append(path) + except KeyError: + continue # setting not specified, nothing to do + for old, new, doc in [ ('LESS_GENERATOR', 'the Webassets plugin', None), ('FILES_TO_COPY', 'STATIC_PATHS and EXTRA_PATH_METADATA', diff --git a/pelican/tests/test_settings.py b/pelican/tests/test_settings.py index 930e0fea..260eff05 100644 --- a/pelican/tests/test_settings.py +++ b/pelican/tests/test_settings.py @@ -43,7 +43,10 @@ class TestSettingsConfiguration(unittest.TestCase): # Providing no file should return the default values. settings = read_settings(None) expected = copy.deepcopy(DEFAULT_CONFIG) - expected['FEED_DOMAIN'] = '' # Added by configure settings + # Added by configure settings + expected['FEED_DOMAIN'] = '' + expected['ARTICLE_EXCLUDES'] = ['pages'] + expected['PAGE_EXCLUDES'] = [''] self.maxDiff = None self.assertDictEqual(settings, expected)