Skip to content

Commit

Permalink
Merge branch 'master' into pslisten
Browse files Browse the repository at this point in the history
  • Loading branch information
nlevitt committed Jan 21, 2018
2 parents 2015585 + 133bde7 commit f92f3bc
Show file tree
Hide file tree
Showing 141 changed files with 23,483 additions and 8,850 deletions.
4 changes: 2 additions & 2 deletions .ci/travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if [[ "$(uname -s)" == 'Darwin' ]]; then
fi

if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]] || [[ $PYVER == 'py26' ]]; then
pip install -U ipaddress unittest2 mock==1.0.1
pip install -U ipaddress unittest2 argparse mock==1.0.1
elif [[ $TRAVIS_PYTHON_VERSION == '2.7' ]] || [[ $PYVER == 'py27' ]]; then
pip install -U ipaddress mock
elif [[ $TRAVIS_PYTHON_VERSION == '3.2' ]] || [[ $PYVER == 'py32' ]]; then
Expand All @@ -51,4 +51,4 @@ elif [[ $TRAVIS_PYTHON_VERSION == '3.3' ]] || [[ $PYVER == 'py33' ]]; then
pip install -U ipaddress
fi

pip install coverage coveralls flake8 pep8 setuptools
pip install -U coverage coveralls flake8 pep8 setuptools
23 changes: 17 additions & 6 deletions .ci/travis/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,33 @@
set -e
set -x

PYVER=`python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))'`

# setup OSX
if [[ "$(uname -s)" == 'Darwin' ]]; then
if which pyenv > /dev/null; then
eval "$(pyenv init -)"
fi
pyenv activate psutil
fi

# install psutil
make clean
python setup.py build
python setup.py develop

if [[ "$(uname -s)" != 'Darwin' ]]; then
coverage run psutil/tests/runner.py --include="psutil/*" --omit="test/*,*setup*"
# run tests (with coverage)
if [[ $PYVER == '2.7' ]] && [[ "$(uname -s)" != 'Darwin' ]]; then
PSUTIL_TESTING=1 python -Wa -m coverage run psutil/tests/__main__.py
else
python psutil/tests/runner.py
PSUTIL_TESTING=1 python -Wa psutil/tests/__main__.py
fi

python psutil/tests/test_memory_leaks.py
flake8
pep8
if [ "$PYVER" == "2.7" ] || [ "$PYVER" == "3.6" ]; then
# run mem leaks test
PSUTIL_TESTING=1 python -Wa psutil/tests/test_memory_leaks.py
# run linter (on Linux only)
if [[ "$(uname -s)" != 'Darwin' ]]; then
python -m flake8
fi
fi
35 changes: 17 additions & 18 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@

include =
*psutil*

omit =
psutil/_compat.py
psutil/tests/*
setup.py
psutil/_compat.py

exclude_lines =
pragma: no cover
if PY3:
enum.IntEnum
except ImportError:
globals().update
if __name__ == .__main__.:
if sys.platform.startswith
if _WINDOWS:
import enum
if enum is not None:
if BSD
if enum is None:
if enum is not None:
if FREEBSD
if has_enums:
if LINUX
if LITTLE_ENDIAN:
enum.IntEnum
except ImportError:
raise NotImplementedError
if WINDOWS
if OSX
if BSD
if FREEBSD
if OPENBSD
if NETBSD
if SUNOS
if LINUX
if OPENBSD
if OSX
if ppid_map is None:
if PY3:
if SUNOS
if sys.platform.startswith
if WINDOWS
import enum
pragma: no cover
raise NotImplementedError
125 changes: 98 additions & 27 deletions .git-pre-commit
Original file line number Diff line number Diff line change
@@ -1,47 +1,118 @@
#!/usr/bin/env python

# This gets executed on 'git commit' and rejects the commit in case the
# submitted code does not pass validation.
# Install it with "make install-git-hooks"
# Copyright (c) 2009 Giampaolo Rodola'. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""
This gets executed on 'git commit' and rejects the commit in case the
submitted code does not pass validation. Validation is run only against
the *.py files which were modified in the commit. Checks:
- assert no space at EOLs
- assert not pdb.set_trace in code
- assert no bare except clause ("except:") in code
- assert "flake8" returns no warnings
Install this with "make install-git-hooks".
"""

from __future__ import print_function
import os
import subprocess
import sys


def term_supports_colors():
try:
import curses
assert sys.stderr.isatty()
curses.setupterm()
assert curses.tigetnum("colors") > 0
except Exception:
return False
else:
return True


def hilite(s, ok=True, bold=False):
"""Return an highlighted version of 'string'."""
if not term_supports_colors():
return s
attr = []
if ok is None: # no color
pass
elif ok: # green
attr.append('32')
else: # red
attr.append('31')
if bold:
attr.append('1')
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), s)


def exit(msg):
msg = hilite(msg, ok=False)
print(msg, file=sys.stderr)
sys.exit(1)


def sh(cmd):
"""run cmd in a subprocess and return its output.
raises RuntimeError on error.
"""
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, universal_newlines=True)
stdout, stderr = p.communicate()
if p.returncode != 0:
raise RuntimeError(stderr)
if stderr:
print(stderr, file=sys.stderr)
if stdout.endswith('\n'):
stdout = stdout[:-1]
return stdout


def main():
out = subprocess.check_output("git diff --cached --name-only", shell=True)
files = [x for x in out.split(b'\n') if x.endswith(b'.py') and
os.path.exists(x)]
out = sh("git diff --cached --name-only")
py_files = [x for x in out.split('\n') if x.endswith('.py') and
os.path.exists(x)]

for path in files:
lineno = 0
for path in py_files:
with open(path) as f:
data = f.read()

# pdb
if "pdb.set_trace" in data:
for lineno, line in enumerate(data.split('\n'), 1):
for line in f:
lineno += 1
# space at end of line
if line.endswith(' '):
print("%s:%s %r" % (path, lineno, line))
return exit(
"commit aborted: space at end of line")
line = line.rstrip()
# pdb
if "pdb.set_trace" in line:
print("%s: %s" % (lineno, line))
sys.exit(
print("%s:%s %s" % (path, lineno, line))
return exit(
"commit aborted: you forgot a pdb in your python code")

# bare except clause
if "except:" in data:
for lineno, line in enumerate(data.split('\n'), 1):
line = line.rstrip()
# bare except clause
if "except:" in line and not line.endswith("# NOQA"):
print("%s: %s" % (lineno, line))
sys.exit("commit aborted: bare except clause")
print("%s:%s %s" % (path, lineno, line))
return exit("commit aborted: bare except clause")

# flake8
failed = False
for path in files:
ret = subprocess.call("python -m flake8 %s" % path, shell=True)
if py_files:
try:
import flake8 # NOQA
except ImportError:
return exit("commit aborted: flake8 is not installed; "
"run 'make setup-dev-env'")

# XXX: we should scape spaces and possibly other amenities here
ret = subprocess.call(
"%s -m flake8 %s" % (sys.executable, " ".join(py_files)),
shell=True)
if ret != 0:
failed = True
if failed:
sys.exit("commit aborted: python code is not flake8-compliant")
return exit("commit aborted: python code is not flake8 compliant")


main()
21 changes: 5 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,26 @@ language: python
cache: pip
matrix:
include:
# Linux
- python: 2.6
- python: 2.7
- python: 3.3
- python: 3.4
- python: 3.5
- "pypy"
# XXX - commented because OSX builds are deadly slow
# - language: generic
# os: osx
# env: PYVER=py26
- python: 3.6
# OSX
- language: generic
os: osx
env: PYVER=py27
# XXX - commented because OSX builds are deadly slow
# - language: generic
# os: osx
# env: PYVER=py33
- language: generic
os: osx
env: PYVER=py34
# XXX - not supported yet
# - language: generic
# os: osx
# env: PYVER=py35
install:
- ./.ci/travis/install.sh
script:
- ./.ci/travis/run.sh
after_success:
# upload reports to coveralls.io
- |
if [ "$(uname -s)" != 'Darwin' ]; then
if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]] && [[ "$(uname -s)" != 'Darwin' ]]; then
echo "sending test coverage results to coveralls.io"
coveralls
fi
Loading

0 comments on commit f92f3bc

Please sign in to comment.