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

Use a plugin system (experimental) #180

Merged
merged 13 commits into from Jul 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions Makefile
Expand Up @@ -13,10 +13,14 @@ help:
@echo 'Run 'make -B' or 'make --always-make' to force a rebuild of all targets'
.PHONY: help

clean: # Clean all build output (cache, tox, coverage)
rm -rf .cache .mypy_cache .pytest_cache .tox docs/_build src/*.egg-info .coverage htmlcov/
clean: clean-test # Clean all build output (cache, tox, coverage)
rm -rf .cache .mypy_cache docs/_build src/*.egg-info
.PHONY: clean

clean-test: # Clean test output
rm -rf .pytest_cache .tox .coverage htmlcov/
.PHONY: clean-test

# Remove cache files if they are older than the configured time, so the targets will be rebuilt
# "fd" is a faster alternative to "find": https://github.com/sharkdp/fd
always-run:
Expand All @@ -25,13 +29,18 @@ always-run:
.PHONY: always-run

pre-commit .cache/make/long-pre-commit: .pre-commit-config.yaml .pre-commit-hooks.yaml # Update and install pre-commit hooks
pre-commit autoupdate
# TODO: isort 5.0.0 is apparently broken, so we can't autoupdate for now
# pre-commit autoupdate
pre-commit install --install-hooks
pre-commit install --hook-type commit-msg
pre-commit gc
touch .cache/make/long-pre-commit
.PHONY: pre-commit

# Poetry install is needed to create the Nitpick plugin entries on setuptools, used by pluggy
src/nitpick.egg-info/entry_points.txt: pyproject.toml
poetry install

poetry .cache/make/long-poetry: pyproject.toml # Update dependencies
poetry update
poetry install
Expand Down Expand Up @@ -63,6 +72,10 @@ endif
touch .cache/make/test
.PHONY: test

pytest: src/nitpick.egg-info/entry_points.txt # Run pytest on the poetry venv (to quickly run tests locally without waiting for tox)
poetry run python -m pytest
.PHONY: pytest

doc .cache/make/doc: docs/*/* styles/*/* *.rst *.md # Build documentation only
@rm -rf docs/source
tox -e docs
Expand Down
10 changes: 5 additions & 5 deletions docs/generate_rst.py
Expand Up @@ -16,12 +16,12 @@
from sortedcontainers import SortedDict

from nitpick.constants import RAW_GITHUB_CONTENT_BASE_URL
from nitpick.files.base import BaseFile
from nitpick.files.json import JSONFile
from nitpick.files.pre_commit import PreCommitFile
from nitpick.files.pyproject_toml import PyProjectTomlFile
from nitpick.files.setup_cfg import SetupCfgFile
from nitpick.generic import get_subclasses
from nitpick.plugins.base import BaseFile
from nitpick.plugins.json import JSONFile
from nitpick.plugins.pre_commit import PreCommitFile
from nitpick.plugins.pyproject_toml import PyProjectTomlFile
from nitpick.plugins.setup_cfg import SetupCfgFile

style_mapping = SortedDict(
{
Expand Down
2 changes: 1 addition & 1 deletion docs/nitpick_section.rst
Expand Up @@ -79,5 +79,5 @@ If a key/value pair appears in more than one sub-style, it will be overridden; t
[nitpick.JSONFile]
------------------

Configure the list of filenames that should be checked by the :py:class:`nitpick.files.json.JSONFile` class.
Configure the list of filenames that should be checked by the :py:class:`nitpick.plugins.json.JSONFile` class.
See :ref:`the default package.json style <default-package-json>` for an example of usage.
7 changes: 0 additions & 7 deletions docs/source/nitpick.files.base.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/source/nitpick.files.json.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/source/nitpick.files.pre_commit.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/source/nitpick.files.pyproject_toml.rst

This file was deleted.

19 changes: 0 additions & 19 deletions docs/source/nitpick.files.rst

This file was deleted.

7 changes: 0 additions & 7 deletions docs/source/nitpick.files.setup_cfg.rst

This file was deleted.

@@ -1,7 +1,7 @@
nitpick.plugin module
nitpick.flake8 module
=====================

.. automodule:: nitpick.plugin
.. automodule:: nitpick.flake8
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/nitpick.plugins.base.rst
@@ -0,0 +1,7 @@
nitpick.plugins.base module
===========================

.. automodule:: nitpick.plugins.base
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/nitpick.plugins.json.rst
@@ -0,0 +1,7 @@
nitpick.plugins.json module
===========================

.. automodule:: nitpick.plugins.json
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/nitpick.plugins.pre_commit.rst
@@ -0,0 +1,7 @@
nitpick.plugins.pre\_commit module
==================================

.. automodule:: nitpick.plugins.pre_commit
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/nitpick.plugins.pyproject_toml.rst
@@ -0,0 +1,7 @@
nitpick.plugins.pyproject\_toml module
======================================

.. automodule:: nitpick.plugins.pyproject_toml
:members:
:undoc-members:
:show-inheritance:
19 changes: 19 additions & 0 deletions docs/source/nitpick.plugins.rst
@@ -0,0 +1,19 @@
nitpick.plugins package
=======================

.. automodule:: nitpick.plugins
:members:
:undoc-members:
:show-inheritance:

Submodules
----------

.. toctree::
:maxdepth: 4

nitpick.plugins.base
nitpick.plugins.json
nitpick.plugins.pre_commit
nitpick.plugins.pyproject_toml
nitpick.plugins.setup_cfg
7 changes: 7 additions & 0 deletions docs/source/nitpick.plugins.setup_cfg.rst
@@ -0,0 +1,7 @@
nitpick.plugins.setup\_cfg module
=================================

.. automodule:: nitpick.plugins.setup_cfg
:members:
:undoc-members:
:show-inheritance:
4 changes: 2 additions & 2 deletions docs/source/nitpick.rst
Expand Up @@ -12,7 +12,7 @@ Subpackages
.. toctree::
:maxdepth: 4

nitpick.files
nitpick.plugins

Submodules
----------
Expand All @@ -25,10 +25,10 @@ Submodules
nitpick.constants
nitpick.exceptions
nitpick.fields
nitpick.flake8
nitpick.formats
nitpick.generic
nitpick.mixin
nitpick.plugin
nitpick.schemas
nitpick.style
nitpick.typedefs
41 changes: 28 additions & 13 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion pyproject.toml
Expand Up @@ -25,7 +25,13 @@ classifiers = [
]

[tool.poetry.plugins."flake8.extension"]
NIP = "nitpick.plugin:NitpickChecker"
NIP = "nitpick.flake8:NitpickExtension"

[tool.poetry.plugins.nitpick]
json = "nitpick.plugins.json"
pre_commit = "nitpick.plugins.pre_commit"
setup_cfg = "nitpick.plugins.setup_cfg"
pyproject_toml = "nitpick.plugins.pyproject_toml"

[tool.poetry.dependencies]
python = "^3.5 || ^3.6 || ^3.7 || ^3.8"
Expand All @@ -45,6 +51,9 @@ marshmallow = {version = ">=3.0.0b10"}
# Pin to avoid error on "flake8 ." when there is an invalid TOML style:
# TypeError: _deserialize() got an unexpected keyword argument 'partial'
marshmallow-polyfield = "^5.7"
identify = "*"
"more-itertools" = "*"
pluggy = "*"

pylint = {version = "*", optional = true}
pytest = {version = "*", optional = true}
Expand Down
7 changes: 5 additions & 2 deletions setup.cfg
Expand Up @@ -50,7 +50,7 @@ include_trailing_comma = True
force_grid_wrap = 0
combine_as_imports = True
known_first_party = tests,nitpick
known_third_party = _pytest,attr,click,dictdiffer,flake8,jmespath,marshmallow,marshmallow_polyfield,pytest,requests,responses,ruamel,slugify,sortedcontainers,testfixtures,toml
known_third_party = _pytest,attr,click,dictdiffer,flake8,identify,jmespath,marshmallow,marshmallow_polyfield,more_itertools,pluggy,pytest,requests,responses,ruamel,slugify,sortedcontainers,testfixtures,toml

[mypy]
ignore_missing_imports = True
Expand Down Expand Up @@ -85,9 +85,12 @@ extras = test
depends =
{py39,py38,py37,py36,py35}: clean
report: py39,py38,py37,py36,py35
setenv =
# I had this error locally, but it worked on Travis CI: https://github.com/pytest-dev/pytest/issues/2042
PY_IGNORE_IMPORTMISMATCH = 1
commands =
# https://pytest-cov.readthedocs.io/en/latest/config.html
pytest --cov-config=setup.cfg --cov --cov-append --cov-report=term-missing --doctest-modules {posargs:-vv}
python -m pytest --cov-config=setup.cfg --cov --cov-append --cov-report=term-missing --doctest-modules {posargs:-vv}

# https://pytest-cov.readthedocs.io/en/latest/tox.html
[testenv:clean]
Expand Down