Skip to content

Commit 7905ff0

Browse files
authored
Merge pull request #468 from pkkid/less_deps
reduce deps
2 parents 337cb29 + 5911597 commit 7905ff0

File tree

7 files changed

+18
-17
lines changed

7 files changed

+18
-17
lines changed

plexapi/alert.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import json
33
import threading
4-
import websocket
4+
55
from plexapi import log
66

77

@@ -40,6 +40,11 @@ def __init__(self, server, callback=None):
4040
self._ws = None
4141

4242
def run(self):
43+
try:
44+
import websocket
45+
except ImportError:
46+
log.warning("Can't use the AlertListener without websocket")
47+
return
4348
# create the websocket connection
4449
url = self._server.url(self.key, includeToken=True).replace('http', 'ws')
4550
log.info('Starting AlertListener: %s', url)

plexapi/compat.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@
4444
except ImportError:
4545
from xml.etree import ElementTree
4646

47-
try:
48-
from unittest.mock import patch, MagicMock
49-
except ImportError:
50-
from mock import patch, MagicMock
51-
5247

5348
def makedirs(name, mode=0o777, exist_ok=False):
5449
""" Mimicks os.makedirs() from Python 3. """

plexapi/utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
import requests
1212
from plexapi import compat
1313
from plexapi.exceptions import NotFound
14-
from tqdm import tqdm
14+
15+
try:
16+
from tqdm import tqdm
17+
except ImportError:
18+
tqdm = None
1519

1620
log = logging.getLogger('plexapi')
1721

@@ -294,17 +298,17 @@ def download(url, token, filename=None, savepath=None, session=None, chunksize=4
294298

295299
# save the file to disk
296300
log.info('Downloading: %s', fullpath)
297-
if showstatus: # pragma: no cover
301+
if showstatus and tqdm: # pragma: no cover
298302
total = int(response.headers.get('content-length', 0))
299303
bar = tqdm(unit='B', unit_scale=True, total=total, desc=filename)
300304

301305
with open(fullpath, 'wb') as handle:
302306
for chunk in response.iter_content(chunk_size=chunksize):
303307
handle.write(chunk)
304-
if showstatus:
308+
if showstatus and tqdm:
305309
bar.update(len(chunk))
306310

307-
if showstatus: # pragma: no cover
311+
if showstatus and tqdm: # pragma: no cover
308312
bar.close()
309313
# check we want to unzip the contents
310314
if fullpath.endswith('zip') and unpack:

requirements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@
33
# pip install -r requirements.txt
44
#---------------------------------------------------------
55
requests
6-
tqdm
7-
websocket-client
8-
mock; python_version < '3.3'

requirements_dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ sphinx
1515
sphinxcontrib-napoleon
1616
tqdm
1717
websocket-client
18+
mock; python_version < '3.3'
19+
1820

1921
# Installing sphinx-rtd-theme directly from github above is used until a point release
2022
# above 0.4.3 is released. https://github.com/readthedocs/sphinx_rtd_theme/issues/739

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import requests
1010
from plexapi import compat
1111
from plexapi.client import PlexClient
12-
from plexapi.compat import MagicMock, patch
1312
from plexapi.myplex import MyPlexAccount
1413
from plexapi.server import PlexServer
1514

tests/test_server.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import pytest
66
from PIL import Image, ImageStat
7-
from plexapi.compat import patch
87
from plexapi.exceptions import BadRequest, NotFound
98
from plexapi.server import PlexServer
109
from plexapi.utils import download
@@ -200,7 +199,7 @@ def test_server_isLatest(plex, mocker):
200199

201200
def test_server_installUpdate(plex, mocker):
202201
m = mocker.MagicMock(release="aa")
203-
with patch("plexapi.server.PlexServer.check_for_update", return_value=m):
202+
with utils.patch('plexapi.server.PlexServer.check_for_update', return_value=m):
204203
with utils.callable_http_patch():
205204
plex.installUpdate()
206205

@@ -215,7 +214,7 @@ def __init__(self, **kwargs):
215214
self.downloadURL = "http://path-to-update"
216215
self.state = "downloaded"
217216

218-
with patch("plexapi.server.PlexServer.check_for_update", return_value=R()):
217+
with utils.patch('plexapi.server.PlexServer.check_for_update', return_value=R()):
219218
rel = plex.check_for_update(force=False, download=True)
220219
assert rel.download_key == "plex.tv/release/1337"
221220
assert rel.version == "1337"

0 commit comments

Comments
 (0)