Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pydocstyle to static checks #53

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .nengobones.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ manifest_in: {}
setup_py:
entry_points:
console_scripts:
- bones-generate=nengo_bones.scripts.generate_bones:main
- bones-check=nengo_bones.scripts.check_bones:main
- bones-pr-number=nengo_bones.scripts.pr_number:main
- bones-generate = nengo_bones.scripts.generate_bones:main
- bones-check = nengo_bones.scripts.check_bones:main
- bones-pr-number = nengo_bones.scripts.pr_number:main
include_package_data: True
# note: docs/tests_req are intentionally empty to test that the correct
# requirements are built into the ci scripts
Expand Down Expand Up @@ -151,6 +151,7 @@ setup_cfg:
ignore:
- nengo_bones/tests/ignoreme


docs_conf_py:
exclude_patterns:
- tests/test-example.ipynb
Expand Down
24 changes: 8 additions & 16 deletions nengo_bones/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@


def check_list(cfg, key):
"""
Verify that config value is a list.
"""Verify that config value is a list.

This is designed to catch the common error of specifying

Expand Down Expand Up @@ -45,8 +44,7 @@ def check_list(cfg, key):


def find_config():
"""
Finds the default nengo-bones config file.
"""Find the default nengo-bones config file.

Returns
-------
Expand All @@ -60,8 +58,7 @@ def find_config():


def fill_defaults(config):
"""
Fills in default values in a loaded config (in-place).
"""Fill in default values in a loaded config (in-place).

Parameters
----------
Expand Down Expand Up @@ -127,8 +124,7 @@ def fill_defaults(config):


def validate_black_config(config):
"""
Validates aspects of the config related to Black.
"""Validate aspects of the config related to Black.

Parameters
----------
Expand Down Expand Up @@ -157,8 +153,7 @@ def validate_black_config(config):


def validate_setup_cfg_config(config):
"""
Validates the ``setup_cfg`` section of the config.
"""Validate the ``setup_cfg`` section of the config.

Parameters
----------
Expand All @@ -176,8 +171,7 @@ def validate_setup_cfg_config(config):


def validate_config(config): # noqa: C901
"""
Validates a populated config dict.
"""Validate a populated config dict.

Parameters
----------
Expand Down Expand Up @@ -209,8 +203,7 @@ def validate_config(config): # noqa: C901


def validate_ci_config(ci_config):
"""
Validates an entry in the ci_scripts list of a config dict.
"""Validate an entry in the ci_scripts list of a config dict.

Parameters
----------
Expand All @@ -237,8 +230,7 @@ def validate_ci_config(ci_config):


def load_config(conf_file=None):
"""
Loads config values from a file and applies defaults/validation.
"""Load config values from a file and apply defaults/validation.

Parameters
----------
Expand Down
3 changes: 1 addition & 2 deletions nengo_bones/scripts/check_bones.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"--verbose", is_flag=True, help="Show more information about failed checks."
)
def main(root_dir, conf_file, verbose):
"""
Validates auto-generated project files.
"""Validate auto-generated project files.

Note: This does not check the ci scripts, because those are generated
on-the-fly in TravisCI (so any ci files we do find are likely local
Expand Down
5 changes: 2 additions & 3 deletions nengo_bones/scripts/generate_bones.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@


def render_template(ctx, output_file):
"""
Render a template to file.
"""Render a template to file.

Parameters
----------
Expand All @@ -33,7 +32,7 @@ def render_template(ctx, output_file):
@click.option("--output-dir", default=".", help="Output directory for scripts")
@click.pass_context
def main(ctx, conf_file, output_dir):
"""Loads config file and sets up template environment.
"""Load config file and set up template environment.

By default, this updates all templated files that are
to be committed to the repository.
Expand Down
14 changes: 5 additions & 9 deletions nengo_bones/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@


class BonesTemplate:
"""
A templated file known to Nengo Bones.
"""A templated file known to Nengo Bones.

The only necessary information is the output filename, relative to the
``templates`` directory, which means that the output filename for the
Expand Down Expand Up @@ -60,8 +59,7 @@ def __init__(self, output_file, env):
self.template_file = "%s.template" % (output_file,)

def get_render_data(self, config):
"""
Construct the ``data`` that will be used to render this template.
"""Construct the ``data`` that will be used to render this template.

This method creates a new dictionary so the original ``config``
is not modified. Additionally, certain sections have
Expand Down Expand Up @@ -116,8 +114,7 @@ def get_render_data(self, config):
return data

def render(self, **data):
"""
Render this template to a string.
"""Render this template to a string.

Parameters
----------
Expand Down Expand Up @@ -145,8 +142,7 @@ def render(self, **data):
return rendered

def render_to_file(self, output_dir, output_name=None, **data):
"""
Render a template to file.
"""Render a template to file.

.. note:: Rendered shell scripts (files with the ``.sh extension``)
are automatically marked as executable.
Expand Down Expand Up @@ -178,7 +174,7 @@ def render_to_file(self, output_dir, output_name=None, **data):


def load_env():
"""Creates a jinja environment for loading/rendering templates."""
"""Create a jinja environment for loading/rendering templates."""

bones_toplevel = os.path.normpath(os.path.dirname(__file__))

Expand Down
18 changes: 18 additions & 0 deletions nengo_bones/templates/setup.cfg.template
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,28 @@ plt_filename_drop =
{% endif %}
{% endblock %}

{% block pydocstyle %}
[pydocstyle]
ignore =
D10,
D202,
D203,
D213,
D401,
D402,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably also want D401, which is the imperative mood one. Also, maybe we should put comments after each of these lines with a word or two saying what it is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message of d2ce6d5 gives my thoughts on D401

Copy link
Member Author

@tbekolay tbekolay Aug 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I'd rather just link to http://www.pydocstyle.org/en/3.0.0/error_codes.html ... we don't give description for flake8, which is similarly code-based

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does take a bit of work to cross-reference the two lists, but not many people are going to be editing this, so it's not a big deal to me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, D415 and D416 are missing from that list? They need to update their docs!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah they actually have a problem with their current docs right now as they don't render the table: PyCQA/pydocstyle#380

D405,
D413,
D415,
D416,
match-dir = '[^\._].*'
{% endblock %}

{% block pylint %}
[pylint]
# note: pylint doesn't look in setup.cfg by default, need to call it with
# `pylint ... --rcfile=setup.cfg`
# Also, this needs to be the last section in this file, so any additional
# configuration must be added above here.
{% if pylint.ignore %}
ignore =
{% for ignore in pylint.ignore %}
Expand Down
3 changes: 2 additions & 1 deletion nengo_bones/templates/static.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ shopt -s globstar

{% block install %}
{{ super() }}
exe pip install "jupyter>=1.0.0" "pylint>=1.9.2" "codespell>=1.12.0" "gitlint>=0.1.2" "collective.checkdocs>=0.2" "flake8>=3.7.7"
exe pip install "jupyter>=1.0.0" "pylint>=1.9.2" "codespell>=1.12.0" "gitlint>=0.1.2" "collective.checkdocs>=0.2" "flake8>=3.7.7" "pydocstyle>=4.0.0"
{% endblock %}

{% block script %}
exe pylint {{ pkg_name }} --rcfile=setup.cfg --jobs=0
exe flake8 {{ pkg_name }}
exe pydocstyle {{ pkg_name }}
if ls docs/**/*.ipynb &>/dev/null; then
exe jupyter nbconvert \
--log-level WARN \
Expand Down
4 changes: 2 additions & 2 deletions nengo_bones/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def write_file(tmpdir, filename, contents):
"""Writes a (multiline) string to file."""
"""Write a (multiline) string to file."""

contents = contents.splitlines()

Expand Down Expand Up @@ -37,7 +37,7 @@ def assert_exit(result, status):


def make_has_line(lines, strip=False, regex=False):
"""Create a function to check file or output lines in order"""
"""Create a function to check file or output lines in order."""

idx = 0

Expand Down
16 changes: 16 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,25 @@ nengo_test_unsupported =
*
"All tests are unsupported"

[pydocstyle]
ignore =
D10,
D202,
D203,
D213,
D401,
D402,
D405,
D413,
D415,
D416,
match-dir = '[^\._].*'

[pylint]
# note: pylint doesn't look in setup.cfg by default, need to call it with
# `pylint ... --rcfile=setup.cfg`
# Also, this needs to be the last section in this file, so any additional
# configuration must be added above here.
ignore =
nengo_bones/tests/ignoreme,
disable =
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def read(*filenames, **kwargs):
python_requires=">=3.5",
entry_points={
"console_scripts": [
"bones-generate=nengo_bones.scripts.generate_bones:main",
"bones-check=nengo_bones.scripts.check_bones:main",
"bones-pr-number=nengo_bones.scripts.pr_number:main",
"bones-generate = nengo_bones.scripts.generate_bones:main",
"bones-check = nengo_bones.scripts.check_bones:main",
"bones-pr-number = nengo_bones.scripts.pr_number:main",
]
},
classifiers=[
Expand Down