Skip to content
This repository has been archived by the owner on Nov 11, 2019. It is now read-only.

Commit

Permalink
Implement initial validator
Browse files Browse the repository at this point in the history
* creates a software thing called clive
* implements a rough validator in clive
* adds some minor tests--needs more tests
* adds infrastructure for travis to run clive tests and validate data

Fixes #2
  • Loading branch information
willkg committed Feb 9, 2016
1 parent 1df867c commit 7d6490a
Show file tree
Hide file tree
Showing 22 changed files with 735 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
sudo: false
language: python
python:
- "3.4"

env:
- TOXENV=py33 TEST_SUITE=clive
- TOXENV=py34 TEST_SUITE=clive
- TEST_SUITE=validate

install:
- bin/travis/setup.sh $TEST_SUITE

script:
- bin/travis/dispatch.sh $TEST_SUITE

notifications:
email: false
irc:
channels: "irc.freenode.net#pyvideo"
on_success: always
on_failure: always
33 changes: 33 additions & 0 deletions bin/travis/dispatch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Copyright (C) 2015, 2016 Sheila Miguez, Will Kahn-Greene
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

SUITE=${1:-all}

case $SUITE in
clive )
cd src/ && tox
;;

validate )
clive-cmd validate data/
;;

* )
echo "Unknown test suite '$SUITE'."
exit 1
;;
esac
27 changes: 27 additions & 0 deletions bin/travis/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Copyright (C) 2015, 2016 Sheila Miguez, Will Kahn-Greene
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

SUITE=${1:-all}

pip install -U tox

case $SUITE in
validate )
cd src && pip install .
;;

esac
21 changes: 21 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
end_of_line = lf

[*.bat]
indent_style = tab
end_of_line = crlf

[LICENSE]
insert_final_newline = false

[Makefile]
indent_style = tab
17 changes: 17 additions & 0 deletions src/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Config file for automatic testing at travis-ci.org
# This file will be regenerated if you run travis_pypi_setup.py

language: python

env:
- TOXENV=py35
- TOXENV=py34
- TOXENV=py33

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: pip install -U tox

# command to run tests, e.g. python setup.py test
script: tox


8 changes: 8 additions & 0 deletions src/AUTHORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=======
Credits
=======

Contributors
============

See ``git log --format="%an" | sort -u``
8 changes: 8 additions & 0 deletions src/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=======
History
=======

0.1.0 (in development)
======================

* FIXME
14 changes: 14 additions & 0 deletions src/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Copyright (C) 2015, 2016 Sheila Miguez, Will Kahn-Greene

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
11 changes: 11 additions & 0 deletions src/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include AUTHORS.rst
include CONTRIBUTING.rst
include HISTORY.rst
include LICENSE
include README.rst

recursive-include tests *
recursive-exclude * __pycache__
recursive-exclude * *.py[co]

recursive-include docs *.rst conf.py Makefile make.bat
70 changes: 70 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
.PHONY: clean-pyc clean-build docs clean
define BROWSER_PYSCRIPT
import os, webbrowser, sys
try:
from urllib import pathname2url
except:
from urllib.request import pathname2url

webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
endef
export BROWSER_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"

help:
@echo "clean - remove all build, test, coverage and Python artifacts"
@echo "clean-build - remove build artifacts"
@echo "clean-pyc - remove Python file artifacts"
@echo "clean-test - remove test and coverage artifacts"
@echo "lint - check style with flake8"
@echo "test - run tests quickly with the default Python"
@echo "test-all - run tests on every Python version with tox"
@echo "coverage - check code coverage quickly with the default Python"
@echo "docs - generate Sphinx HTML documentation, including API docs"
@echo "install - install the package to the active Python's site-packages"

clean: clean-build clean-pyc clean-test

clean-build:
rm -fr build/
rm -fr dist/
rm -fr .eggs/
find . -name '*.egg-info' -exec rm -fr {} +
find . -name '*.egg' -exec rm -f {} +

clean-pyc:
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +

clean-test:
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/

lint:
flake8 clive tests

test:
python setup.py test

test-all:
tox

coverage:
coverage run --source clive setup.py test
coverage report -m
coverage html
$(BROWSER) htmlcov/index.html

docs:
rm -f docs/clive.rst
rm -f docs/modules.rst
sphinx-apidoc -o docs/ clive
$(MAKE) -C docs clean
$(MAKE) -C docs html
$(BROWSER) docs/_build/html/index.html

install: clean
python setup.py install
8 changes: 8 additions & 0 deletions src/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
==================
pyvideo-data clive
==================

Data manipulation tools for pyvideo-data.

* Free software: AGPLv3
* Documentation: https://pyvideo-data.readthedocs.org/
18 changes: 18 additions & 0 deletions src/clive/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (C) 2015, 2016 Sheila Miguez, Will Kahn-Greene
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__author__ = ''
__email__ = ''
__version__ = '0.1.0'
87 changes: 87 additions & 0 deletions src/clive/cmdline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright (C) 2015, 2016 Sheila Miguez, Will Kahn-Greene
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import sys
import traceback
from textwrap import dedent

import click

from clive import __version__
from clive.lib import load_json_data
from clive.validate import validate_item


USAGE = '%prog [options] [command] [command-options]'
VERSION = 'clive ' + __version__


def click_run():
sys.excepthook = exception_handler
cli(obj={})


@click.group()
def cli():
pass


@cli.command()
@click.argument('paths', nargs=-1, type=click.Path(exists=True))
@click.pass_context
def validate(ctx, paths):
if not paths:
raise click.UsageError('No files or directories specified.')

error_count = 0

for path in paths:
data = load_json_data(path)
print('Looking at %d items...' % len(data))
for fn, item in data:
try:
validate_item(fn, item)
except ValueError as ve:
click.echo('Error: %s:' % fn, err=True)
click.echo(ve, err=True)
error_count += 1

# FIXME: Validate things that need to be unique across the
# dataset here.

# FIXME: Validate file format? i.e. 2-space indents? Sort order?

print('Done!')
ctx.exit(code=1 if error_count else 0)


def exception_handler(exc_type, exc_value, exc_tb):
click.echo(dedent("""\
Oh no! Clive has thrown an error while trying to do stuff. Please write
up a bug report with the specifics so that we can fix it.
https://github.com/pyvideo/pyvideo-data/issues
Here is some information you can copy and paste into the bug report:
"""))
click.echo('---')
click.echo('Clive: %s' % repr(__version__))
click.echo('Python: %s' % repr(sys.version))
click.echo('Command line: %s' % repr(sys.argv))
click.echo()
click.echo(
''.join(traceback.format_exception(exc_type, exc_value, exc_tb)))
click.echo('---')
Loading

0 comments on commit 7d6490a

Please sign in to comment.