From 510635a9134f7ed2563e60649802708564a5d39b Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 3 Jun 2014 15:12:11 -0700 Subject: [PATCH] Remove check_doc.py and use doc8 Instead of using a helper script that is internal to taskflow use the doc8 package (which was created based on the check_doc.py work) instead. This avoids repeating duplicated code when a stackforge/external pypi package can provide the same functionality. Change-Id: Ie5a43f96b20e34f3955657ad2ef8beba05a4300e --- tools/check_doc.py | 114 --------------------------------------------- tox-tmpl.ini | 3 +- tox.ini | 3 +- 3 files changed, 4 insertions(+), 116 deletions(-) delete mode 100644 tools/check_doc.py diff --git a/tools/check_doc.py b/tools/check_doc.py deleted file mode 100644 index 04c70dc2..00000000 --- a/tools/check_doc.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# Copyright (C) 2014 Ivan Melnikov -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -"""Check documentation for simple style requirements. - -What is checked: - - lines should not be longer than 79 characters - - exception: line with no whitespace except maybe in the beginning - - exception: line that starts with '..' -- longer directives are allowed, - including footnotes - - no tabulation for indentation - - no trailing whitespace -""" - -import fnmatch -import os -import re -import sys - - -FILE_PATTERNS = ['*.rst', '*.txt'] -MAX_LINE_LENGTH = 79 -TRAILING_WHITESPACE_REGEX = re.compile('\s$') -STARTING_WHITESPACE_REGEX = re.compile('^(\s+)') - - -def check_max_length(line): - if len(line) > MAX_LINE_LENGTH: - stripped = line.strip() - if not any(( - line.startswith('..'), # this is directive - stripped.startswith('>>>'), # this is doctest - stripped.startswith('...'), # and this - stripped.startswith('taskflow.'), - ' ' not in stripped # line can't be split - )): - yield ('D001', 'Line too long') - - -def check_trailing_whitespace(line): - if TRAILING_WHITESPACE_REGEX.search(line): - yield ('D002', 'Trailing whitespace') - - -def check_indentation_no_tab(line): - match = STARTING_WHITESPACE_REGEX.search(line) - if match: - spaces = match.group(1) - if '\t' in spaces: - yield ('D003', 'Tabulation used for indentation') - - -LINE_CHECKS = (check_max_length, - check_trailing_whitespace, - check_indentation_no_tab) - - -def check_lines(lines): - for idx, line in enumerate(lines, 1): - line = line.rstrip('\n') - for check in LINE_CHECKS: - for code, message in check(line): - yield idx, code, message - - -def check_files(filenames): - for fn in filenames: - with open(fn) as f: - for line_num, code, message in check_lines(f): - yield fn, line_num, code, message - - -def find_files(pathes, patterns): - for path in pathes: - if os.path.isfile(path): - yield path - elif os.path.isdir(path): - for root, dirnames, filenames in os.walk(path): - for filename in filenames: - if any(fnmatch.fnmatch(filename, pattern) - for pattern in patterns): - yield os.path.join(root, filename) - else: - print('Invalid path: %s' % path) - - -def main(): - ok = True - if len(sys.argv) > 1: - dirs = sys.argv[1:] - else: - dirs = ['.'] - for error in check_files(find_files(dirs, FILE_PATTERNS)): - ok = False - print('%s:%s: %s %s' % error) - sys.exit(0 if ok else 1) - -if __name__ == '__main__': - main() diff --git a/tox-tmpl.ini b/tox-tmpl.ini index 08164ecf..8cc6940e 100644 --- a/tox-tmpl.ini +++ b/tox-tmpl.ini @@ -56,10 +56,11 @@ deps = {[testenv:py26-sa7-mysql-ev]deps} deps = -r{toxinidir}/requirements.txt -r{toxinidir}/optional-requirements.txt -r{toxinidir}/test-requirements.txt + doc8>=0.3.4 commands = python setup.py testr --slowest --testr-args='{posargs}' sphinx-build -b doctest doc/source doc/build - python tools/check_doc.py doc/source + doc8 doc/source [testenv:py33] deps = {[testenv]deps} diff --git a/tox.ini b/tox.ini index f63a612d..9d276c2c 100644 --- a/tox.ini +++ b/tox.ini @@ -79,10 +79,11 @@ deps = {[testenv:py26-sa7-mysql-ev]deps} deps = -r{toxinidir}/requirements.txt -r{toxinidir}/optional-requirements.txt -r{toxinidir}/test-requirements.txt + doc8>=0.3.4 commands = python setup.py testr --slowest --testr-args='{posargs}' sphinx-build -b doctest doc/source doc/build - python tools/check_doc.py doc/source + doc8 doc/source [testenv:py33] deps = {[testenv]deps}