Skip to main content

No project description provided

Project description

General

This package provides an Interface that can be implemented to then be turned into a job. The used URI interface (from uai_pre_transform_interface import URI) is basically a pathlib.Path with some missing functionality.

WARNING: URI is not a local file

Beware: Inside understand.ai we will hand cloud paths as URIs. So using the string of a path to open it will fail in these cases! E.g. Do not do things like this:

from uai_pre_import_transform_interface import PreImportTransformInterface, URI
from PIL import Image

class PreImportTransformer(PreImportTransformInterface):
    def transform(self, input_path: URI, output_path: URI):
        path_to_image = input_path / "images" / "00001.png"
        with Image.open(str(path_to_image)) as im:  # This will fail if input path is "gs://dataset/clip1/"
            im.show()

instead you could do

from uai_pre_import_transform_interface import PreImportTransformInterface, URI
from PIL import Image
from tempfile import NamedTemporaryFile

class PreImportTransformer(PreImportTransformInterface):
    def transform(self, input_path: URI, output_path: URI):
        path_to_image = input_path / "images" / "00001.png"
        
        # example for when your method takes readable bytes
        with Image.open(path_to_image.open("rb")) as im:
            im.show()

        # example for when your method needs just a path to the file
        with NamedTemporaryFile() as tmp:
            tmp.write(path_to_image.open("rb").read())
            Image.open(tmp.name)

Unit tests do not catch this, unfortunately. One idea to be more save against this could be to not use pathlib.Path directly for debugging but to instead extend path with an implementation that raises an error on usage of __str__.

from pathlib import Path

class DebuPath(Path):
    def __str__(self):
        raise Exception("it is not a good idea to use strings for paths for anything but logging as these paths could point to remote resources.")

Implementation

Every implementation should provide a python package named by you. Let's use package_name as an example. From this package the following import has to work:

from package_name import PreImportTransformer

This should give your implementation of the interface. To achieve this the __init__.py oyour package should contain something like this (depending on how you name things):

from .my_interface_implementation import PreImportTransformer
__all__: Sequence[str] = ["PreImportTransformer"]

This is how we will automatically bind your library into our system. img.png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uai_pre_import_transform_interface-1.1.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file uai_pre_import_transform_interface-1.1.1.tar.gz.

File metadata

File hashes

Hashes for uai_pre_import_transform_interface-1.1.1.tar.gz
Algorithm Hash digest
SHA256 82c700df6a85be881656d1c97215853b459d679139cc629e64890ac84901c655
MD5 2ff6d7add5cdf0e273ddbaf7b5aa3f74
BLAKE2b-256 9778572749ce5f9644fa665e42b0bca55048ecfd2b5f8b5ec63dee65ec9023ba

See more details on using hashes here.

File details

Details for the file uai_pre_import_transform_interface-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for uai_pre_import_transform_interface-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 16d2b81dbe8dbd81856deb120d0450ae896b117e987ca554ae4813536c62c059
MD5 19cf31d4b173656763cca8a0cbd43dc1
BLAKE2b-256 81ce6136416cd2ca1b864fd2e10863c110163f91fb86e7ad1e8b67183c22cabf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page