Skip to content

Commit 291ed72

Browse files
committed
Merge branch 'release/18.0.0'
2 parents 9d6a66c + df53b40 commit 291ed72

File tree

7 files changed

+57
-28
lines changed

7 files changed

+57
-28
lines changed

CHANGELOG

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
ChangeLog
33
*********
44

5+
18.0.0 (2018-10-11)
6+
===================
7+
- UPDATE: MFR is now following the CalVer (https://calver.org/) versioning scheme to match the
8+
OSF. All new versions will use the `YY.MINOR.MICRO` format.
9+
- Fix: Move Hypothes.is toolbar toggle button down, so that it doesn't block the pdf.js controls on
10+
tiny mobile screens.
11+
- Fix: Don't crash when the image exporter receives a misformatted dimensions argument.
12+
- Fix: Show informative errors to users when a tabular file rendering action fails.
13+
514
0.27.1 (2018-07-25)
615
===================
716
- Feature: Tell Keen analytics to strip ip on upload.

mfr/extensions/image/export.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ def __init__(self, *args, **kwargs):
1818

1919
def export(self):
2020
parts = self.format.split('.')
21-
type = parts[-1].lower()
22-
max_size = [int(x) for x in parts[0].split('x')] if len(parts) == 2 else None
21+
image_type = parts[-1].lower()
22+
max_size = {'w': None, 'h': None}
23+
if len(parts) == 2:
24+
max_size['w'], max_size['h'] = [int(size) for size in parts[0].split('x')]
2325
self.metrics.merge({
24-
'type': type,
25-
'max_size_w': max_size[0],
26-
'max_size_h': max_size[1],
26+
'type': image_type,
27+
'max_size_w': max_size['w'],
28+
'max_size_h': max_size['h'],
2729
})
2830
try:
2931
if self.ext in ['.psd']:
@@ -36,13 +38,14 @@ def export(self):
3638
else:
3739
image = Image.open(self.source_file_path)
3840

39-
if max_size:
41+
# Only resize when both dimensions are available
42+
if max_size.get('w') and max_size.get('h'):
4043
# resize the image to the w/h maximum specified
41-
ratio = min(max_size[0] / image.size[0], max_size[1] / image.size[1])
44+
ratio = min(max_size['w'] / image.size[0], max_size['h'] / image.size[1])
4245
self.metrics.add('ratio', ratio)
4346
if ratio < 1:
44-
image = image.resize((round(image.size[0] * ratio),
45-
round(image.size[1] * ratio)), Image.ANTIALIAS)
47+
size_tuple = (round(image.size[0] * ratio), round(image.size[1] * ratio))
48+
image = image.resize(size_tuple, Image.ANTIALIAS)
4649

4750
# Mode 'P' is for paletted images. They must be converted to RGB before exporting to
4851
# jpeg, otherwise Pillow will throw an error. This is a temporary workaround, as the
@@ -53,22 +56,22 @@ def export(self):
5356

5457
# handle transparency
5558
# from https://github.com/python-pillow/Pillow/issues/2609
56-
if image.mode in ('RGBA', 'RGBa', 'LA') and type in ['jpeg', 'jpg']:
59+
if image.mode in ('RGBA', 'RGBa', 'LA') and image_type in ['jpeg', 'jpg']:
5760
# JPEG has no transparency, so anything that was transparent gets changed to
5861
# EXPORT_BACKGROUND_COLOR. Default is white.
5962
background = Image.new(image.mode[:-1], image.size, EXPORT_BACKGROUND_COLOR)
6063
background.paste(image, image.split()[-1])
6164
image = background
6265

63-
image.save(self.output_file_path, type)
66+
image.save(self.output_file_path, image_type)
6467
image.close()
6568

6669
except (UnicodeDecodeError, IOError, FileNotFoundError, OSError) as err:
67-
name, extension = os.path.splitext(os.path.split(self.source_file_path)[-1])
70+
os.path.splitext(os.path.split(self.source_file_path)[-1])
6871
raise exceptions.PillowImageError(
6972
'Unable to export the file as a {}, please check that the '
70-
'file is a valid image.'.format(type),
71-
export_format=type,
73+
'file is a valid image.'.format(image_type),
74+
export_format=image_type,
7275
detected_format=imghdr.what(self.source_file_path),
7376
original_exception=err,
7477
code=400,

mfr/extensions/pdf/templates/viewer.mako

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ http://sourceforge.net/adobe/cmap/wiki/License/
4040

4141
% if enable_hypothesis:
4242
<style>
43-
body.show-hypothesis #toolbarViewer {
44-
position: relative;
45-
margin-right: 36px;
43+
body.show-hypothesis .annotator-frame {
44+
margin-top: 32px;
4645
}
4746
</style>
4847
% endif

mfr/extensions/tabular/render.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,22 @@ def _populate_data(self, fp, ext):
110110
"""
111111
function_preference = settings.LIBS.get(ext.lower())
112112

113-
for function in function_preference:
113+
for populate_func in function_preference:
114114
try:
115-
imported = function()
115+
imported = populate_func()
116116
except ImportError:
117117
pass
118118
else:
119-
self._renderer_tabular_metrics['importer'] = function.__name__
119+
self._renderer_tabular_metrics['importer'] = populate_func.__name__
120120
try:
121121
return imported(fp)
122-
except (KeyError, ValueError):
122+
except (KeyError, ValueError) as err:
123+
logger.error('WB has encountered an unexpected error '
124+
'when trying to render a tabular file: {}'.format(err))
123125
raise exceptions.UnexpectedFormattingError(
124126
'Unexpected formatting error.',
125127
extension=self.metadata.ext,
126-
formatting_function=str(function),
128+
formatting_function=str(populate_func),
127129
)
128130

129131
# this will only occur if function_preference is an empty set

mfr/providers/osf/provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def metadata(self):
7373
metadata_response = await self._make_request(
7474
'HEAD',
7575
download_url,
76-
headers={settings.MFR_ACTION_HEADER: self.action or ''}
76+
headers=({settings.MFR_ACTION_HEADER: self.action} if self.action else None)
7777
)
7878
response_code = metadata_response.status
7979
response_reason = metadata_response.reason

mfr/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.27.1'
1+
__version__ = '18.0.0'

tasks.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,27 @@ def flake(ctx):
4949

5050

5151
@task
52-
def test(ctx, verbose=False):
52+
def test(ctx, verbose=False, nocov=False, extension=None, path=None):
53+
"""Run full or customized tests for MFR.
54+
:param ctx: the ``invoke`` context
55+
:param verbose: the flag to increase verbosity
56+
:param nocov: the flag to disable coverage
57+
:param extension: limit the tests to the given extension only
58+
:param path: limit the tests to the given path only
59+
:return: None
60+
"""
5361
flake(ctx)
54-
cmd = 'py.test --cov-report term-missing --cov mfr tests'
55-
if verbose:
56-
cmd += ' -v'
62+
# `--extension=` and `--path=` are mutually exclusive options
63+
assert not (extension and path)
64+
if path:
65+
path = '/{}'.format(path) if path else ''
66+
elif extension:
67+
path = '/extensions/{}/'.format(extension) if extension else ''
68+
else:
69+
path = ''
70+
coverage = ' --cov-report term-missing --cov mfr' if not nocov else ''
71+
verbose = '-v' if verbose else ''
72+
cmd = 'py.test{} tests{} {}'.format(coverage, path, verbose)
5773
ctx.run(cmd, pty=True)
5874

5975

0 commit comments

Comments
 (0)