From 40e396a2c49052b40886bd05df652c184733ff7d Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Sun, 19 Feb 2023 22:10:35 -0600 Subject: [PATCH] sonar lint fixes --- api/onnx_web/chain/upscale_resrgan.py | 4 ++-- api/onnx_web/chain/utils.py | 2 +- api/onnx_web/image.py | 6 +++--- api/onnx_web/serve.py | 4 ++-- api/onnx_web/server/device_pool.py | 4 ++-- api/onnx_web/utils.py | 4 ++-- api/scripts/test-memory-leak.sh | 10 +++++----- 7 files changed, 17 insertions(+), 17 deletions(-) mode change 100644 => 100755 api/scripts/test-memory-leak.sh diff --git a/api/onnx_web/chain/upscale_resrgan.py b/api/onnx_web/chain/upscale_resrgan.py index a97f7ecd..178360c3 100644 --- a/api/onnx_web/chain/upscale_resrgan.py +++ b/api/onnx_web/chain/upscale_resrgan.py @@ -35,7 +35,7 @@ def load_resrgan( return cache_pipe if not path.isfile(model_path): - raise Exception("Real ESRGAN model not found at %s" % model_path) + raise FileNotFoundError("Real ESRGAN model not found at %s" % model_path) if params.format == "onnx": # use ONNX acceleration, if available @@ -66,7 +66,7 @@ def load_resrgan( scale=params.scale, ) else: - raise Exception("unknown platform %s" % params.format) + raise ValueError("unknown platform %s" % params.format) dni_weight = None if params.upscale_model == TAG_X4_V3 and params.denoise != 1: diff --git a/api/onnx_web/chain/utils.py b/api/onnx_web/chain/utils.py index 053a093f..6598f10b 100644 --- a/api/onnx_web/chain/utils.py +++ b/api/onnx_web/chain/utils.py @@ -52,7 +52,7 @@ def process_tile_spiral( **kwargs, ) -> Image.Image: if scale != 1: - raise Exception("unsupported scale") + raise ValueError("unsupported scale") width, height = source.size image = Image.new("RGB", (width * scale, height * scale)) diff --git a/api/onnx_web/image.py b/api/onnx_web/image.py index bd9378f3..2e658cf0 100644 --- a/api/onnx_web/image.py +++ b/api/onnx_web/image.py @@ -30,7 +30,7 @@ def mask_filter_gaussian_multiply( """ noise = mask_filter_none(mask, dims, origin) - for i in range(rounds): + for _i in range(rounds): blur = noise.filter(ImageFilter.GaussianBlur(5)) noise = ImageChops.multiply(noise, blur) @@ -45,7 +45,7 @@ def mask_filter_gaussian_screen( """ noise = mask_filter_none(mask, dims, origin) - for i in range(rounds): + for _i in range(rounds): blur = noise.filter(ImageFilter.GaussianBlur(5)) noise = ImageChops.screen(noise, blur) @@ -88,7 +88,7 @@ def noise_source_gaussian( noise = noise_source_uniform(source, dims, origin) noise.paste(source, origin) - for i in range(rounds): + for _i in range(rounds): noise = noise.filter(ImageFilter.GaussianBlur(5)) return noise diff --git a/api/onnx_web/serve.py b/api/onnx_web/serve.py index 3be531cf..38ef1981 100644 --- a/api/onnx_web/serve.py +++ b/api/onnx_web/serve.py @@ -803,8 +803,8 @@ def ready(): done, progress = executor.done(output_file) if done is None: - file = base_join(context.output_path, output_file) - if path.exists(file): + output = base_join(context.output_path, output_file) + if path.exists(output): return ready_reply(True) return ready_reply(done, progress=progress) diff --git a/api/onnx_web/server/device_pool.py b/api/onnx_web/server/device_pool.py index ef091d8e..d6799b75 100644 --- a/api/onnx_web/server/device_pool.py +++ b/api/onnx_web/server/device_pool.py @@ -44,7 +44,7 @@ class JobContext: with self.device_index.get_lock(): device_index = self.device_index.value if device_index < 0: - raise Exception("job has not been assigned to a device") + raise ValueError("job has not been assigned to a device") else: device = self.devices[device_index] logger.debug("job %s assigned to device %s", self.key, device) @@ -57,7 +57,7 @@ class JobContext: def on_progress(step: int, timestep: int, latents: Any): on_progress.step = step if self.is_cancelled(): - raise Exception("job has been cancelled") + raise RuntimeError("job has been cancelled") else: logger.debug("setting progress for job %s to %s", self.key, step) self.set_progress(step) diff --git a/api/onnx_web/utils.py b/api/onnx_web/utils.py index 78befc16..feff4f50 100644 --- a/api/onnx_web/utils.py +++ b/api/onnx_web/utils.py @@ -65,7 +65,7 @@ def get_not_empty(args: Any, key: str, default: Any) -> Any: return val -def get_size(val: Union[int, str, None]) -> SizeChart: +def get_size(val: Union[int, str, None]) -> Union[int, SizeChart]: if val is None: return SizeChart.auto @@ -79,7 +79,7 @@ def get_size(val: Union[int, str, None]) -> SizeChart: return int(val) - raise Exception("invalid size") + raise ValueError("invalid size") def run_gc(devices: List[DeviceParams] = None): diff --git a/api/scripts/test-memory-leak.sh b/api/scripts/test-memory-leak.sh old mode 100644 new mode 100755 index 42d2cdba..764da0c9 --- a/api/scripts/test-memory-leak.sh +++ b/api/scripts/test-memory-leak.sh @@ -4,11 +4,11 @@ test_images=0 while true; do curl "http://${test_host}:5000/api/txt2img?"\ - 'cfg=16.00&steps=35&scheduler=deis-multi&seed=-1&'\ - 'prompt=an+astronaut+eating+a+hamburger&negativePrompt=&'\ - 'model=stable-diffusion-v1-5&platform=any&'\ - 'upscaling=upscaling-real-esrgan-x2-plus&correction=correction-codeformer&'\ - 'lpw=false&width=512&height=512&upscaleOrder=correction-both' \ +'cfg=16.00&steps=35&scheduler=deis-multi&seed=-1&'\ +'prompt=an+astronaut+eating+a+hamburger&negativePrompt=&'\ +'model=stable-diffusion-onnx-v1-5&platform=any&'\ +'upscaling=upscaling-real-esrgan-x2-plus&correction=correction-codeformer&'\ +'lpw=false&width=512&height=512&upscaleOrder=correction-both' \ -X 'POST' \ --compressed \ --insecure || break;