Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmmacleod committed Feb 28, 2019
2 parents 1818853 + 876d03e commit ab45cad
Show file tree
Hide file tree
Showing 21 changed files with 800 additions and 242 deletions.
95 changes: 51 additions & 44 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
test: &test
name: Test
command: |
set -x;
python${PYTHON_VERSION} -m pip install pytest pytest-cov;
python${PYTHON_VERSION} -m pytest --pyargs gwosc --cov=gwosc;
build:debian: &build-debian
name: Build
command: |
set -x;
apt-get -yqq update;
apt-get -yqq install \
dpkg-dev \
debhelper \
dh-python \
python-all \
python3-all \
python-setuptools \
python3-setuptools \
python-six \
python3-six \
python-pytest \
python3-pytest \
python-mock \
python-pip \
python3-pip \
python-pytest-cov \
python3-pytest-cov;
pushd $(mktemp -d -p .)
devscripts;
pushd $(mktemp -d -p .);
tar -xf ../gwosc-*.tar.gz --strip-components=1;
# install build dependencies
mk-build-deps --tool "apt-get -y" --install --remove;
# build binary package
dpkg-buildpackage -us -uc -b;
# mv and install
popd;
rm -rf tmp*;
dpkg --install python*-gwosc*.deb;
Expand All @@ -40,37 +23,60 @@ build:centos: &build-centos
set -x;
yum -y -q update;
yum -y -q install \
yum-utils \
rpm-build \
python-rpm-macros \
python2-rpm-macros \
python3-rpm-macros \
python2-setuptools \
python34-setuptools \
python2-six \
python34-six \
python2-pytest \
python34-pytest \
python2-mock \
python2-pip \
python34-pip \
python2-pytest-cov \
python34-pytest-cov;
tar -xf gwosc-*.tar.gz
rm -rf gwosc-*.tar.gz
_version=$(grep "define version" gwosc-*/gwosc.spec | awk '{print $3}')
mv gwosc-* gwosc-${_version}
tar -zcf gwosc-${_version}.tar.gz gwosc-${_version}
rm -rf gwosc-${_version}/
rpmbuild --quiet --define "_rpmdir $(pwd)" -tb gwosc-*.tar.gz;
python34 \
python3-rpm-macros;
# hack version number
tar -xf gwosc-*.tar.gz;
rm -rf gwosc-*.tar.gz;
_version=$(grep "define version" gwosc-*/gwosc.spec | awk '{print $3}');
mv gwosc-* gwosc-${_version};
tar -zcf gwosc-${_version}.tar.gz gwosc-${_version};
rm -rf gwosc-${_version}/;
# build src rpm
SRC_RPM=$(rpmbuild -ts gwosc*.tar.gz | cut -d\ -f2);
# install build dependencies
yum-builddep -y -q ${SRC_RPM};
# build binary rpm(s)
rpmbuild --quiet --define "_rpmdir $(pwd)" --rebuild ${SRC_RPM};
# mv and install
mv noarch/*.rpm .;
rm -rf noarch;
yum -y -q --nogpgcheck localinstall *.rpm;
prepare-test:debian: &prep-test-debian
name: Prepare tests
command: |
set -x;
apt-get -yqq install \
python-pip python3-pip \
python-pytest python3-pytest \
python-pytest-cov python3-pytest-cov;
prepare-test:centos: &prep-test-centos
name: Prepare tests
command: |
set -x;
yum -y -q install \
python2-pip python34-pip \
pytest python34-pytest \
python2-pytest-cov python34-pytest-cov;
test: &test
name: Test
command: |
set -x;
python${PYTHON_VERSION} -m pip install --upgrade pytest pytest-cov;
python${PYTHON_VERSION} -m pytest --pyargs gwosc --cov=gwosc;
debian: &debian
steps:
- attach_workspace:
at: .
- run: *build-debian
- run: *prep-test-debian
- run: *test
- store_artifacts:
path: "*.deb"
Expand All @@ -80,6 +86,7 @@ centos: &centos
- attach_workspace:
at: .
- run: *build-centos
- run: *prep-test-centos
- run: *test
- store_artifacts:
path: "*.rpm"
Expand Down
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "2"
checks:
argument-count:
config:
threshold: 8
threshold: 10
file-lines:
config:
threshold: 500
Expand Down
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist: xenial
language: python

env:
Expand All @@ -9,6 +10,7 @@ python:
- '3.4'
- '3.5'
- '3.6'
- '3.7'
- 'nightly'

before_install:
Expand All @@ -18,12 +20,15 @@ install:
- python -m pip install .

before_script:
- python -m pip install coveralls "pytest>=2.8" pytest-runner sphinx_rtd_theme numpydoc
- python -m pip install coveralls "pytest>=2.8" pytest-runner sphinx_rtd_theme numpydoc pytest-socket

script:
# run unit tests
- coverage run ./setup.py test

# run unit tests again with --disable-socket to ensure that tests are marked properly
- python -m pytest --disable-socket -m "not remote"

# build documentation
- cd docs && make html; cd ../

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
environment:
matrix:
- PYTHON: "C:\\Python27-x64"
- PYTHON: "C:\\Python35-x64"
- PYTHON: "C:\\Python36-x64"
- PYTHON: "C:\\Python37-x64"
install:
- "%PYTHON%\\python.exe -m pip install --upgrade pip"
build_script:
Expand Down
25 changes: 17 additions & 8 deletions gwosc.spec
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@ Source0: https://pypi.io/packages/source/g/%{name}/%{name}-%{version}.tar.gz
Vendor: Duncan Macleod <duncan.macleod@ligo.org>

BuildArch: noarch

# rpmbuild dependencies
BuildRequires: rpm-build
BuildRequires: python-rpm-macros
BuildRequires: python2-rpm-macros
BuildRequires: python3-rpm-macros

# build dependencies
BuildRequires: python-setuptools
BuildRequires: python%{python3_pkgversion}-setuptools
BuildRequires: python%{python3_version_nodots}-setuptools

# runtime dependencies (required for %check)
BuildRequires: python2-six
BuildRequires: python%{python3_pkgversion}-six
BuildRequires: python%{python3_version_nodots}-six

# testing dependencies (required for %check)
BuildRequires: python2-pytest
BuildRequires: python%{python3_pkgversion}-pytest
BuildRequires: python%{python3_version_nodots}-pytest
BuildRequires: python2-mock

%description
Expand All @@ -43,11 +52,11 @@ gravitational-wave observatories.

# -- python-3X-ligotimegps

%package -n python%{python3_pkgversion}-%{name}
%package -n python%{python3_version_nodots}-%{name}
Summary: %{summary}
Requires: python%{python3_pkgversion}-six
%{?python_provide:%python_provide python%{python3_pkgversion}-%{name}}
%description -n python%{python3_pkgversion}-%{name}
Requires: python%{python3_version_nodots}-six
%{?python_provide:%python_provide python%{python3_version_nodots}-%{name}}
%description -n python%{python3_version_nodots}-%{name}
The `gwosc` package provides an interface to querying the open data
releases hosted on <https://losc.ligo.org> from the LIGO and Virgo
gravitational-wave observatories.
Expand Down Expand Up @@ -77,7 +86,7 @@ rm -rf $RPM_BUILD_ROOT
%doc README.md
%{python2_sitelib}/*

%files -n python%{python3_pkgversion}-%{name}
%files -n python%{python3_version_nodots}-%{name}
%license LICENSE
%doc README.md
%{python3_sitelib}/*
Expand Down
112 changes: 104 additions & 8 deletions gwosc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@

import contextlib
import json
import re

from six.moves.urllib.request import urlopen
from six.moves.urllib.error import URLError

DEFAULT_URL = 'https://losc.ligo.org'
DEFAULT_URL = "https://www.gw-openscience.org"
MAX_GPS = 99999999999

VERSIONED_EVENT_REGEX = re.compile(r"_[RV]\d+\Z")


# -- JSON handling ------------------------------------------------------------

Expand Down Expand Up @@ -64,6 +68,10 @@ def fetch_json(url):

# -- API calls ----------------------------------------------------------------

def _dataset_url(start, end, host=DEFAULT_URL):
return "{}/archive/{:d}/{:d}/json/".format(host, start, end)


def fetch_dataset_json(gpsstart, gpsend, host=DEFAULT_URL):
"""Returns the JSON metadata for all datasets matching the GPS interval
Expand All @@ -83,8 +91,11 @@ def fetch_dataset_json(gpsstart, gpsend, host=DEFAULT_URL):
json
the JSON data retrieved from LOSC and returned by `json.loads`
"""
url = '{}/archive/{:d}/{:d}/json/'.format(host, gpsstart, gpsend)
return fetch_json(url)
return fetch_json(_dataset_url(gpsstart, gpsend, host=host))


def _event_url(event, host=DEFAULT_URL):
return "{}/archive/{}/json/".format(host, event)


def fetch_event_json(event, host=DEFAULT_URL):
Expand All @@ -103,8 +114,13 @@ def fetch_event_json(event, host=DEFAULT_URL):
json
the JSON data retrieved from LOSC and returned by `json.loads`
"""
url = '{}/archive/{}/json/'.format(host, event)
return fetch_json(url)
return fetch_json(_event_url(event, host=host))


def _run_url(run, detector, start, end, host=DEFAULT_URL):
return "{}/archive/links/{}/{}/{:d}/{:d}/json/".format(
host, run, detector, start, end,
)


def fetch_run_json(run, detector, gpsstart=0, gpsend=MAX_GPS,
Expand Down Expand Up @@ -133,6 +149,86 @@ def fetch_run_json(run, detector, gpsstart=0, gpsend=MAX_GPS,
json
the JSON data retrieved from LOSC and returned by `json.loads`
"""
url = '{}/archive/links/{}/{}/{:d}/{:d}/json/'.format(
host, run, detector, gpsstart, gpsend)
return fetch_json(url)
return fetch_json(_run_url(run, detector, gpsstart, gpsend, host=host))


def _catalog_url(catalog, host=DEFAULT_URL):
return "{}/catalog/{}/filelist/".format(
host, catalog,
)


def fetch_catalog_json(catalog, host=DEFAULT_URL):
""""Returns the JSON metadata for the given catalogue
Parameters
----------
catalog : `str`
the name of the event catalog, e.g. `GWTC-1-confident`
host : `str`, optional
the URL of the LOSC host to query, defaults to losc.ligo.org
Returns
-------
json
the JSON data retrieved from GWOSC and returnend by
:func:`json.loads`
"""
return fetch_json(_catalog_url(catalog, host=host))


def fetch_catalog_event_json(event, version=None, host=DEFAULT_URL):
"""Returns the JSON metadata for the given event in a catalog
This method queries for all available data-release versions, returning
the highest available version, unless ``version=<X>`` is specified.
Parameters
----------
event : `str`
the name of the event to query
host : `str`, optional
the URL of the LOSC host to query, defaults to losc.ligo.org
version : `int`, `None`, optional
restrict query to a given data-release version
Returns
-------
json
the JSON data retrieved from LOSC and returned by `json.loads`
"""
# if user gave a versioned event (e.g. GW150914_R1), use it directly
if VERSIONED_EVENT_REGEX.search(event):
return fetch_event_json(event, host=host)

# if user specified a version separately, use it
if version is not None:
return fetch_event_json("{0}_R{1}".format(event, version), host=host)

# otherwise find all available versions and return highest
# its inefficient, but it works..
versions = _find_catalog_event_versions(event, host=host)
return fetch_catalog_event_json(event, version=versions[-1], host=host)


def _find_catalog_event_versions(event, host=DEFAULT_URL):
"""List all available versions of a catalogue event
"""
vers = 1
found = []
while True:
try:
resp = urlopen(_event_url("{0}_R{1}".format(event, vers),
host=host))
except URLError:
break
else:
resp.close()
found.append(vers)
vers += 1
if not found:
raise ValueError("no event datasets found for {!r}".format(event))
return found
Loading

0 comments on commit ab45cad

Please sign in to comment.