Skip to content

Commit 56721e7

Browse files
committed
Initial docstring linting.
- Apply one docstring lint to the global lint list (D302 - unicode docstrings should start with u"""). - Create an inclusion list with many more docstring checks (public modules need a docstring, white space and quoting issue, check imperative mood and capitializaton). Add a couple modules to this inclusion list. - Add tox and Travis targets for this linting. This gives a person who wants to work on improving Galaxy's in-code docstring documentation three ways to "raise the bar" for the project. One could: - Add more modules to the inclusion list (.ci/flake8_docstrings_include_list.txt). Many more modules should contain docstrings - especially things in galaxy-lib and web controllers. - Add more checks to the existing inclusion list checks - I'd say D101 and/or D103 first or any of the missing D2XX or D4XX options. D102 seems a bit too ambitious and I worry it'd be too much of a burden. - Pick some DXXX check that is ignored globally and fix it for the whole project and then remove it from the exclude list in setup.cfg.
1 parent d9af95b commit 56721e7

7 files changed

+49
-6
lines changed
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib/galaxy/jobs/metrics
2+
lib/galaxy/exceptions

.ci/flake8_wrapper.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ set -e
55
flake8 --exclude `paste -sd, .ci/flake8_blacklist.txt` .
66

77
# Apply stricter rules for the directories shared with Pulsar
8-
flake8 --ignore= --max-line-length=150 lib/galaxy/jobs/runners/util/
8+
flake8 --ignore=D --max-line-length=150 lib/galaxy/jobs/runners/util/

.ci/flake8_wrapper_docstrings.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# D100 - Missing docstring in public module.
6+
# D2XX - Whitespace issues.
7+
# D3XX - Quoting issues.
8+
# D401 - First line should be in imperative mood
9+
# D403 - First word of the first line should be properly capitalized
10+
args="--ignore=D --select=D100,D201,D202,D206,D207,D208,D209,D211,D3,D401,D403"
11+
12+
# If the first argument is --include, lint the modules expected to pass. If
13+
# the first argument is --exclude, lint all modules the full Galaxy linter lints
14+
# (this will fail).
15+
16+
if [ "$1" = "--include" ];
17+
then
18+
flake8 $args `paste .ci/flake8_docstrings_include_list.txt`
19+
else
20+
flake8 $args --exclude `paste -sd, .ci/flake8_blacklist.txt` .
21+
fi

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ env:
1111
- TOX_ENV=py27-lint-imports
1212
- TOX_ENV=py27-lint-imports-include-list
1313
- TOX_ENV=validate-test-tools
14+
- TOX_ENV=py27-lint-docstring-include-list
1415

1516
matrix:
1617
include:

lib/galaxy/util/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ def mask_password_from_url( url ):
570570

571571

572572
def ready_name_for_url( raw_name ):
573-
""" General method to convert a string (i.e. object name) to a URL-ready
573+
u""" General method to convert a string (i.e. object name) to a URL-ready
574574
slug.
575575
576576
>>> ready_name_for_url( "My Cool Object" )

setup.cfg

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
[flake8]
2-
# These are exceptions allowed (encouraged?) by Galaxy style guidelines.
2+
# These are exceptions allowed by Galaxy style guidelines.
33
# 128 continuation line under-indented for visual indent
44
# 201 and 202 are spaces after ( and before )
55
# 203 whitespace before ':'
66
# 402 module level import not at top of file # TODO, we would like to improve this.
77
# 501 is line length
88
# W503 is line breaks before binary operators, which has been reversed in PEP 8.
9-
ignore = E128,E201,E202,E203,E501,E402,W503
9+
# D** are docstring linting - which we mostly ignore except D302. (Hopefully we will solve more over time).
10+
ignore = E128,E201,E202,E203,E501,E402,W503,D100,D101,D102,D103,D104,D105,D200,D201,D202,D204,D205,D206,D207,D208,D209,D210,D211,D300,D301,D400,D401,D402,D403
1011
exclude = lib/galaxy/util/jstree.py
1112
# For flake8-import-order
1213
# https://github.com/PyCQA/flake8-import-order/blob/master/tests/test_cases/complete_smarkets.py

tox.ini

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
[tox]
2-
envlist = py27-lint, py27-lint-imports, py27-lint-imports-include-list, py27-unit, qunit, mako-count, web-controller-line-count, py33-lint, py34-lint, py35-lint, validate-test-tools
2+
envlist = py27-lint, py27-lint-imports, py27-lint-imports-include-list, py27-unit, qunit, mako-count, web-controller-line-count, py33-lint, py34-lint, py35-lint, validate-test-tools, py27-lint-docstring-include-list, py27-lint-docstring
33
skipsdist = True
44

55
[testenv:py27-lint]
66
commands = bash .ci/flake8_wrapper.sh
77
whitelist_externals = bash
8-
deps = flake8
8+
deps =
9+
flake8
10+
flake8_docstrings==1.0.2
911

1012
[testenv:py33-lint]
1113
commands = bash .ci/flake8_py3_wrapper.sh
@@ -70,3 +72,19 @@ whitelist_externals = bash
7072
[testenv:validate-test-tools]
7173
commands = bash .ci/validate_test_tools.sh
7274
whitelist_externals = bash
75+
76+
[testenv:py27-lint-docstring]
77+
commands = bash .ci/flake8_wrapper_docstrings.sh --exclude
78+
whitelist_externals = bash
79+
skip_install = True
80+
deps =
81+
flake8
82+
flake8-docstrings==1.0.2
83+
84+
[testenv:py27-lint-docstring-include-list]
85+
commands = bash .ci/flake8_wrapper_docstrings.sh --include
86+
whitelist_externals = bash
87+
skip_install = True
88+
deps =
89+
flake8
90+
flake8-docstrings==1.0.2

0 commit comments

Comments
 (0)