From 79c5f06cf95c39f14b83631683a95c7792e02411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20M=C3=A5nsson?= Date: Fri, 6 Sep 2019 22:10:30 +0200 Subject: [PATCH 1/3] Moves files to a src-layout * Moves src/*.{c,h} to src/_cffi_src * Moves vi3o/*.py to src/vi3o * Moves build_* to src/_cffi_src * Moves test/ to tests/ * Moves misc to scripts/ * Updates build_*.py and setup.py for new layout * Updates manifest * Restructures setup.py --- MANIFEST.in | 12 ++- .../docker_unittests.py | 0 release.sh => scripts/release.sh | 0 setup.py | 96 ++++++++++++------ build_mjpg.py => src/_cffi_src/build_mjpg.py | 4 +- build_mkv.py => src/_cffi_src/build_mkv.py | 4 +- src/{ => _cffi_src}/decode.c | 0 src/{ => _cffi_src}/decode.h | 0 src/{ => _cffi_src}/mjpg.c | 0 src/{ => _cffi_src}/mjpg.h | 0 src/{ => _cffi_src}/mkv.c | 0 src/{ => _cffi_src}/mkv.h | 0 {vi3o => src/vi3o}/__init__.py | 0 {vi3o => src/vi3o}/cat.py | 0 {vi3o => src/vi3o}/compat.py | 0 {vi3o => src/vi3o}/cvview.py | 0 {vi3o => src/vi3o}/debugview.py | 0 {vi3o => src/vi3o}/image.py | 0 {vi3o => src/vi3o}/imageio.py | 0 {vi3o => src/vi3o}/mjpg.py | 0 {vi3o => src/vi3o}/mkv.py | 0 {vi3o => src/vi3o}/netcam.py | 0 {vi3o => src/vi3o}/opencv.py | 0 {vi3o => src/vi3o}/recording.py | 0 {vi3o => src/vi3o}/sync.py | 0 {vi3o => src/vi3o}/utils.py | 0 {vi3o => src/vi3o}/version.py | 0 {test => tests}/00000000.jpg | Bin {test => tests}/__init__.py | 0 {test => tests}/a.mkv | Bin {test => tests}/b.mkv | Bin {test => tests}/c.mkv | Bin {test => tests}/img00012680.jpg | Bin {test => tests}/systime.mkv | Bin {test => tests}/t.mjpg | Bin {test => tests}/t.mkv | Bin {test => tests}/test_api.py | 0 {test => tests}/test_cat.py | 2 +- {test => tests}/test_image.py | 2 +- {test => tests}/test_mjpg.py | 0 {test => tests}/test_mjpg_codec.mkv | Bin {test => tests}/test_mkv.py | 0 {test => tests}/test_recording.py | 2 +- {test => tests}/test_sync.py | 0 {test => tests}/tst.jpg | Bin {test => tests}/util.py | 0 46 files changed, 81 insertions(+), 41 deletions(-) rename docker_unittests.py => scripts/docker_unittests.py (100%) rename release.sh => scripts/release.sh (100%) rename build_mjpg.py => src/_cffi_src/build_mjpg.py (92%) rename build_mkv.py => src/_cffi_src/build_mkv.py (90%) rename src/{ => _cffi_src}/decode.c (100%) rename src/{ => _cffi_src}/decode.h (100%) rename src/{ => _cffi_src}/mjpg.c (100%) rename src/{ => _cffi_src}/mjpg.h (100%) rename src/{ => _cffi_src}/mkv.c (100%) rename src/{ => _cffi_src}/mkv.h (100%) rename {vi3o => src/vi3o}/__init__.py (100%) rename {vi3o => src/vi3o}/cat.py (100%) rename {vi3o => src/vi3o}/compat.py (100%) rename {vi3o => src/vi3o}/cvview.py (100%) rename {vi3o => src/vi3o}/debugview.py (100%) rename {vi3o => src/vi3o}/image.py (100%) rename {vi3o => src/vi3o}/imageio.py (100%) rename {vi3o => src/vi3o}/mjpg.py (100%) rename {vi3o => src/vi3o}/mkv.py (100%) rename {vi3o => src/vi3o}/netcam.py (100%) rename {vi3o => src/vi3o}/opencv.py (100%) rename {vi3o => src/vi3o}/recording.py (100%) rename {vi3o => src/vi3o}/sync.py (100%) rename {vi3o => src/vi3o}/utils.py (100%) rename {vi3o => src/vi3o}/version.py (100%) rename {test => tests}/00000000.jpg (100%) rename {test => tests}/__init__.py (100%) rename {test => tests}/a.mkv (100%) rename {test => tests}/b.mkv (100%) rename {test => tests}/c.mkv (100%) rename {test => tests}/img00012680.jpg (100%) rename {test => tests}/systime.mkv (100%) rename {test => tests}/t.mjpg (100%) rename {test => tests}/t.mkv (100%) rename {test => tests}/test_api.py (100%) rename {test => tests}/test_cat.py (99%) rename {test => tests}/test_image.py (99%) rename {test => tests}/test_mjpg.py (100%) rename {test => tests}/test_mjpg_codec.mkv (100%) rename {test => tests}/test_mkv.py (100%) rename {test => tests}/test_recording.py (99%) rename {test => tests}/test_sync.py (100%) rename {test => tests}/tst.jpg (100%) rename {test => tests}/util.py (100%) diff --git a/MANIFEST.in b/MANIFEST.in index a2e202b..24f0954 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,10 @@ -include build_*.py src/*.h -include LICENSE README.rst requirements.txt \ No newline at end of file +include LICENSE +include README.rst +include requirements.txt + +recursive-include src/_cffi_src *.py *.c *.h +recursive-include tests *.py + +prune docs/_build +recursive-exclude scripts * +exclude .coveragerc tox.ini requirements.txt diff --git a/docker_unittests.py b/scripts/docker_unittests.py similarity index 100% rename from docker_unittests.py rename to scripts/docker_unittests.py diff --git a/release.sh b/scripts/release.sh similarity index 100% rename from release.sh rename to scripts/release.sh diff --git a/setup.py b/setup.py index 03af7d8..bb61912 100644 --- a/setup.py +++ b/setup.py @@ -1,31 +1,71 @@ -from setuptools import setup +from setuptools import setup, find_packages from setuptools.command.test import test as TestCommand import sys import os -# Read the version but avoid importing the __init__.py since -# we might not have all dependencies installed -with open(os.path.join(os.path.dirname(__file__), "vi3o", "version.py")) as fp: - exec(fp.read()) +is_PY2 = sys.version_info <= (3, 0, 0) + +KEYWORDS = [ + "video", "mkv", "mjpg" +] + +CLASSIFIERS = [ + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT", + "Natural Language :: English", + "Operating System :: Linux", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python", + "Topic :: Software Development :: Libraries :: Python Modules" +] -requirements=["cffi>=1.0.0", "numpy>=1.7.1,<1.17"] -if sys.version_info <= (3, 3, 0): - requirements.append("pathlib2") +INSTALL_REQUIRES = ["cffi>=1.0.0", "numpy>=1.7.1,<1.17"] +if is_PY2: + INSTALL_REQUIRES.append("pathlib2") -class PyTestCommand(TestCommand): - user_options = [] +SETUP_REQUIRES = [ + 'cffi>=1.0.0' +] - def finalize_options(self): - pass +EXTRAS_REQUIRE = { + "dev": [ + "coverage", + "pytest <= 4.6, != 4.6.0", + "pillow < 7", + "sphinx < 1.8", + ], + "full": [ + "pillow < 7", + "pyglet < 1.5" + ] +} - def run_tests(self): - import pytest - errno = pytest.main() - sys.exit(errno) +if is_PY2: + EXTRAS_REQUIRE['dev'].append('mock') + + +PACKAGES = find_packages(where="src") + +CFFI_MODULES = [ + "src/_cffi_src/build_mjpg.py:ffi", + "src/_cffi_src/build_mkv.py:ffi" +] + +# Read the version but avoid importing the __init__.py since +# we might not have all dependencies installed +with open(os.path.join(os.path.dirname(__file__), "src", "vi3o", "version.py")) as fp: + exec(fp.read()) setup( name='vi3o', description='VIdeo and Image IO', + license='MIT', + url='http://vi3o.readthedocs.org', + author='Hakan Ardo', + author_email='hakan@debian.org', long_description=''' Utility for loading/saving/displaying video and images. It gives random access to mjpg (in http multipart format) and H264 (in .mkv format) video @@ -33,21 +73,13 @@ def run_tests(self): time at the time of capture is provided as timestamp for each frame. ''', version=__version__, - packages=['vi3o'], + keywords=KEYWORDS, + classifiers=CLASSIFIERS, + packages=PACKAGES, + package_dir={"": "src"}, + setup_requires=SETUP_REQUIRES, + cffi_modules=CFFI_MODULES, + install_requires=INSTALL_REQUIRES, + extras_require=EXTRAS_REQUIRE, zip_safe=False, - url='http://vi3o.readthedocs.org', - author='Hakan Ardo', - author_email='hakan@debian.org', - license='MIT', - setup_requires=["cffi>=1.0.0"], - cffi_modules=["build_mjpg.py:ffi", "build_mkv.py:ffi"], - install_requires=requirements, - extras_require={ - "full": [ - "pillow < 7", - "pyglet < 1.5" - ] - }, - cmdclass={'test': PyTestCommand}, - tests_require=['pytest <= 4.6, !=4.6.0', 'pillow < 7', "mock"], ) diff --git a/build_mjpg.py b/src/_cffi_src/build_mjpg.py similarity index 92% rename from build_mjpg.py rename to src/_cffi_src/build_mjpg.py index b7cf877..fd7815a 100644 --- a/build_mjpg.py +++ b/src/_cffi_src/build_mjpg.py @@ -30,9 +30,9 @@ int mjpg_seek (struct mjpg *m, long offset); """) -ffi.set_source("vi3o._mjpg", '#include "src/mjpg.h"', +ffi.set_source("vi3o._mjpg", '#include "mjpg.h"', include_dirs=[mydir], - sources=["src/mjpg.c"], + sources=[os.path.join(mydir, "mjpg.c")], libraries=["jpeg"], ) if __name__ == '__main__': diff --git a/build_mkv.py b/src/_cffi_src/build_mkv.py similarity index 90% rename from build_mkv.py rename to src/_cffi_src/build_mkv.py index ff78a4b..5c70157 100644 --- a/build_mkv.py +++ b/src/_cffi_src/build_mkv.py @@ -34,9 +34,9 @@ int64_t mkv_estimate_systime_offset(struct mkv *s); """) -ffi.set_source("vi3o._mkv", '#include "src/decode.h"', +ffi.set_source("vi3o._mkv", '#include "decode.h"', include_dirs=[mydir], - sources=["src/mkv.c", "src/decode.c"], + sources=[os.path.join(mydir, "mkv.c"), os.path.join(mydir,"decode.c")], # cflags=["-g"], libraries=["avcodec", "swscale"]) diff --git a/src/decode.c b/src/_cffi_src/decode.c similarity index 100% rename from src/decode.c rename to src/_cffi_src/decode.c diff --git a/src/decode.h b/src/_cffi_src/decode.h similarity index 100% rename from src/decode.h rename to src/_cffi_src/decode.h diff --git a/src/mjpg.c b/src/_cffi_src/mjpg.c similarity index 100% rename from src/mjpg.c rename to src/_cffi_src/mjpg.c diff --git a/src/mjpg.h b/src/_cffi_src/mjpg.h similarity index 100% rename from src/mjpg.h rename to src/_cffi_src/mjpg.h diff --git a/src/mkv.c b/src/_cffi_src/mkv.c similarity index 100% rename from src/mkv.c rename to src/_cffi_src/mkv.c diff --git a/src/mkv.h b/src/_cffi_src/mkv.h similarity index 100% rename from src/mkv.h rename to src/_cffi_src/mkv.h diff --git a/vi3o/__init__.py b/src/vi3o/__init__.py similarity index 100% rename from vi3o/__init__.py rename to src/vi3o/__init__.py diff --git a/vi3o/cat.py b/src/vi3o/cat.py similarity index 100% rename from vi3o/cat.py rename to src/vi3o/cat.py diff --git a/vi3o/compat.py b/src/vi3o/compat.py similarity index 100% rename from vi3o/compat.py rename to src/vi3o/compat.py diff --git a/vi3o/cvview.py b/src/vi3o/cvview.py similarity index 100% rename from vi3o/cvview.py rename to src/vi3o/cvview.py diff --git a/vi3o/debugview.py b/src/vi3o/debugview.py similarity index 100% rename from vi3o/debugview.py rename to src/vi3o/debugview.py diff --git a/vi3o/image.py b/src/vi3o/image.py similarity index 100% rename from vi3o/image.py rename to src/vi3o/image.py diff --git a/vi3o/imageio.py b/src/vi3o/imageio.py similarity index 100% rename from vi3o/imageio.py rename to src/vi3o/imageio.py diff --git a/vi3o/mjpg.py b/src/vi3o/mjpg.py similarity index 100% rename from vi3o/mjpg.py rename to src/vi3o/mjpg.py diff --git a/vi3o/mkv.py b/src/vi3o/mkv.py similarity index 100% rename from vi3o/mkv.py rename to src/vi3o/mkv.py diff --git a/vi3o/netcam.py b/src/vi3o/netcam.py similarity index 100% rename from vi3o/netcam.py rename to src/vi3o/netcam.py diff --git a/vi3o/opencv.py b/src/vi3o/opencv.py similarity index 100% rename from vi3o/opencv.py rename to src/vi3o/opencv.py diff --git a/vi3o/recording.py b/src/vi3o/recording.py similarity index 100% rename from vi3o/recording.py rename to src/vi3o/recording.py diff --git a/vi3o/sync.py b/src/vi3o/sync.py similarity index 100% rename from vi3o/sync.py rename to src/vi3o/sync.py diff --git a/vi3o/utils.py b/src/vi3o/utils.py similarity index 100% rename from vi3o/utils.py rename to src/vi3o/utils.py diff --git a/vi3o/version.py b/src/vi3o/version.py similarity index 100% rename from vi3o/version.py rename to src/vi3o/version.py diff --git a/test/00000000.jpg b/tests/00000000.jpg similarity index 100% rename from test/00000000.jpg rename to tests/00000000.jpg diff --git a/test/__init__.py b/tests/__init__.py similarity index 100% rename from test/__init__.py rename to tests/__init__.py diff --git a/test/a.mkv b/tests/a.mkv similarity index 100% rename from test/a.mkv rename to tests/a.mkv diff --git a/test/b.mkv b/tests/b.mkv similarity index 100% rename from test/b.mkv rename to tests/b.mkv diff --git a/test/c.mkv b/tests/c.mkv similarity index 100% rename from test/c.mkv rename to tests/c.mkv diff --git a/test/img00012680.jpg b/tests/img00012680.jpg similarity index 100% rename from test/img00012680.jpg rename to tests/img00012680.jpg diff --git a/test/systime.mkv b/tests/systime.mkv similarity index 100% rename from test/systime.mkv rename to tests/systime.mkv diff --git a/test/t.mjpg b/tests/t.mjpg similarity index 100% rename from test/t.mjpg rename to tests/t.mjpg diff --git a/test/t.mkv b/tests/t.mkv similarity index 100% rename from test/t.mkv rename to tests/t.mkv diff --git a/test/test_api.py b/tests/test_api.py similarity index 100% rename from test/test_api.py rename to tests/test_api.py diff --git a/test/test_cat.py b/tests/test_cat.py similarity index 99% rename from test/test_cat.py rename to tests/test_cat.py index f54f32c..6b38bbc 100644 --- a/test/test_cat.py +++ b/tests/test_cat.py @@ -7,7 +7,7 @@ import pytest import vi3o from vi3o import cat -from test.util import _FakeVideo, itertools, mock +from tests.util import _FakeVideo, itertools, mock diff --git a/test/test_image.py b/tests/test_image.py similarity index 99% rename from test/test_image.py rename to tests/test_image.py index ad8dd84..176c5a8 100644 --- a/test/test_image.py +++ b/tests/test_image.py @@ -1,5 +1,5 @@ from vi3o.image import * -from test.util import TempDir +from tests.util import TempDir import numpy as np from py.test import raises from vi3o.compat import pathlib diff --git a/test/test_mjpg.py b/tests/test_mjpg.py similarity index 100% rename from test/test_mjpg.py rename to tests/test_mjpg.py diff --git a/test/test_mjpg_codec.mkv b/tests/test_mjpg_codec.mkv similarity index 100% rename from test/test_mjpg_codec.mkv rename to tests/test_mjpg_codec.mkv diff --git a/test/test_mkv.py b/tests/test_mkv.py similarity index 100% rename from test/test_mkv.py rename to tests/test_mkv.py diff --git a/test/test_recording.py b/tests/test_recording.py similarity index 99% rename from test/test_recording.py rename to tests/test_recording.py index 9f51dd8..4083a3b 100644 --- a/test/test_recording.py +++ b/tests/test_recording.py @@ -8,7 +8,7 @@ import vi3o.compat as compat from vi3o import recording -from test.util import _FakeVideo, itertools, mock +from tests.util import _FakeVideo, itertools, mock # pylint: disable=missing-docstring # pylint: disable=redefined-outer-name diff --git a/test/test_sync.py b/tests/test_sync.py similarity index 100% rename from test/test_sync.py rename to tests/test_sync.py diff --git a/test/tst.jpg b/tests/tst.jpg similarity index 100% rename from test/tst.jpg rename to tests/tst.jpg diff --git a/test/util.py b/tests/util.py similarity index 100% rename from test/util.py rename to tests/util.py From 223958ce8323a465c4747630602ed957502d9197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20M=C3=A5nsson?= Date: Thu, 22 Aug 2019 23:17:26 +0200 Subject: [PATCH 2/3] Adds tox support .. to provide improved testing of different python versions, as well as tooling for running linting, formatting and coverage reports. --- .coveragerc | 11 +++++++++++ .python-version | 2 ++ docs/conf.py | 2 +- tox.ini | 42 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 .coveragerc create mode 100644 .python-version create mode 100644 tox.ini diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..5aaaead --- /dev/null +++ b/.coveragerc @@ -0,0 +1,11 @@ +[run] +branch = True +source = vi3o + +[paths] +source = + src/vi3o + .tox/*/lib/python*/site-packages/vi3o + +[report] +show_missing = True diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..c9a6a43 --- /dev/null +++ b/.python-version @@ -0,0 +1,2 @@ +system +3.7.3 diff --git a/docs/conf.py b/docs/conf.py index 08390de..40d713f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -33,7 +33,7 @@ extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.coverage', - 'sphinx.ext.pngmath', + 'sphinx.ext.imgmath', 'sphinx.ext.viewcode', ] diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..ec62f0d --- /dev/null +++ b/tox.ini @@ -0,0 +1,42 @@ +[tox] +envlist = py27, py34, py35, py36, py37, docs, format, lint, coverage-report +skip_missing_interpreters = true +minversion = 3.4.0 + +[testenv] +description = Run test and measure coverage +extras = dev +commands = + coverage run --parallel -m pytest {posargs} + +[testenv:lint] +description = Check linting +deps = pylint +# Do not fail builds due to linting yet, we need to fix the current +# issues first +commands = + pylint src/ {posargs} --exit-zero + +[testenv:format] +description = Check formatting +basepython = python3.6 +deps = black +commands = + black --check src/ tests/ {posargs} + +[testenv:docs] +description = Build docs +basepython = python3.6 +extras = dev +commands = + sphinx-build -b html -d docs/_build/doctrees docs/ docs/_build/html + + +[testenv:coverage-report] +depends = py{27,35,37} +deps = coverage +skip_install = true +parallel_show_output = true +commands = + coverage combine + coverage report From a25d6fde3340ab05dcbe3ed10eb0e69f62dc3629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20M=C3=A5nsson?= Date: Mon, 26 Aug 2019 21:51:04 +0200 Subject: [PATCH 3/3] Adds init_env.sh --- init_env.sh | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 init_env.sh diff --git a/init_env.sh b/init_env.sh new file mode 100644 index 0000000..98429a3 --- /dev/null +++ b/init_env.sh @@ -0,0 +1,3 @@ +python3 -m venv venv/ +venv/bin/pip install tox +source venv/bin/activate