From ec44afdf5fdf717183d31346af2cf3c003420b6e Mon Sep 17 00:00:00 2001 From: Alex Urban Date: Sun, 13 Dec 2020 10:29:11 -0600 Subject: [PATCH 1/8] Require gwdetchar-2.0.0 and enhance build tests slightly --- .travis.yml | 4 +--- requirements.txt | 4 ++-- setup.cfg | 6 +++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 487da5d..df79d51 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,14 +40,12 @@ install: - travis_retry conda install --quiet --yes --update-all --name hvetoci --file conda-reqs.txt # clean up - rm -f conda-reqs.txt parse-conda-requirements.py - # install this version - - python -m pip install . script: # run flake8 - python -m flake8 . # run test suite - - python -m coverage run -m pytest --pyargs hveto + - python -m coverage run -m pytest --verbose --pyargs hveto # test executables - python -m coverage run --append --source hveto -m hveto --help - python -m coverage run --append --source hveto -m hveto.cli.cache_events --help diff --git a/requirements.txt b/requirements.txt index 6072ef8..87e0ef6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # development -gwdetchar >= 1.1.0 +gwdetchar >= 2.0.0 gwpy >= 2.0.0 gwtrigfind lxml @@ -9,6 +9,6 @@ numpy >= 1.10 python-ligo-lw >= 1.5.0 scipy # testing +coverage flake8 pytest >= 3.1.0 -coverage diff --git a/setup.cfg b/setup.cfg index fd6c66e..b2d65fa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -48,7 +48,7 @@ python_requires = >=3.6 setup_requires = setuptools >=30.3.0 install_requires = - gwdetchar >= 1.1.0 + gwdetchar >= 2.0.0 gwpy >=2.0.0 gwtrigfind lxml @@ -58,9 +58,9 @@ install_requires = python-ligo-lw >= 1.5.0 scipy tests_require = + coverage flake8 pytest >=3.1.0 - coverage [options.entry_points] console_scripts = @@ -78,7 +78,7 @@ doc = [tool:pytest] ; print skip reasons -addopts = --verbose -r s +addopts = -r s ; -- tools ------------------ From 3c1c0769fa3748db5919ce10ab41b31768ff42a9 Mon Sep 17 00:00:00 2001 From: Alex Urban Date: Sun, 13 Dec 2020 10:49:39 -0600 Subject: [PATCH 2/8] Prefer pytest tmpdir fixture --- hveto/tests/test_plot.py | 22 +++++++++++++++------- hveto/tests/test_segments.py | 19 ++++++++++--------- hveto/triggers.py | 2 +- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/hveto/tests/test_plot.py b/hveto/tests/test_plot.py index 7ba471a..a5c9322 100644 --- a/hveto/tests/test_plot.py +++ b/hveto/tests/test_plot.py @@ -19,8 +19,9 @@ """Tests for `hveto.plot` """ +import os import pytest -import tempfile +import shutil from numpy import random @@ -31,14 +32,21 @@ @pytest.mark.parametrize('num', (10, 50, 200)) -def test_drop_plot(num): +def test_drop_plot(num, tmpdir): random.seed(0) + outdir = str(tmpdir) # this test just makes sure the drop plot code runs end-to-end channels = ['X1:TEST-%d' % i for i in range(num)] old = dict(zip(channels, random.normal(size=num))) new = dict(zip(channels, random.normal(size=num))) - with tempfile.NamedTemporaryFile(suffix='.png') as png: - plot.significance_drop(png.name, old, new) - - with tempfile.NamedTemporaryFile(suffix='.svg') as svg: - plot.significance_drop(svg.name, old, new) + # test PNG files + plot.significance_drop(os.path.join(outdir, 'test.png'), + old, new) + # test SVG files, which raise UserWarnings + with pytest.warns(UserWarning) as record: + plot.significance_drop(os.path.join(outdir, 'test.svg'), + old, new) + for rec in record: + assert rec.message.args[0].startswith("Failed to recover tooltip") + # clean up + shutil.rmtree(outdir, ignore_errors=True) diff --git a/hveto/tests/test_segments.py b/hveto/tests/test_segments.py index f479628..155ef88 100644 --- a/hveto/tests/test_segments.py +++ b/hveto/tests/test_segments.py @@ -20,11 +20,10 @@ """ import os +import pytest import shutil -from tempfile import NamedTemporaryFile -from unittest import mock -import pytest +from unittest import mock from gwpy.segments import (Segment, SegmentList, DataQualityFlag, DataQualityDict) @@ -57,12 +56,14 @@ def test_query(dqflag): @pytest.mark.parametrize('ncol', (2, 4)) -def test_write_segments_ascii(ncol): - with NamedTemporaryFile(suffix='.txt', delete=False) as tmp: - segments.write_ascii(tmp.name, TEST_SEGMENTS, ncol=ncol) - tmp.delete = True - a = SegmentList.read(tmp.name, gpstype=float, strict=False) - assert a == TEST_SEGMENTS_2 +def test_write_segments_ascii(ncol, tmpdir): + outdir = str(tmpdir) + out = os.path.join(outdir, 'test.txt') + segments.write_ascii(out, TEST_SEGMENTS, ncol=ncol) + a = SegmentList.read(out, gpstype=float, strict=False) + assert a == TEST_SEGMENTS_2 + # clean up + shutil.rmtree(outdir, ignore_errors=True) def test_write_segments_ascii_failure(): diff --git a/hveto/triggers.py b/hveto/triggers.py index 38b4d1e..c73c980 100644 --- a/hveto/triggers.py +++ b/hveto/triggers.py @@ -224,7 +224,7 @@ def find_auxiliary_channels(etg, gps='*', ifo='*', cache=None): def _sanitize_name(name): - return re.sub("[-_\.]", "_", name).lower() # noqa: W605 + return re.sub(r"[-_\.]", "_", name).lower() def _format_params(channel, etg, fmt, trigfind_kwargs, read_kwargs): From 5eb9936c20220840734b87fdf8b734479ab88ebc Mon Sep 17 00:00:00 2001 From: Alex Urban Date: Sun, 13 Dec 2020 10:56:19 -0600 Subject: [PATCH 3/8] Discover program name at runtime --- hveto/__main__.py | 7 ++++++- hveto/cli/cache_events.py | 6 +++++- hveto/cli/trace.py | 7 ++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/hveto/__main__.py b/hveto/__main__.py index 70bcefc..b6050c3 100644 --- a/hveto/__main__.py +++ b/hveto/__main__.py @@ -57,7 +57,11 @@ IFO = os.getenv('IFO') JOBSTART = time.time() -LOGGER = cli.logger(name='hveto') + +# set up logger +PROG = ('python -m hveto' if sys.argv[0].endswith('.py') + else os.path.basename(sys.argv[0])) +LOGGER = cli.logger(name=PROG.split('python -m ').pop()) __author__ = 'Duncan Macleod ' __credits__ = ('Joshua Smith , ' @@ -125,6 +129,7 @@ def create_parser(): """Create a command-line parser for this entry point """ parser = cli.create_parser( + prog=PROG, description=__doc__, version=__version__, ) diff --git a/hveto/cli/cache_events.py b/hveto/cli/cache_events.py index 3756d63..413b5f4 100644 --- a/hveto/cli/cache_events.py +++ b/hveto/cli/cache_events.py @@ -57,7 +57,10 @@ IFO = os.getenv('IFO') -LOGGER = cli.logger(name='hveto.cache_events') +# set up logger +PROG = ('python -m hveto.cache_events' if sys.argv[0].endswith('.py') + else os.path.basename(sys.argv[0])) +LOGGER = cli.logger(name=PROG.split('python -m ').pop()) # -- parse command line ------------------------------------------------------- @@ -70,6 +73,7 @@ def create_parser(): """Create a command-line parser for this entry point """ parser = cli.create_parser( + prog=PROG, description=__doc__, version=__version__, ) diff --git a/hveto/cli/trace.py b/hveto/cli/trace.py index eef11c4..f1aea7a 100644 --- a/hveto/cli/trace.py +++ b/hveto/cli/trace.py @@ -31,6 +31,9 @@ __author__ = 'Joshua Smith ' +PROG = ('python -m hveto.trace' if sys.argv[0].endswith('.py') + else os.path.basename(sys.argv[0])) + # -- parse command line ------------------------------------------------------- @@ -42,6 +45,7 @@ def create_parser(): """Create a command-line parser for this entry point """ parser = cli.create_parser( + prog=PROG, description=__doc__, version=__version__, ) @@ -80,7 +84,8 @@ def main(args=None): args = parser.parse_args(args=args) directory = args.directory - logger = cli.logger(name='hveto.trace', level=args.loglevel) + logger = cli.logger(name=PROG.split('python -m ').pop(), + level=args.loglevel) logger.debug('Running in verbose mode') logger.debug('Search directory: %s' % directory) From 7aab98e0e07b8a7c3ad99e9666585a0d4db0d9e7 Mon Sep 17 00:00:00 2001 From: Alex Urban Date: Sun, 13 Dec 2020 10:58:38 -0600 Subject: [PATCH 4/8] Resolve flake8 complaints --- hveto/cli/cache_events.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hveto/cli/cache_events.py b/hveto/cli/cache_events.py index 413b5f4..2edaf56 100644 --- a/hveto/cli/cache_events.py +++ b/hveto/cli/cache_events.py @@ -22,12 +22,13 @@ as given in the configuration files """ +import h4py import os -import warnings import multiprocessing -from pathlib import Path +import sys +import warnings -import h5py +from pathlib import Path from astropy.table import vstack From b84c5a9e3b4e2a5da2e4cec84805efd8ddd5cef4 Mon Sep 17 00:00:00 2001 From: Alex Urban Date: Sun, 13 Dec 2020 11:08:58 -0600 Subject: [PATCH 5/8] Propagate program name to the 'about' page --- hveto/__main__.py | 1 + hveto/html.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hveto/__main__.py b/hveto/__main__.py index b6050c3..e764f38 100644 --- a/hveto/__main__.py +++ b/hveto/__main__.py @@ -250,6 +250,7 @@ def main(args=None): htmlv = { 'title': '%s Hveto | %d-%d' % (ifo, start, end), 'config': None, + 'prog': PROG, 'context': ifo.lower(), } diff --git a/hveto/html.py b/hveto/html.py index 13c3f7b..740d43a 100644 --- a/hveto/html.py +++ b/hveto/html.py @@ -121,10 +121,11 @@ def decorated_func(ifo, start, end, *args, **kwargs): else: iargs = initargs.copy() aboutdir = os.path.join(outdir, 'about') + prog = kwargs.pop('prog', None) if iargs['base'] == os.path.curdir: iargs['base'] = os.path.pardir - about = write_about_page(ifo, start, end, config, outdir=aboutdir, - **iargs) + about = write_about_page( + ifo, start, end, config, prog=prog, outdir=aboutdir, **iargs) if os.path.basename(about) == 'index.html': about = about[:-10] # open page @@ -410,7 +411,7 @@ def write_null_page(reason, context='info'): @wrap_html -def write_about_page(configfile): +def write_about_page(configfile, prog=None): """Write a page explaining how an hveto analysis was completed Parameters @@ -423,6 +424,9 @@ def write_about_page(configfile): the GPS end time of the analysis configfile : `str` the path of the configuration file to embed + prog : `str`, optional + name of the program which produced this page, defaults to + the script run on the command-line outdir : `str`, optional the output directory for the HTML @@ -431,4 +435,4 @@ def write_about_page(configfile): index : `str` the path of the HTML written for this analysis """ - return gwhtml.about_this_page(configfile) + return gwhtml.about_this_page(configfile, prog=pro, prog=prog) From ac0b11ca80e733e9f31375e2afcdf42e5afeded7 Mon Sep 17 00:00:00 2001 From: Alex Urban Date: Sun, 13 Dec 2020 11:13:59 -0600 Subject: [PATCH 6/8] Fix a typo --- hveto/cli/cache_events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hveto/cli/cache_events.py b/hveto/cli/cache_events.py index 2edaf56..d2f0eb9 100644 --- a/hveto/cli/cache_events.py +++ b/hveto/cli/cache_events.py @@ -22,7 +22,7 @@ as given in the configuration files """ -import h4py +import h5py import os import multiprocessing import sys From d3e8ef4f1cf5c8e0f57382e858f19b20ac404c0e Mon Sep 17 00:00:00 2001 From: Alex Urban Date: Sun, 13 Dec 2020 12:09:02 -0600 Subject: [PATCH 7/8] Fix doublekwarg in hveto.html --- hveto/html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hveto/html.py b/hveto/html.py index 740d43a..f03b1de 100644 --- a/hveto/html.py +++ b/hveto/html.py @@ -435,4 +435,4 @@ def write_about_page(configfile, prog=None): index : `str` the path of the HTML written for this analysis """ - return gwhtml.about_this_page(configfile, prog=pro, prog=prog) + return gwhtml.about_this_page(configfile, prog=prog) From 8a042189df2c8a3e548ed75edb0b86176611656e Mon Sep 17 00:00:00 2001 From: Alex Urban Date: Sun, 13 Dec 2020 12:44:27 -0600 Subject: [PATCH 8/8] Use the correct module names --- hveto/cli/cache_events.py | 2 +- hveto/cli/trace.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hveto/cli/cache_events.py b/hveto/cli/cache_events.py index d2f0eb9..fd3fb13 100644 --- a/hveto/cli/cache_events.py +++ b/hveto/cli/cache_events.py @@ -59,7 +59,7 @@ IFO = os.getenv('IFO') # set up logger -PROG = ('python -m hveto.cache_events' if sys.argv[0].endswith('.py') +PROG = ('python -m hveto.cli.cache_events' if sys.argv[0].endswith('.py') else os.path.basename(sys.argv[0])) LOGGER = cli.logger(name=PROG.split('python -m ').pop()) diff --git a/hveto/cli/trace.py b/hveto/cli/trace.py index f1aea7a..7f283e7 100644 --- a/hveto/cli/trace.py +++ b/hveto/cli/trace.py @@ -31,7 +31,7 @@ __author__ = 'Joshua Smith ' -PROG = ('python -m hveto.trace' if sys.argv[0].endswith('.py') +PROG = ('python -m hveto.cli.trace' if sys.argv[0].endswith('.py') else os.path.basename(sys.argv[0]))