From 2b7cdabd802153267bbe4dcd47afbc0012e22c65 Mon Sep 17 00:00:00 2001 From: theychx Date: Mon, 19 Mar 2018 15:03:45 +0100 Subject: [PATCH] fix: Remove py2 compat code (#75) * Remove py2-specific imports * Remove subclassing of "object" * Fix bare except statements * Update setup.py * Fix CI and tox * Junk commit to retrigger CI * Junk commit to retrigger CI (again) * Fix tests --- .travis.yml | 3 +-- catt/cli.py | 8 ++------ catt/controllers.py | 6 +++--- catt/http_server.py | 12 +++--------- setup.py | 9 +++------ tests/test_catt.py | 6 +++--- tox.ini | 11 ++++------- 7 files changed, 19 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1797450..944ceb3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,8 @@ language: python python: - - "2.7" - - "3.3" - "3.4" - "3.5" + - "3.6" install: "pip install -r requirements_dev.txt" diff --git a/catt/cli.py b/catt/cli.py index 143d2a8..ee3040b 100644 --- a/catt/cli.py +++ b/catt/cli.py @@ -1,13 +1,9 @@ # -*- coding: utf-8 -*- +import configparser import os import time from threading import Thread -try: - import ConfigParser as configparser -except ImportError: - import configparser - import click from .controllers import ( @@ -248,7 +244,7 @@ def scan(): def writeconfig(settings): try: os.mkdir(CONFIG_DIR) - except: # noqa + except FileExistsError: pass # Put all the standalone options from the settings into an "options" key. diff --git a/catt/controllers.py b/catt/controllers.py index 6573aeb..90ec8ad 100644 --- a/catt/controllers.py +++ b/catt/controllers.py @@ -136,7 +136,7 @@ def __init__(self, duration=3 * 24 * 3600, self.cache_dir = cache_dir try: os.mkdir(cache_dir) - except: # noqa + except FileExistsError: pass self.cache_filename = os.path.join(cache_dir, "chromecast_hosts") @@ -186,7 +186,7 @@ def set(self, name, value): def clear(self): try: shutil.rmtree(self.cache_dir) - except: # noqa + except FileNotFoundError: pass @@ -217,7 +217,7 @@ def new_media_status(self, status): self.not_buffering.clear() -class CastController(object): +class CastController: def __init__(self, cast, name, app_id, prep=None): self._cast = cast self.name = name diff --git a/catt/http_server.py b/catt/http_server.py index f926293..5f98c1e 100644 --- a/catt/http_server.py +++ b/catt/http_server.py @@ -1,14 +1,8 @@ import os +import socketserver import time import traceback -try: - import SocketServer -except ImportError: - import socketserver as SocketServer -try: - from BaseHTTPServer import BaseHTTPRequestHandler -except ImportError: - from http.server import BaseHTTPRequestHandler +from http.server import BaseHTTPRequestHandler def serve_file(filename, address="", port=45114): @@ -43,6 +37,6 @@ def do_GET(self): # noqa file.close() - httpd = SocketServer.TCPServer((address, port), FileHandler) + httpd = socketserver.TCPServer((address, port), FileHandler) httpd.serve_forever() httpd.server_close() diff --git a/setup.py b/setup.py index e002bf1..a233f58 100644 --- a/setup.py +++ b/setup.py @@ -14,8 +14,7 @@ requirements = [ "youtube-dl>=2017.3.15", - "PyChromecast==1.0.3", - "zeroconf==0.19.1", + "PyChromecast>=2.0.0", "Click>=5.0", ] @@ -41,16 +40,14 @@ zip_safe=False, keywords="chromecast cast catt cast_all_the_things", classifiers=[ - 'Development Status :: 2 - Pre-Alpha', + 'Development Status :: 3 - Alpha', 'Intended Audience :: End Users/Desktop', 'License :: OSI Approved :: BSD License', 'Natural Language :: English', - "Programming Language :: Python :: 2", - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', ], test_suite='tests', tests_require=test_requirements, diff --git a/tests/test_catt.py b/tests/test_catt.py index d0b65a2..ea54058 100644 --- a/tests/test_catt.py +++ b/tests/test_catt.py @@ -24,11 +24,11 @@ def test_stream_info_youtube_playlist(self): self.assertEqual(stream.extractor, "youtube") def test_stream_info_other_video(self): - stream = StreamInfo("https://vimeo.com/225888984") + stream = StreamInfo("http://www.dailymotion.com/video/x6fotne") self.assertIn("https://", stream.video_url) - self.assertEqual(stream.video_id, "225888984") + self.assertEqual(stream.video_id, "x6fotne") self.assertTrue(stream.is_video) - self.assertEqual(stream.extractor, "vimeo") + self.assertEqual(stream.extractor, "dailymotion") def test_cache(self): cache = Cache() diff --git a/tox.ini b/tox.ini index c3fff11..523847e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,19 +1,16 @@ [tox] -envlist = py27, py33, py34, py35 +envlist = py34, py35, py36 [testenv] setenv = PYTHONPATH = {toxinidir}:{toxinidir}/catt commands = python setup.py test -[testenv:py27] -basepython = python2.7 - -[testenv:py33] -basepython = python3.3 - [testenv:py34] basepython = python3.4 [testenv:py35] basepython = python3.5 + +[testenv:py36] +basepython = python3.6