Skip to content

adapt Pre commit hook and black #3485

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

Merged
merged 17 commits into from
May 25, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
exclude: doc/en/example/py2py3/test_py2.py
repos:
- repo: https://github.com/ambv/black
rev: 18.4a4
hooks:
- id: black
args: [--safe, --quiet]
python_version: python3.6
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
exclude: _pytest/debugging.py
- id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v1.2.0
hooks:
- id: pyupgrade
- repo: local
hooks:
- id: rst
name: rst
entry: python scripts/check-rst.py
language: python
additional_dependencies: [pygments, restructuredtext_lint]
python_version: python3.6
14 changes: 13 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
sudo: false
language: python
stages:
- linting
- test
- deploy
python:
- '3.6'
install:
Expand All @@ -9,7 +13,7 @@ env:
# coveralls is not listed in tox's envlist, but should run in travis
- TOXENV=coveralls
# note: please use "tox --listenvs" to populate the build matrix below
- TOXENV=linting
# please remove the linting env in all cases
- TOXENV=py27
- TOXENV=py34
- TOXENV=py36
Expand Down Expand Up @@ -53,6 +57,14 @@ jobs:
on:
tags: true
repo: pytest-dev/pytest
- stage: linting
python: '3.6'
env:
install:
- pip install pre-commit
- pre-commit install-hooks
script:
- pre-commit run --all-files

script: tox --recreate

Expand Down
21 changes: 16 additions & 5 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Here's a rundown of how a repository transfer usually proceeds
* ``joedoe`` transfers repository ownership to ``pytest-dev`` administrator ``calvin``.
* ``calvin`` creates ``pytest-xyz-admin`` and ``pytest-xyz-developers`` teams, inviting ``joedoe`` to both as **maintainer**.
* ``calvin`` transfers repository to ``pytest-dev`` and configures team access:

- ``pytest-xyz-admin`` **admin** access;
- ``pytest-xyz-developers`` **write** access;

Expand All @@ -163,6 +163,7 @@ Short version
~~~~~~~~~~~~~

#. Fork the repository;
#. enable and install pre-commit https://pre-commit.com/ to ensure styleguides and codechecks are followed
#. Target ``master`` for bugfixes and doc changes;
#. Target ``features`` for new features or functionality changes.
#. Follow **PEP-8**. There's a ``tox`` command to help fixing it: ``tox -e fix-lint``.
Expand Down Expand Up @@ -202,20 +203,30 @@ Here is a simple overview, with pytest-specific bits:
$ git clone [email protected]:YOUR_GITHUB_USERNAME/pytest.git
$ cd pytest
# now, to fix a bug create your own branch off "master":

$ git checkout -b your-bugfix-branch-name master

# or to instead add a feature create your own branch off "features":

$ git checkout -b your-feature-branch-name features

Given we have "major.minor.micro" version numbers, bugfixes will usually
be released in micro releases whereas features will be released in
Given we have "major.minor.micro" version numbers, bugfixes will usually
be released in micro releases whereas features will be released in
minor releases and incompatible changes in major releases.

If you need some help with Git, follow this quick start
guide: https://git.wiki.kernel.org/index.php/QuickStart

#. install pre-commit and install its hook on the pytest repo

https://pre-commit.com/ is a framework for managing and maintaining multi-language pre-commit hooks
pytest uses pre-commit to ensure code-style and code formatting is the same

$ pip install --user pre-commit
$ pre-commit install

Afterwards pre-commit will run whenever you commit.

#. Install tox

Tox is used to run all the tests and will automatically setup virtualenvs
Expand Down
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
.. image:: https://ci.appveyor.com/api/projects/status/mrgbjaua7t33pg6b?svg=true
:target: https://ci.appveyor.com/project/pytestbot/pytest

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

.. image:: https://www.codetriage.com/pytest-dev/pytest/badges/users.svg
:target: https://www.codetriage.com/pytest-dev/pytest

Expand Down
4 changes: 2 additions & 2 deletions _pytest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
__all__ = ['__version__']
__all__ = ["__version__"]

try:
from ._version import version as __version__
except ImportError:
# broken installation, we don't even try
# unknown only works because we do poor mans version compare
__version__ = 'unknown'
__version__ = "unknown"
16 changes: 10 additions & 6 deletions _pytest/_argcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@


class FastFilesCompleter(object):
'Fast file completer class'
"Fast file completer class"

def __init__(self, directories=True):
self.directories = directories
Expand All @@ -74,21 +74,21 @@ def __call__(self, prefix, **kwargs):
prefix_dir = 0
completion = []
globbed = []
if '*' not in prefix and '?' not in prefix:
if "*" not in prefix and "?" not in prefix:
# we are on unix, otherwise no bash
if not prefix or prefix[-1] == os.path.sep:
globbed.extend(glob(prefix + '.*'))
prefix += '*'
globbed.extend(glob(prefix + ".*"))
prefix += "*"
globbed.extend(glob(prefix))
for x in sorted(globbed):
if os.path.isdir(x):
x += '/'
x += "/"
# append stripping the prefix (like bash, not like compgen)
completion.append(x[prefix_dir:])
return completion


if os.environ.get('_ARGCOMPLETE'):
if os.environ.get("_ARGCOMPLETE"):
try:
import argcomplete.completers
except ImportError:
Expand All @@ -97,7 +97,11 @@ def __call__(self, prefix, **kwargs):

def try_argcomplete(parser):
argcomplete.autocomplete(parser, always_complete_options=False)


else:

def try_argcomplete(parser):
pass

filescompleter = None
24 changes: 14 additions & 10 deletions _pytest/_code/_py2traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
from __future__ import absolute_import, division, print_function
import types
from six import text_type


def format_exception_only(etype, value):
Expand All @@ -29,9 +30,12 @@ def format_exception_only(etype, value):
#
# Clear these out first because issubtype(string1, SyntaxError)
# would throw another exception and mask the original problem.
if (isinstance(etype, BaseException) or
isinstance(etype, types.InstanceType) or
etype is None or type(etype) is str):
if (
isinstance(etype, BaseException)
or isinstance(etype, types.InstanceType)
or etype is None
or type(etype) is str
):
return [_format_final_exc_line(etype, value)]

stype = etype.__name__
Expand All @@ -50,14 +54,14 @@ def format_exception_only(etype, value):
lines.append(' File "%s", line %d\n' % (filename, lineno))
if badline is not None:
if isinstance(badline, bytes): # python 2 only
badline = badline.decode('utf-8', 'replace')
lines.append(u' %s\n' % badline.strip())
badline = badline.decode("utf-8", "replace")
lines.append(u" %s\n" % badline.strip())
if offset is not None:
caretspace = badline.rstrip('\n')[:offset].lstrip()
caretspace = badline.rstrip("\n")[:offset].lstrip()
# non-space whitespace (likes tabs) must be kept for alignment
caretspace = ((c.isspace() and c or ' ') for c in caretspace)
caretspace = ((c.isspace() and c or " ") for c in caretspace)
# only three spaces to account for offset1 == pos 0
lines.append(' %s^\n' % ''.join(caretspace))
lines.append(" %s^\n" % "".join(caretspace))
value = msg

lines.append(_format_final_exc_line(stype, value))
Expand All @@ -76,10 +80,10 @@ def _format_final_exc_line(etype, value):

def _some_str(value):
try:
return unicode(value)
return text_type(value)
except Exception:
try:
return str(value)
except Exception:
pass
return '<unprintable %s object>' % type(value).__name__
return "<unprintable %s object>" % type(value).__name__
Loading