Skip to content

Commit

Permalink
Merge pull request pytest-dev#169 from nicoddemus/pre-commit-black
Browse files Browse the repository at this point in the history
Add pre-commit for style checks and use black as formatter
  • Loading branch information
goodboy authored Aug 3, 2018
2 parents 962d674 + 9940cf2 commit 6587ed0
Show file tree
Hide file tree
Showing 34 changed files with 446 additions and 285 deletions.
32 changes: 32 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
repos:
- repo: https://github.com/ambv/black
rev: 18.6b4
hooks:
- id: black
args: [--safe, --quiet]
language_version: python3.6
- repo: https://github.com/asottile/blacken-docs
rev: v0.2.0
hooks:
- id: blacken-docs
additional_dependencies: [black==18.6b4]
language_version: python3.6
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: flake8
- repo: local
hooks:
- id: rst
name: rst
entry: rst-lint --encoding utf-8
files: ^(CHANGELOG.rst|HOWTORELEASE.rst|README.rst|changelog/.*)$
language: python
additional_dependencies: [pygments, restructuredtext_lint]
python_version: python3.6
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.0.0
hooks:
- id: rst-backticks
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ language: python
jobs:
include:
- python: '3.6'
env: TOXENV=check
env: TOXENV=linting
- python: '3.6'
env: TOXENV=docs
- python: '2.7'
Expand Down
1 change: 0 additions & 1 deletion HOWTORELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ Release Procedure
#. Make sure it is `available on PyPI <https://pypi.org/project/pluggy>`_.

#. Merge the PR into ``master``, either manually or using GitHub's web interface.

3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 holger krekel (rather uses bitbucket/hpk42)
Copyright (c) 2015 holger krekel (rather uses bitbucket/hpk42)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

20 changes: 16 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pluggy - A minimalist production ready plugin system
====================================================

|pypi| |anaconda| |versions| |travis| |appveyor| |gitter|
|pypi| |anaconda| |versions| |travis| |appveyor| |gitter| |black|

This is the core framework used by the `pytest`_, `tox`_, and `devpi`_ projects.

Expand All @@ -21,6 +21,7 @@ A definitive example
class MySpec(object):
"""A hook specification namespace.
"""
@hookspec
def myhook(self, arg1, arg2):
"""My special little hook that you can customize.
Expand All @@ -30,6 +31,7 @@ A definitive example
class Plugin_1(object):
"""A hook implementation namespace.
"""
@hookimpl
def myhook(self, arg1, arg2):
print("inside Plugin_1.myhook()")
Expand All @@ -39,6 +41,7 @@ A definitive example
class Plugin_2(object):
"""A 2nd hook implementation namespace.
"""
@hookimpl
def myhook(self, arg1, arg2):
print("inside Plugin_2.myhook()")
Expand All @@ -53,25 +56,34 @@ A definitive example
pm.register(Plugin_1())
pm.register(Plugin_2())
# call our `myhook` hook
# call our ``myhook`` hook
results = pm.hook.myhook(arg1=1, arg2=2)
print(results)
.. badges
.. |pypi| image:: https://img.shields.io/pypi/v/pluggy.svg
:target: https://pypi.org/pypi/pluggy

.. |versions| image:: https://img.shields.io/pypi/pyversions/pluggy.svg
:target: https://pypi.org/pypi/pluggy

.. |travis| image:: https://img.shields.io/travis/pytest-dev/pluggy/master.svg
:target: https://travis-ci.org/pytest-dev/pluggy

.. |appveyor| image:: https://img.shields.io/appveyor/ci/pytestbot/pluggy/master.svg
:target: https://ci.appveyor.com/project/pytestbot/pluggy

.. |anaconda| image:: https://anaconda.org/conda-forge/pluggy/badges/version.svg
:target: https://anaconda.org/conda-forge/pluggy
:target: https://anaconda.org/conda-forge/pluggy

.. |gitter| image:: https://badges.gitter.im/pytest-dev/pluggy.svg
:alt: Join the chat at https://gitter.im/pytest-dev/pluggy
:target: https://gitter.im/pytest-dev/pluggy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
:target: https://gitter.im/pytest-dev/pluggy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge

.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black

.. links
.. _pytest:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
environment:
matrix:
# note: please use "tox --listenvs" to populate the build matrix below
- TOXENV: "check"
- TOXENV: "linting"
- TOXENV: "docs"
- TOXENV: "py27-pytestrelease"
- TOXENV: "py34-pytestrelease"
Expand Down
2 changes: 1 addition & 1 deletion changelog/165.trivial.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add changelog in long package description and documentation.
Add changelog in long package description and documentation.
65 changes: 34 additions & 31 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,54 @@


extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.coverage",
"sphinx.ext.viewcode",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.

dist = pkg_resources.get_distribution('pluggy')
dist = pkg_resources.get_distribution("pluggy")
project = dist.project_name
copyright = u'2016, Holger Krekel'
author = 'Holger Krekel'
copyright = u"2016, Holger Krekel"
author = "Holger Krekel"

release = dist.version
# The short X.Y version.
version = u'.'.join(dist.version.split('.')[:2])
version = u".".join(dist.version.split(".")[:2])


language = None

pygments_style = 'sphinx'
html_logo = '_static/img/plug.png'
html_theme = 'alabaster'
pygments_style = "sphinx"
html_logo = "_static/img/plug.png"
html_theme = "alabaster"
html_theme_options = {
# 'logo': 'img/plug.png',
# 'logo_name': 'true',
'description': 'The `pytest` plugin system',
'github_user': 'pytest-dev',
'github_repo': 'pluggy',
'github_button': 'true',
'github_banner': 'true',
'page_width': '1080px',
'fixed_sidebar': 'false',
"description": "The `pytest` plugin system",
"github_user": "pytest-dev",
"github_repo": "pluggy",
"github_button": "true",
"github_banner": "true",
"page_width": "1080px",
"fixed_sidebar": "false",
}
html_static_path = ['_static']
html_static_path = ["_static"]

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'pluggy', u'pluggy Documentation',
[author], 1)
]
man_pages = [(master_doc, "pluggy", u"pluggy Documentation", [author], 1)]


# -- Options for Texinfo output -------------------------------------------
Expand All @@ -62,10 +59,16 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'pluggy', u'pluggy Documentation',
author, 'pluggy', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"pluggy",
u"pluggy Documentation",
author,
"pluggy",
"One line description of project.",
"Miscellaneous",
)
]

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping = {"https://docs.python.org/": None}
4 changes: 3 additions & 1 deletion docs/examples/eggsample-spam/eggsample_spam.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import eggsample


@eggsample.hookimpl
def eggsample_add_ingredients(ingredients):
"""Here the caller expects us to return a list."""
Expand All @@ -9,12 +10,13 @@ def eggsample_add_ingredients(ingredients):
spam = ["splendiferous spam", "magnificent spam"]
return spam


@eggsample.hookimpl
def eggsample_prep_condiments(condiments):
"""Here the caller passes a mutable object, so we mess with it directly."""
try:
del condiments["steak sauce"]
except KeyError:
pass
condiments['spam sauce'] = 42
condiments["spam sauce"] = 42
return f"Now this is what I call a condiments tray!"
9 changes: 6 additions & 3 deletions docs/examples/eggsample-spam/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from setuptools import setup

setup(name="eggsample-spam", install_requires="eggsample",
entry_points={'eggsample': ['spam = eggsample_spam']},
py_modules=['eggsample_spam'])
setup(
name="eggsample-spam",
install_requires="eggsample",
entry_points={"eggsample": ["spam = eggsample_spam"]},
py_modules=["eggsample_spam"],
)
2 changes: 2 additions & 0 deletions docs/examples/eggsample/eggsample/hookspecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

hookspec = pluggy.HookspecMarker("eggsample")


@hookspec
def eggsample_add_ingredients(ingredients: tuple):
"""Have a look at the ingredients and offer your own.
Expand All @@ -10,6 +11,7 @@ def eggsample_add_ingredients(ingredients: tuple):
:return: a list of ingredients
"""


@hookspec
def eggsample_prep_condiments(condiments: dict):
"""Reorganize the condiments tray to your heart's content.
Expand Down
12 changes: 9 additions & 3 deletions docs/examples/eggsample/eggsample/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@

condiments_tray = {"pickled walnuts": 13, "steak sauce": 4, "mushy peas": 2}


def main():
pm = get_plugin_manager()
cook = EggsellentCook(pm.hook)
cook.add_ingredients()
cook.prepare_the_food()
cook.serve_the_food()


def get_plugin_manager():
pm = pluggy.PluginManager("eggsample")
pm.add_hookspecs(hookspecs)
pm.load_setuptools_entrypoints("eggsample")
pm.register(lib)
return pm


class EggsellentCook:
FAVORITE_INGREDIENTS = ("egg", "egg", "egg")

Expand All @@ -30,7 +33,8 @@ def __init__(self, hook):

def add_ingredients(self):
results = self.hook.eggsample_add_ingredients(
ingredients=self.FAVORITE_INGREDIENTS)
ingredients=self.FAVORITE_INGREDIENTS
)
my_ingredients = list(self.FAVORITE_INGREDIENTS)
# Each hook returns a list - so we chain this list of lists
other_ingredients = list(itertools.chain(*results))
Expand All @@ -41,11 +45,13 @@ def prepare_the_food(self):

def serve_the_food(self):
condiment_comments = self.hook.eggsample_prep_condiments(
condiments=condiments_tray)
condiments=condiments_tray
)
print(f"Your food. Enjoy some {', '.join(self.ingredients)}")
print(f"Some condiments? We have {', '.join(condiments_tray.keys())}")
if any(condiment_comments):
print("\n".join(condiment_comments))

if __name__ == '__main__':

if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions docs/examples/eggsample/eggsample/lib.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import eggsample


@eggsample.hookimpl
def eggsample_add_ingredients():
spices = ["salt", "pepper"]
you_can_never_have_enough_eggs = ["egg", "egg"]
ingredients = spices + you_can_never_have_enough_eggs
return ingredients


@eggsample.hookimpl
def eggsample_prep_condiments(condiments):
condiments["mint sauce"] = 1
9 changes: 6 additions & 3 deletions docs/examples/eggsample/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from setuptools import setup, find_packages

setup(name="eggsample", install_requires="pluggy>=0.3,<1.0",
entry_points={'console_scripts': ['eggsample=eggsample.host:main']},
packages=find_packages())
setup(
name="eggsample",
install_requires="pluggy>=0.3,<1.0",
entry_points={"console_scripts": ["eggsample=eggsample.host:main"]},
packages=find_packages(),
)
3 changes: 3 additions & 0 deletions docs/examples/toy-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@

class MySpec(object):
"""A hook specification namespace."""

@hookspec
def myhook(self, arg1, arg2):
"""My special little hook that you can customize."""


class Plugin_1(object):
"""A hook implementation namespace."""

@hookimpl
def myhook(self, arg1, arg2):
print("inside Plugin_1.myhook()")
Expand All @@ -21,6 +23,7 @@ def myhook(self, arg1, arg2):

class Plugin_2(object):
"""A 2nd hook implementation namespace."""

@hookimpl
def myhook(self, arg1, arg2):
print("inside Plugin_2.myhook()")
Expand Down
Loading

0 comments on commit 6587ed0

Please sign in to comment.