Skip to content

Commit

Permalink
STY: format code base with black and add CI tests to check conformanc…
Browse files Browse the repository at this point in the history
…e going forward
  • Loading branch information
qwhelan committed Oct 5, 2019
1 parent ac9db04 commit 8032e91
Show file tree
Hide file tree
Showing 30 changed files with 1,007 additions and 802 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ matrix:
PYTHON_ARCH="64"
TEST_RUN="sdist"

# flake8
# flake8 and black
- os: linux
env: TEST_DEPS="flake8"
env: TEST_DEPS="flake8 black"
PYTHON_VERSION="3.7"
PYTHON_ARCH="64"
TEST_RUN="style"
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ test:
flake8:
flake8

black:
black . --exclude "(build/|dist/|\.git/|\.mypy_cache/|\.tox/|\.venv/\.asv/|env|\.eggs)"

readme:
PYTHONPATH=`pwd`:PYTHONPATH ${PYTHON} tools/update_readme.py

Expand Down
53 changes: 39 additions & 14 deletions bottleneck/__init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,55 @@
try:
from .reduce import (nansum, nanmean, nanstd, nanvar, nanmin, nanmax,
median, nanmedian, ss, nanargmin, nanargmax, anynan,
allnan)
from .reduce import (
nansum,
nanmean,
nanstd,
nanvar,
nanmin,
nanmax,
median,
nanmedian,
ss,
nanargmin,
nanargmax,
anynan,
allnan,
)
from .nonreduce import replace
from .nonreduce_axis import (partition, argpartition, rankdata, nanrankdata,
push)
from .move import (move_sum, move_mean, move_std, move_var, move_min,
move_max, move_argmin, move_argmax, move_median,
move_rank)
from .nonreduce_axis import partition, argpartition, rankdata, nanrankdata, push
from .move import (
move_sum,
move_mean,
move_std,
move_var,
move_min,
move_max,
move_argmin,
move_argmax,
move_median,
move_rank,
)

from . import slow

except ImportError:
raise ImportError("bottleneck modules failed to import, likely due to a "
"mismatch in NumPy versions. Either upgrade numpy to "
"1.16+ or install with:\n\t"
"pip install --no-build-isolation --no-cache-dir "
"bottleneck")
raise ImportError(
"bottleneck modules failed to import, likely due to a "
"mismatch in NumPy versions. Either upgrade numpy to "
"1.16+ or install with:\n\t"
"pip install --no-build-isolation --no-cache-dir "
"bottleneck"
)

from bottleneck.benchmark.bench import bench
from bottleneck.benchmark.bench_detailed import bench_detailed
from bottleneck.tests.util import get_functions

from ._pytesttester import PytestTester

test = PytestTester(__name__)
del PytestTester

from ._version import get_versions # noqa: E402
__version__ = get_versions()['version']

__version__ = get_versions()["version"]
del get_versions
32 changes: 22 additions & 10 deletions bottleneck/_pytesttester.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sys


__all__ = ['PytestTester']
__all__ = ["PytestTester"]


class PytestTester(object):
Expand All @@ -21,14 +21,22 @@ class PytestTester(object):
def __init__(self, module_name):
self.module_name = module_name

def __call__(self, label="fast", verbose=1, extra_argv=None, doctests=False,
coverage=False, tests=None, parallel=None):
def __call__(
self,
label="fast",
verbose=1,
extra_argv=None,
doctests=False,
coverage=False,
tests=None,
parallel=None,
):
import pytest

module = sys.modules[self.module_name]
module_path = os.path.abspath(module.__path__[0])

pytest_args = ['-l']
pytest_args = ["-l"]

if doctests:
raise ValueError("Doctests not supported")
Expand All @@ -52,20 +60,23 @@ def __call__(self, label="fast", verbose=1, extra_argv=None, doctests=False,

if parallel is not None and parallel > 1:
if _pytest_has_xdist():
pytest_args += ['-n', str(parallel)]
pytest_args += ["-n", str(parallel)]
else:
import warnings
warnings.warn('Could not run tests in parallel because '
'pytest-xdist plugin is not available.')

pytest_args += ['--pyargs'] + list(tests)
warnings.warn(
"Could not run tests in parallel because "
"pytest-xdist plugin is not available."
)

pytest_args += ["--pyargs"] + list(tests)

try:
code = pytest.main(pytest_args)
except SystemExit as exc:
code = exc.code

return (code == 0)
return code == 0


def _pytest_has_xdist():
Expand All @@ -74,4 +85,5 @@ def _pytest_has_xdist():
"""
# Check xdist exists without importing, otherwise pytests emits warnings
from importlib.util import find_spec
return find_spec('xdist') is not None

return find_spec("xdist") is not None

0 comments on commit 8032e91

Please sign in to comment.