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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file uai_pre_import_transform_interface-1.1.2.tar.gz.
File metadata
- Download URL: uai_pre_import_transform_interface-1.1.2.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.9 Linux/5.4.0-1038-aws
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eca2fcb5e1de5227953329b6da07e1fa35f6161f1368887683ee7decc1a81ed5
|
|
| MD5 |
f1ce1e92e14223a7df7c6c92a8ad867b
|
|
| BLAKE2b-256 |
6355ce772ca1f5d9e62b61edacff9a00ee752f68ff7ea13b55ccf069cf14cbaf
|
File details
Details for the file uai_pre_import_transform_interface-1.1.2-py3-none-any.whl.
File metadata
- Download URL: uai_pre_import_transform_interface-1.1.2-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.9 Linux/5.4.0-1038-aws
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55c51ee3097c73f0ca81e0571fd42021fd4ed20ef9c16d89342383a4fb192fcd
|
|
| MD5 |
3536dc0808ebbe7b481123049ff7a16c
|
|
| BLAKE2b-256 |
1b221250fc726a11f195c06fce3092e323e4ab928c11fbc74bea8fc82872ff9e
|