algoo / preview-generator

generates previews of files with cache management
https://pypi.org/project/preview-generator/
MIT License
228 stars 50 forks source link

Add 'dry_run' parameter to get_*_preview() to just return the preview file path #203

Closed flyte closed 3 years ago

flyte commented 3 years ago

This is useful to implement your own caching system, for example if your previews are on S3, and you want to check if they exist there before generating a new preview. This type of behaviour is important for distributed systems such as multiple preview-generator instances running on Kubernetes, since they may not share a local file system (although it is possible).

flyte commented 3 years ago

Not sure why the format test is failing, as black -l 100 doesn't reformat the file it's complaining about:

flyte@demosthenes:~/dev/preview-generator/preview_generator/preview
$ black -l 100 generic_preview.py 
All done! ✨ 🍰 ✨
1 file left unchanged.

From Travis:

$ black -l 100 --exclude '/(\..*)/' --diff --check preview_generator tests setup.py
--- preview_generator/preview/generic_preview.py    2020-10-13 14:59:33.301142 +0000
+++ preview_generator/preview/generic_preview.py    2020-10-13 15:01:09.642880 +0000
@@ -14,11 +14,13 @@

 class PreviewBuilder(object):
     default_size = ImgDims(256, 256)

-    def __init__(self,) -> None:
+    def __init__(
+        self,
+    ) -> None:
         self.logger = logging.getLogger(LOGGER_NAME)
         self.logger.info("New Preview builder of class" + str(self.__class__))

     @classmethod
     def get_supported_mimetypes(cls) -> typing.List[str]:
would reformat preview_generator/preview/generic_preview.py
Oh no! 💥 💔 💥
1 file would be reformatted, 82 files would be left unchanged.
The command "black -l 100 --exclude '/(\..*)/' --diff --check preview_generator tests setup.py" exited with 1.
raphj commented 3 years ago

@flyte it's probably because of the comma after self, you may want to try to remove it :-)

flyte commented 3 years ago

A-ha! I don't recall changing that :shrug:

All passing now, thanks.

flyte commented 3 years ago

FYI, this was a difference between my version of black (19.3b0) and the latest, which is used on the CI (20.8b1).

inkhey commented 3 years ago

Thanks for your contribution @flyte . :+1: