Skip to content
Pre-release
Pre-release

@heynemann heynemann released this Feb 27, 2020

THIS RELEASE HAS MANY BREAKING CHANGES AND IS AN ALPHA!

Also this is a draft for the release notes. I'll be updating it in the coming days.

WARNING

This is an alpha release! Most of the extensions will be broken at this point.
Who this release is for:

  • Alpha testers (would be great if you could be one of them ❤️ );
  • Extension devs (if you have a thumbor extension now is a great time to modernize it to py3 and thumbor 7).

Installing

Since this release is an alpha release if you want to test it you must specify the version when using pip:

$ pip install "thumbor==7.0.0a5"
$ thumbor-doctor

Keep on reading for the changes you need to be aware of. If you experience any problems, please run thumbor-doctor --nocolor and create an issue with your problem and the results of running thumbor-doctor.

Introduction

This release notes will be slightly different from others as I feel we need to have more of a conversation on what happened. I'll try to detail the changes below, but first I'll explain them.

We set out to update thumbor to work with python3. During the work required to do that, it became clear that we were going to break most extensions with this release.

At this point we made a decision to not only update thumbor to python3, but completely modernize it.

Some of the 7.0.0 features:

  • Python 3.6+ support. Python 2 is not supported anymore (does not even work).
  • Updated tornado to release 6.0.3. This should fix many bugs/vulnerabilities we still had due to old tornado.
  • Updated pillow version to 7.0.0.
  • All tests now run using py.test.
  • Updated every dependency we could update.

While updating the codebase to support new tornado and python 3 we also decided to get rid of the callback hell that tormended the committers for the last 10 years or so. The new codebase uses proper async/await idioms for all the asynchronous code.

As the last part of the intro, we added a new concept to customizing thumbor: handler lists. It has been a request for a long time to allow thumbor extensions to add new handlers to thumbor. Well, now you can!

Lets get to the details!

Breaking Changes

First let's see what breaks (apart from not supporting python 2, that is).

Storages

Previously storages were implemented like this (this is No Storage):

class Storage(BaseStorage):

    def put(self, path, bytes):
        return path

    def put_crypto(self, path):
        return path

    def put_detector_data(self, path, data):
        return path

    @return_future
    def get_crypto(self, path, callback):
        callback(None)

    @return_future
    def get_detector_data(self, path, callback):
        callback(None)

    @return_future
    def get(self, path, callback):
        callback(None)

    @return_future
    def exists(self, path, callback):
        callback(False)

    def remove(self, path):
        pass

With release 7.0.0 we modernize these functions to be async. The same storage in the new release:

class Storage(BaseStorage):
    async def put(self, path, file_bytes):
        return path

    async def put_crypto(self, path):
        return path

    async def put_detector_data(self, path, data):
        return path

    async def get_crypto(self, path):
        return None

    async def get_detector_data(self, path):
        return None

    async def get(self, path):
        return None

    async def exists(self, path):
        return False

    async def remove(self, path):
        pass

Much simpler, right? No funky callback business. The downside is that all storages out there need to be updated. It should be simply a matter of "asyncifying" them.

Loaders

The same applies to loaders. Let's see what a loader looked like in 6.7.2:

@return_future
def load(context, path, callback):
    # does a lot of stuff and :(
    callback(loaded_image)

Now in 7.0.0 it is a simple async function:

async def load(context, path):
    # does a lot of stuff with no callbacks whatsoever
    return loader_result

It's much simpler to understand the new loaders (and to create new ones), but the same issue as above: previous loaders won't work with thumbor 7.0.0+ (until asyncified).
Important note: going forward, loaders should return LoaderResult object. While returning plain image bytes still works, it's encouraged to update loaders to return object.

Result Storages

You get the gist, right? No Storage Result Storage in 6.7.2:

class Storage(BaseStorage):
    # THIS METHOD IS NOT EVEN ASYNC :(
    def put(self, bytes):
        return ''

    @return_future
    def get(self, callback):
        callback(None)

Now in 7.0.0+:

class Storage(BaseStorage):
    async def put(self, image_bytes):
        return ""

    async def get(self):
        return None

Previous result storages won't work with thumbor 7.0.0+ (until asyncified).

Filters

Same ol', same ol'. Let's check format filter in 6.7.2.

class Filter(BaseFilter):

    @filter_method(BaseFilter.String)
    def format(self, format):
        if format.lower() not in ALLOWED_FORMATS:
            logger.debug('Format not allowed: %s' % format.lower())
            self.context.request.format = None
        else:
            logger.debug('Format specified: %s' % format.lower())
            self.context.request.format = format.lower()

Now the same filter in 7.0.0:

class Filter(BaseFilter):
    @filter_method(BaseFilter.String)
    async def format(self, file_format):
        if file_format.lower() not in ALLOWED_FORMATS:
            logger.debug("Format not allowed: %s", file_format.lower())
            self.context.request.format = None
        else:
            logger.debug("Format specified: %s", file_format.lower())
            self.context.request.format = file_format.lower()

Hardly noticeable, right? Except now you get to run async code in your filters without arcane magic or callbacks. As with all the others, previous filters won't work with thumbor 7.0.0+ (until asyncified).

Detectors

These were also modernized. Let's take a look at our face detector in 6.7.2:

class Detector(CascadeLoaderDetector):
    # details removed for clarity
    def detect(self, callback):
        features = self.get_features()
        if features:
            for (left, top, width, height), neighbors in features:
                top = self.__add_hair_offset(top, height)
                self.context.request.focal_points.append(
                    FocalPoint.from_square(left, top, width, height, origin="Face Detection")
                )
            callback()
        else:
            self.next(callback)

Now the same detector in 7.0.0+:

class Detector(CascadeLoaderDetector):
    # details removed for clarity

    async def detect(self):
        features = self.get_features()
        if features:
            for (left, top, width, height), _ in features:
                top = self.__add_hair_offset(top, height)
                self.context.request.focal_points.append(
                    FocalPoint.from_square(
                        left, top, width, height, origin="Face Detection"
                    )
                )
            return

        await self.next()

No more callbacks and now detector pipeline works by awaiting the next detector or just a plain early return to stop the pipe. As with the other updates, previous detectors will not work with thumbor 7.0.0 (until asyncified).

Improvements

Thumbor Testing Tools

This one is for you, an extension author! Thumbor now includes a thumbor.testing module that ships with it and allows extensions to create tests that get thumbor up and running easier. An example test from our code:

from preggy import expect
from tornado.testing import gen_test

from thumbor.testing import TestCase
from thumbor.storages.no_storage import Storage as NoStorage

class NoStorageTestCase(TestCase):
    def get_image_url(self, image):
        return "s.glbimg.com/some/{0}".format(image)

    @gen_test
    async def test_store_image_should_be_null(self):
        iurl = self.get_image_url("source.jpg")
        storage = NoStorage(None)
        stored = await storage.get(iurl)
        expect(stored).to_be_null()

   # many more tests!

Notice how the test can now test only what it needs to. We're using py.test now and that allows async test methods.

Revised Docs

The many fundamental changes in thumbor prompted a major review of the docs and improvement of many areas in it.

Handler Lists

Not all is breaking changes, though. Now you get to extend thumbor with new handlers! And it is as simple as creating a module with:

   from typing import Any, cast

   from thumbor.handler_lists import HandlerList

   from my.handlers.index import IndexHandler

   def get_handlers(context: Any) -> HandlerList:
       something_enabled = cast(bool, self.context.config.SOMETHING_ENABLED)
       if not something_enabled:
           return []
       return [
           (r"/my-url/?", IndexHandler, {"context": self.context}),
       ]

Then including it in thumbor.conf:

   from thumbor.handler_lists import BUILTIN_HANDLERS

   # Two things worth noticing here:
   # 1) The handler list order indicates precedence, so whatever matches first will be executed;
   # 2) Please do not forget thumbor's built-ins or you'll kill thumbor functionality.
   HANDLER_LISTS = BUILTIN_HANDLERS + [
       "my.handler_list',
   ]

Acknowledgements

This release would not be possible without the work of thumbor's commiters. I'd like to call out the work of @kkopachev that has enabled me to move forward with this release.

Again thanks @kkopachev for all the code reviews and thanks the whole of thumbor community for catching errors when I hadn't even written the release notes! That's nothing short of amazing.

Now onto the not comprehensive list of changes in this release!

Fixes/Features

  • Fix typo (thanks @timgates42);
  • Python 3 support (thanks @kkopachev);
  • Removed callbacks in favor of async-await;
  • Simplified pillow feature checks (thanks @kkopachev);
  • Extensive work to improve codebase quality (lint errors should be few now);
  • Using stdlib which instead of a custom one (thanks @kkopachev);
  • Major documentation review;
  • Added handler lists to allow further extension;
  • Update classifiers and add python_requires to help pip (thanks @hugovk);
  • Ability to run thumbor in multiprocess mode (thanks @kkopachev);
  • Python 3.6 support (thanks @amanagr);
  • New thumbor-doctor command to help diagnose issues with installs.

Diff to previous release
Pypi release

Assets 2
Mar 9, 2020
Release 7.0.0a4
Mar 9, 2020
[IMPR] Removed poetry from thumbor
**Is backwards compatible**: yes

This commit removes poetry from thumbor as it was making it
increasingy harder to release consistent versions.

We still manage to keep most of the versioning used in poetry in
setup.py. If you feel like the versions can be a little looser, just PR.

@heynemann heynemann released this Mar 9, 2020 · 51 commits to master since this release

Changelog

Docs

  • Fixed issue with packaging in 6.7.3.

Diff to previous release
Pypi release

Assets 2
Mar 9, 2020
Release 6.7.4

@heynemann heynemann released this Feb 29, 2020 · 51 commits to master since this release

Changelog

Docs

  • Fixed issue with running thumbor with a file descriptor (thanks @kkopachev).

Diff to previous release
Pypi release

Assets 2
Feb 27, 2020
Release 7.0.0a2
Feb 26, 2020
Release 7.0.0a1

@heynemann heynemann released this Feb 26, 2020 · 51 commits to master since this release

Changelog

Docs

  • Fixed documentation build issues.

Diff to previous release
Pypi release

Assets 2

@heynemann heynemann released this Feb 3, 2020 · 51 commits to master since this release

Changelog

Fixes

  • Fix for a bug that blocked tornado thread (#1151 thanks @Tideorz);
  • Fix numpy not writable ndarray (#1171 thanks @cristiandean);
  • Fix FocalPoint from_dict now returns integer (#1172 thanks @cristiandean);
  • Replace dots in original image's source with underscore to prevent stats hierarchy levels being created (#1241 thanks @dfrieling).

Improvements

Modernizing

Docs

Diff to previous release
Pypi release

Assets 2
You can’t perform that action at this time.