Skip to content

Conversation

@AddisonSchiller
Copy link
Contributor

@AddisonSchiller AddisonSchiller commented Jul 28, 2017

refs: https://openscience.atlassian.net/browse/SVCS-407

Purpose

add the .psd format to tabular file renderer

Summary of Changes

Added support to the image exporter to export .psd files as jpeg
Added the ext variable to the base exporter.

Testing Notes

There are 5-6 files on the jira ticket that can be used for testing. All should be renderable and not too large.

@AddisonSchiller AddisonSchiller changed the title Adding support for .psd files to MFR. Also added an ext variable to b… [SVCS-404] Adding support for .psd files to MFR Oct 5, 2017
@AddisonSchiller AddisonSchiller changed the title [SVCS-404] Adding support for .psd files to MFR [SVCS-407] Adding support for .psd files to MFR Oct 5, 2017
Copy link
Contributor

@cslzchen cslzchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code runs as expected on my local machine 👍 .
PR looks great except one question on warnings and a few nick-picky style requests. Back to you @AddisonSchiller 🔥

class BaseExporter(metaclass=abc.ABCMeta):

def __init__(self, source_file_path, output_file_path, format):
def __init__(self, ext, source_file_path, output_file_path, format):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For naming, normalized_name may be better then ext since it is consistent (LINK). Or consider full word extension if no conflicting/shadowing issue. I understand it is confusing since the normalized_name is indeed the extension name (LINK).

Our code base is not documented well. It will be great if we can gradually add doc string for functions and methods (e.g. for the ones that you modified, or the ones that you had a hard time to understand) that have many arguments. Here is an example where my description is not accurate and please revise:

def __init__(self, extension, source_file_path, output_file_path, format):

    """Initialize the base exporter.
    
    :param extension: the name of the extension to be exported
    :param source_file_path: the path of the input file
    :param output_file_path: the path of the output file
    :param format: the format of the exported file (e.g. 1200*1200.jpg)
    """
    ...

Copy link
Contributor Author

@AddisonSchiller AddisonSchiller Oct 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ext and self.ext was used as I saw it already being used elsewhere. Extension in MFR could refer to an actual extension library (eg the images extension, or Unoconv extension) So that is why it was avoided. normalized_name and ext are the same thing,
but the variable name doesnt make sense to me, so i did didn't use it.(dont remember why it is this way).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Let's keep using ext then and having the doc string should help for clarification.

try:
image = Image.open(self.source_file_path)
if self.ext in ['.psd']:
# silence warnings from psd-tools
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the warnings? Could this silence useful warnings as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warnings are custom thrown by the library. If there is an error, that still is caught. warnings look something like this:
/usr/local/lib/python3.5/site-packages/psd_tools/decoder/image_resources.py:138: UserWarning: ICC profile is not handled; colors could be incorrect. Please build PIL or Pillow with littlecms/littlecms2 support.

I remember doing some research into this when i originally did this PR, but Its been quite awhile and i can't remember much besides coming to the conclusion that it would be okay.
Warnings are silence so they dont spam the logs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Warnings are fine since they are not exceptions. Your comment in the code also helps. We do want to catch exceptions thrown by psd-tools but maybe in another ticket so this is not a blocker.

import os
import imghdr

import warnings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warnings is a standard python library (double check in case). Here is mine:

# standard python libarary
import os
import imghdr
import warnings

# third-party library
from PIL import Image
from psd_tools import PSDImage

# application code
from mfr.core import extension
from mfr.extensions.image import exceptions

@cslzchen
Copy link
Contributor

cslzchen commented Oct 6, 2017

One more thing that I forgot: add tests if applicable. Update: as discussed
, no tests for this PR (due to some limitation on Pillow 2.82).

Also added an ext variable to base_exporter.
Extensions get swallowed in the image exporter.
This serves as a work around to it.
Copy link
Contributor

@cslzchen cslzchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New changes looks good 🎆 🎆 , move to PCR 🔥 🔥 .

@felliott
Copy link
Member

felliott commented Nov 8, 2017

LGTMMTRTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants