Skip to content

[ENG-7601] Ext image ext ipy updates #383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion mfr/extensions/docx/__init__.py

This file was deleted.

40 changes: 0 additions & 40 deletions mfr/extensions/docx/render.py

This file was deleted.

6 changes: 0 additions & 6 deletions mfr/extensions/docx/templates/viewer.mako

This file was deleted.

14 changes: 10 additions & 4 deletions mfr/extensions/image/export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import imghdr
import warnings

from PIL import Image
Expand All @@ -14,7 +13,7 @@ class ImageExporter(extension.BaseExporter):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.metrics.add('pil_version', Image.VERSION)
self.metrics.add('pil_version', Image.__version__)

def export(self):
parts = self.format.split('.')
Expand Down Expand Up @@ -45,7 +44,7 @@ def export(self):
self.metrics.add('ratio', ratio)
if ratio < 1:
size_tuple = (round(image.size[0] * ratio), round(image.size[1] * ratio))
image = image.resize(size_tuple, Image.ANTIALIAS)
image = image.resize(size_tuple, Image.Resampling.LANCZOS)

# Mode 'P' is for paletted images. They must be converted to RGB before exporting to
# jpeg, otherwise Pillow will throw an error. This is a temporary workaround, as the
Expand All @@ -72,7 +71,14 @@ def export(self):
'Unable to export the file as a {}, please check that the '
'file is a valid image.'.format(image_type),
export_format=image_type,
detected_format=imghdr.what(self.source_file_path),
detected_format= self.detect_image_format(),
original_exception=err,
code=400,
)

def detect_image_format(self):
try:
with Image.open(self.source_file_path) as img:
return img.format.lower()
except Exception:
return None
3 changes: 0 additions & 3 deletions mfr/extensions/ipynb/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ def render(self):
)

exporter = HTMLExporter(config=Config({
'HTMLExporter': {
'template_file': 'basic',
},
'CSSHtmlHeaderTransformer': {
'enabled': False,
},
Expand Down
2 changes: 1 addition & 1 deletion mfr/extensions/md/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MdRenderer(extension.BaseRenderer):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.metrics.add('markdown_version', markdown.version)
self.metrics.add('markdown_version', markdown.__version__)

def render(self):
"""Render a markdown file to html."""
Expand Down
12 changes: 9 additions & 3 deletions mfr/extensions/pdf/export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import imghdr
import logging
from http import HTTPStatus

Expand All @@ -18,7 +17,7 @@ class PdfExporter(extension.BaseExporter):
def __init__(self, *args, **kwargs):

super().__init__(*args, **kwargs)
self.metrics.add('pil_version', Image.VERSION)
self.metrics.add('pil_version', Image.__version__)

def tiff_to_pdf(self, tiff_img, max_size):
""" Turn a tiff into a pdf to support multipage tiffs"""
Expand Down Expand Up @@ -94,7 +93,14 @@ def export(self):
'Unable to export the file as a {}, please check that the '
'file is a valid tiff image.'.format(export_type),
export_format=export_type,
detected_format=imghdr.what(self.source_file_path),
detected_format= self.detect_image_format(),
original_exception=err,
code=HTTPStatus.BAD_REQUEST,
)

def detect_image_format(self):
try:
with Image.open(self.source_file_path) as img:
return img.format.lower()
except Exception as e:
return None
2 changes: 1 addition & 1 deletion mfr/extensions/tabular/libs/h5py_scipy_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def mat_v73(fp):
if isinstance(data, h5py.Dataset):
# h5py Uses row-major ordering. this fixes it so it displays like it does in matlab
# basically just flip it on its axis
list_data = list(zip(*data.value.tolist()))
list_data = list(zip(*data[()].tolist()))
build_sheets(name, list_data, sheets)

return sheets
Expand Down
2 changes: 1 addition & 1 deletion mfr/extensions/tabular/libs/panda_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def data_from_dataframe(dataframe):
data = []
for _, frame_row in dataframe.iterrows():
data_row = {}
for name, value in frame_row.iteritems():
for name, value in frame_row.items():
try:
data_row[name] = numpy.asscalar(value)
except AttributeError:
Expand Down
25 changes: 10 additions & 15 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
aiohttp==3.10.5
chardet==5.2.0
furl==2.0.0
humanfriendly==10
humanfriendly==10.0
invoke==2.2.0
mako==1.3.2
sentry-sdk==2.22.0
Expand All @@ -20,21 +20,20 @@ Pygments==2.19.1

# Docx
#git+https://github.com/jsocol/bleach.git
pydocx==0.9.10

# Image
olefile==0.44
Pillow==11.0.0
olefile==0.47
Pillow==11.2.1
psd-tools==1.10.7

# IPython
ipython==7.31.1
nbconvert==6.4.0
nbformat==5.1.3
traitlets==5.0
jsonschema==2.4.0
jinja2==3.0.0
mistune==0.8.1
nbconvert==7.16.6
nbformat==5.10.4
traitlets==5.14.3
jsonschema==4.24.0
jinja2==3.1.5
mistune==3.1.2

# Pdf
reportlab==4.4.0
Expand All @@ -52,12 +51,8 @@ h5py==3.13
scipy==1.15.2

# Md
markdown==3.8.0
markdown==3.3.7

certifi==2025.1.31


markupsafe==2.0.1

# Standard library imghdr redistribution because it is not supported in python 3.13.
standard-imghdr==3.13.0
4 changes: 2 additions & 2 deletions tests/extensions/audio/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def assets_url():


@pytest.fixture
def export_url():
return 'http://mfr.osf.io/export?url=' + url()
def export_url(url):
return 'http://mfr.osf.io/export?url=' + url


@pytest.fixture
Expand Down
6 changes: 3 additions & 3 deletions tests/extensions/codepygments/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def assets_url():


@pytest.fixture
def export_url():
return 'http://mfr.osf.io/export?url=' + url()
def export_url(url):
return 'http://mfr.osf.io/export?url=' + url


@pytest.fixture
Expand Down Expand Up @@ -133,4 +133,4 @@ def test_render_iso_not_utf16(self, metadata, url, assets_url, export_url):
)
renderer = CodePygmentsRenderer(metadata, file_path, url, assets_url, export_url)
body = renderer.render()
assert 'CREATIVE COMMONS' in body
assert 'CREATIVE<span class="w"> </span>COMMONS' in body
Empty file removed tests/extensions/docx/__init__.py
Empty file.
134 changes: 0 additions & 134 deletions tests/extensions/docx/files/invalid.docx

This file was deleted.

Binary file removed tests/extensions/docx/files/test.docx
Binary file not shown.
Loading
Loading