From 3395e71570c797d19067bf53faf8bd0c2a60d3f3 Mon Sep 17 00:00:00 2001 From: John Franey Date: Wed, 6 Feb 2019 10:22:57 -0400 Subject: [PATCH] Fix linting issues Fixes linting issues that caused the `flake8` CI stage to fail. --- pelican/__init__.py | 4 ++-- pelican/settings.py | 10 +++++----- pelican/tests/test_importer.py | 30 +++++++++++++++--------------- pelican/tools/pelican_themes.py | 4 ++-- pelican/utils.py | 15 +++++++++------ 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/pelican/__init__.py b/pelican/__init__.py index 27fc7fba..97d5fffa 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -444,8 +444,8 @@ def get_instance(args): config_file = args.settings if config_file is None and os.path.isfile(DEFAULT_CONFIG_NAME): - config_file = DEFAULT_CONFIG_NAME - args.settings = DEFAULT_CONFIG_NAME + config_file = DEFAULT_CONFIG_NAME + args.settings = DEFAULT_CONFIG_NAME settings = read_settings(config_file, override=get_config(args)) diff --git a/pelican/settings.py b/pelican/settings.py index b963007a..a957b26c 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -524,11 +524,11 @@ def configure_settings(settings): # check content caching layer and warn of incompatibilities if settings.get('CACHE_CONTENT', False) and \ - settings.get('CONTENT_CACHING_LAYER', '') == 'generator' and \ - settings.get('WITH_FUTURE_DATES', False): - logger.warning( - "WITH_FUTURE_DATES conflicts with CONTENT_CACHING_LAYER " - "set to 'generator', use 'reader' layer instead") + settings.get('CONTENT_CACHING_LAYER', '') == 'generator' and \ + settings.get('WITH_FUTURE_DATES', False): + logger.warning( + "WITH_FUTURE_DATES conflicts with CONTENT_CACHING_LAYER " + "set to 'generator', use 'reader' layer instead") # Warn if feeds are generated with both SITEURL & FEED_DOMAIN undefined feed_keys = [ diff --git a/pelican/tests/test_importer.py b/pelican/tests/test_importer.py index 75310a80..6eb62852 100644 --- a/pelican/tests/test_importer.py +++ b/pelican/tests/test_importer.py @@ -102,8 +102,8 @@ class TestWordpressXmlImporter(unittest.TestCase): def test_ignore_empty_posts(self): self.assertTrue(self.posts) for (title, content, fname, date, author, - categ, tags, status, kind, format) in self.posts: - self.assertTrue(title.strip()) + categ, tags, status, kind, format) in self.posts: + self.assertTrue(title.strip()) def test_recognise_page_kind(self): """ Check that we recognise pages in wordpress, as opposed to posts """ @@ -111,9 +111,9 @@ class TestWordpressXmlImporter(unittest.TestCase): # Collect (title, filename, kind) of non-empty posts recognised as page pages_data = [] for (title, content, fname, date, author, - categ, tags, status, kind, format) in self.posts: - if kind == 'page': - pages_data.append((title, fname)) + categ, tags, status, kind, format) in self.posts: + if kind == 'page': + pages_data.append((title, fname)) self.assertEqual(2, len(pages_data)) self.assertEqual(('Page', 'contact'), pages_data[0]) self.assertEqual(('Empty Page', 'empty'), pages_data[1]) @@ -151,22 +151,22 @@ class TestWordpressXmlImporter(unittest.TestCase): self.assertTrue(self.posts) pages_data = [] for (title, content, fname, date, author, categ, - tags, status, kind, format) in self.posts: - if kind == 'page' or kind == 'article': - pass - else: - pages_data.append((title, fname)) + tags, status, kind, format) in self.posts: + if kind == 'page' or kind == 'article': + pass + else: + pages_data.append((title, fname)) self.assertEqual(0, len(pages_data)) def test_recognise_custom_post_type(self): self.assertTrue(self.custposts) cust_data = [] for (title, content, fname, date, author, categ, - tags, status, kind, format) in self.custposts: - if kind == 'article' or kind == 'page': - pass - else: - cust_data.append((title, kind)) + tags, status, kind, format) in self.custposts: + if kind == 'article' or kind == 'page': + pass + else: + cust_data.append((title, kind)) self.assertEqual(3, len(cust_data)) self.assertEqual( ('A custom post in category 4', 'custom1'), diff --git a/pelican/tools/pelican_themes.py b/pelican/tools/pelican_themes.py index b99a7ba3..9f9b2328 100755 --- a/pelican/tools/pelican_themes.py +++ b/pelican/tools/pelican_themes.py @@ -81,9 +81,9 @@ def main(): to_sym = args.to_symlink or args.clean if args.action: - if args.action is 'list': + if args.action == 'list': list_themes(args.verbose) - elif args.action is 'path': + elif args.action == 'path': print(_THEMES_PATH) elif to_install or args.to_remove or to_sym: if args.to_remove: diff --git a/pelican/utils.py b/pelican/utils.py index 50d428a5..4a31658b 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -787,12 +787,15 @@ def folder_watcher(path, extensions, ignores=[]): dirs[:] = [x for x in dirs if not x.startswith(os.curdir)] for f in files: - if f.endswith(tuple(extensions)) and \ - not any(fnmatch.fnmatch(f, ignore) for ignore in ignores): - try: - yield os.stat(os.path.join(root, f)).st_mtime - except OSError as e: - logger.warning('Caught Exception: %s', e) + valid_extension = f.endswith(tuple(extensions)) + file_ignored = any( + fnmatch.fnmatch(f, ignore) for ignore in ignores + ) + if valid_extension and not file_ignored: + try: + yield os.stat(os.path.join(root, f)).st_mtime + except OSError as e: + logger.warning('Caught Exception: %s', e) LAST_MTIME = 0 while True: