Skip to content

Commit

Permalink
Include flake8 test as well as test to make sure that the version can…
Browse files Browse the repository at this point in the history
… be accessed without dependencies installed
  • Loading branch information
astrofrog committed Jun 16, 2018
1 parent 9dd8772 commit 8bea13b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ env:
- PYTHON_VERSION=3.3 PSUTIL_VERSION=3
- PYTHON_VERSION=3.4 PSUTIL_VERSION=4
- PYTHON_VERSION=3.5 PSUTIL_VERSION=5
- PYTHON_VERSION=3.6 PSUTIL_VERSION=5
global:
- CONDA_DEPENDENCIES='numpy matplotlib psutil'
- CONDA_DEPENDENCIES='matplotlib psutil'
- PIP_DEPENDENCIES='coveralls pytest-cov'
- SETUP_XVFB=True

before_install:
# Make sure we can get the version without any dependencies installed
- python setup.py --version
- git clone git://github.com/astropy/ci-helpers.git
- source ci-helpers/travis/setup_conda.sh

script:
- flake8 psrecord
- py.test --cov psrecord psrecord
- python setup.py check --restructuredtext

Expand Down
23 changes: 12 additions & 11 deletions psrecord/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from .main import main
from .main import main # noqa

__version__ = '1.1.dev0'
11 changes: 7 additions & 4 deletions psrecord/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from __future__ import (unicode_literals, division, print_function,
absolute_import)

import psutil
import time
import argparse

Expand Down Expand Up @@ -97,7 +96,7 @@ def main():
pid = int(args.process_id_or_command)
print("Attaching to process {0}".format(pid))
sprocess = None
except:
except Exception:
import subprocess
command = args.process_id_or_command
print("Starting up command '{0}' and attaching to process"
Expand All @@ -115,6 +114,10 @@ def main():
def monitor(pid, logfile=None, plot=None, duration=None, interval=None,
include_children=False):

# We import psutil here so that the module can be imported even if psutil
# is not present (for example if accessing the version)
import psutil

pr = psutil.Process(pid)

# Record start time
Expand Down Expand Up @@ -164,7 +167,7 @@ def monitor(pid, logfile=None, plot=None, duration=None, interval=None,
try:
current_cpu = get_percent(pr)
current_mem = get_memory(pr)
except:
except Exception:
break
current_mem_real = current_mem.rss / 1024. ** 2
current_mem_virtual = current_mem.vms / 1024. ** 2
Expand All @@ -175,7 +178,7 @@ def monitor(pid, logfile=None, plot=None, duration=None, interval=None,
try:
current_cpu += get_percent(child)
current_mem = get_memory(child)
except:
except Exception:
continue
current_mem_real += current_mem.rss / 1024. ** 2
current_mem_virtual += current_mem.vms / 1024. ** 2
Expand Down

0 comments on commit 8bea13b

Please sign in to comment.