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.2.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.2.tar.gz.

File metadata

File hashes

Hashes for uai_pre_import_transform_interface-1.1.2.tar.gz
Algorithm Hash digest
SHA256 eca2fcb5e1de5227953329b6da07e1fa35f6161f1368887683ee7decc1a81ed5
MD5 f1ce1e92e14223a7df7c6c92a8ad867b
BLAKE2b-256 6355ce772ca1f5d9e62b61edacff9a00ee752f68ff7ea13b55ccf069cf14cbaf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for uai_pre_import_transform_interface-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 55c51ee3097c73f0ca81e0571fd42021fd4ed20ef9c16d89342383a4fb192fcd
MD5 3536dc0808ebbe7b481123049ff7a16c
BLAKE2b-256 1b221250fc726a11f195c06fce3092e323e4ab928c11fbc74bea8fc82872ff9e

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