Skip to content

Commit 018396c

Browse files
authored
Merge pull request #4030 from arogl/pyupgrade
pyupgrade of beets to Python 3.6
2 parents 7ae8b9c + 237bd07 commit 018396c

File tree

182 files changed

+4880
-5395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+4880
-5395
lines changed

beet

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32

43
# This file is part of beets.
54
# Copyright 2016, Adrian Sampson.
@@ -15,7 +14,6 @@
1514
# The above copyright notice and this permission notice shall be
1615
# included in all copies or substantial portions of the Software.
1716

18-
from __future__ import division, absolute_import, print_function
1917

2018
import beets.ui
2119

beets/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# This file is part of beets.
32
# Copyright 2016, Adrian Sampson.
43
#
@@ -13,21 +12,20 @@
1312
# The above copyright notice and this permission notice shall be
1413
# included in all copies or substantial portions of the Software.
1514

16-
from __future__ import division, absolute_import, print_function
1715

1816
import confuse
1917
from sys import stderr
2018

21-
__version__ = u'1.5.1'
22-
__author__ = u'Adrian Sampson <[email protected]>'
19+
__version__ = '1.5.1'
20+
__author__ = 'Adrian Sampson <[email protected]>'
2321

2422

2523
class IncludeLazyConfig(confuse.LazyConfig):
2624
"""A version of Confuse's LazyConfig that also merges in data from
2725
YAML files specified in an `include` setting.
2826
"""
2927
def read(self, user=True, defaults=True):
30-
super(IncludeLazyConfig, self).read(user, defaults)
28+
super().read(user, defaults)
3129

3230
try:
3331
for view in self['include']:

beets/__main__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# This file is part of beets.
32
# Copyright 2017, Adrian Sampson.
43
#
@@ -17,7 +16,6 @@
1716
`python -m beets`.
1817
"""
1918

20-
from __future__ import division, absolute_import, print_function
2119

2220
import sys
2321
from .ui import main

beets/art.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# This file is part of beets.
32
# Copyright 2016, Adrian Sampson.
43
#
@@ -17,7 +16,6 @@
1716
music and items' embedded album art.
1817
"""
1918

20-
from __future__ import division, absolute_import, print_function
2119

2220
import subprocess
2321
import platform
@@ -43,7 +41,7 @@ def get_art(log, item):
4341
try:
4442
mf = mediafile.MediaFile(syspath(item.path))
4543
except mediafile.UnreadableFileError as exc:
46-
log.warning(u'Could not extract art from {0}: {1}',
44+
log.warning('Could not extract art from {0}: {1}',
4745
displayable_path(item.path), exc)
4846
return
4947

@@ -58,20 +56,20 @@ def embed_item(log, item, imagepath, maxwidth=None, itempath=None,
5856
# Conditions and filters.
5957
if compare_threshold:
6058
if not check_art_similarity(log, item, imagepath, compare_threshold):
61-
log.info(u'Image not similar; skipping.')
59+
log.info('Image not similar; skipping.')
6260
return
6361
if ifempty and get_art(log, item):
64-
log.info(u'media file already contained art')
62+
log.info('media file already contained art')
6563
return
6664
if maxwidth and not as_album:
6765
imagepath = resize_image(log, imagepath, maxwidth, quality)
6866

6967
# Get the `Image` object from the file.
7068
try:
71-
log.debug(u'embedding {0}', displayable_path(imagepath))
69+
log.debug('embedding {0}', displayable_path(imagepath))
7270
image = mediafile_image(imagepath, maxwidth)
73-
except IOError as exc:
74-
log.warning(u'could not read image file: {0}', exc)
71+
except OSError as exc:
72+
log.warning('could not read image file: {0}', exc)
7573
return
7674

7775
# Make sure the image kind is safe (some formats only support PNG
@@ -90,16 +88,16 @@ def embed_album(log, album, maxwidth=None, quiet=False, compare_threshold=0,
9088
"""
9189
imagepath = album.artpath
9290
if not imagepath:
93-
log.info(u'No album art present for {0}', album)
91+
log.info('No album art present for {0}', album)
9492
return
9593
if not os.path.isfile(syspath(imagepath)):
96-
log.info(u'Album art not found at {0} for {1}',
94+
log.info('Album art not found at {0} for {1}',
9795
displayable_path(imagepath), album)
9896
return
9997
if maxwidth:
10098
imagepath = resize_image(log, imagepath, maxwidth, quality)
10199

102-
log.info(u'Embedding album art into {0}', album)
100+
log.info('Embedding album art into {0}', album)
103101

104102
for item in album.items():
105103
embed_item(log, item, imagepath, maxwidth, None, compare_threshold,
@@ -110,7 +108,7 @@ def resize_image(log, imagepath, maxwidth, quality):
110108
"""Returns path to an image resized to maxwidth and encoded with the
111109
specified quality level.
112110
"""
113-
log.debug(u'Resizing album art to {0} pixels wide and encoding at quality \
111+
log.debug('Resizing album art to {0} pixels wide and encoding at quality \
114112
level {1}', maxwidth, quality)
115113
imagepath = ArtResizer.shared.resize(maxwidth, syspath(imagepath),
116114
quality=quality)
@@ -135,7 +133,7 @@ def check_art_similarity(log, item, imagepath, compare_threshold):
135133
syspath(art, prefix=False),
136134
'-colorspace', 'gray', 'MIFF:-']
137135
compare_cmd = ['compare', '-metric', 'PHASH', '-', 'null:']
138-
log.debug(u'comparing images with pipeline {} | {}',
136+
log.debug('comparing images with pipeline {} | {}',
139137
convert_cmd, compare_cmd)
140138
convert_proc = subprocess.Popen(
141139
convert_cmd,
@@ -159,7 +157,7 @@ def check_art_similarity(log, item, imagepath, compare_threshold):
159157
convert_proc.wait()
160158
if convert_proc.returncode:
161159
log.debug(
162-
u'ImageMagick convert failed with status {}: {!r}',
160+
'ImageMagick convert failed with status {}: {!r}',
163161
convert_proc.returncode,
164162
convert_stderr,
165163
)
@@ -169,7 +167,7 @@ def check_art_similarity(log, item, imagepath, compare_threshold):
169167
stdout, stderr = compare_proc.communicate()
170168
if compare_proc.returncode:
171169
if compare_proc.returncode != 1:
172-
log.debug(u'ImageMagick compare failed: {0}, {1}',
170+
log.debug('ImageMagick compare failed: {0}, {1}',
173171
displayable_path(imagepath),
174172
displayable_path(art))
175173
return
@@ -180,10 +178,10 @@ def check_art_similarity(log, item, imagepath, compare_threshold):
180178
try:
181179
phash_diff = float(out_str)
182180
except ValueError:
183-
log.debug(u'IM output is not a number: {0!r}', out_str)
181+
log.debug('IM output is not a number: {0!r}', out_str)
184182
return
185183

186-
log.debug(u'ImageMagick compare score: {0}', phash_diff)
184+
log.debug('ImageMagick compare score: {0}', phash_diff)
187185
return phash_diff <= compare_threshold
188186

189187
return True
@@ -193,18 +191,18 @@ def extract(log, outpath, item):
193191
art = get_art(log, item)
194192
outpath = bytestring_path(outpath)
195193
if not art:
196-
log.info(u'No album art present in {0}, skipping.', item)
194+
log.info('No album art present in {0}, skipping.', item)
197195
return
198196

199197
# Add an extension to the filename.
200198
ext = mediafile.image_extension(art)
201199
if not ext:
202-
log.warning(u'Unknown image type in {0}.',
200+
log.warning('Unknown image type in {0}.',
203201
displayable_path(item.path))
204202
return
205203
outpath += bytestring_path('.' + ext)
206204

207-
log.info(u'Extracting album art from: {0} to: {1}',
205+
log.info('Extracting album art from: {0} to: {1}',
208206
item, displayable_path(outpath))
209207
with open(syspath(outpath), 'wb') as f:
210208
f.write(art)
@@ -220,7 +218,7 @@ def extract_first(log, outpath, items):
220218

221219
def clear(log, lib, query):
222220
items = lib.items(query)
223-
log.info(u'Clearing album art from {0} items', len(items))
221+
log.info('Clearing album art from {0} items', len(items))
224222
for item in items:
225-
log.debug(u'Clearing art for {0}', item)
223+
log.debug('Clearing art for {0}', item)
226224
item.try_write(tags={'images': None})

beets/autotag/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# This file is part of beets.
32
# Copyright 2016, Adrian Sampson.
43
#
@@ -16,7 +15,6 @@
1615
"""Facilities for automatically determining files' correct metadata.
1716
"""
1817

19-
from __future__ import division, absolute_import, print_function
2018

2119
from beets import logging
2220
from beets import config

0 commit comments

Comments
 (0)