stricter lint rules

pull/1553/head^2
Vladimir Mandic 2023-06-27 10:28:47 -04:00
parent f7ff5bcf3c
commit c80b1ebc36
10 changed files with 54 additions and 25 deletions

View File

@ -16,11 +16,16 @@ jobs:
python-version: 3.10.6
cache: pip
cache-dependency-path: requirements.txt
- name: run-lint
- name: run-ruff
run: |
python -m pip install --upgrade pip
pip install pylint
pylint $(git ls-files '*.py')
pip install ruff
ruff .
# - name: run-pylint
# run: |
# python -m pip install --upgrade pip
# pip install pylint
# pylint $(git ls-files '*.py')
- name: test-startup
run: |
export COMMANDLINE_ARGS="--debug --test"

View File

@ -13,6 +13,8 @@ ignore-paths=^repositories/.*$,
^extensions/.*$,
^extensions-builtin/.*$,
/usr/lib/.*$,
^modules/dml/.*$,
^modules/models/diffusion/.*$,
ignore-patterns=
ignored-modules=
jobs=0

View File

@ -381,7 +381,7 @@ def check_modified_files():
try:
res = git('status --porcelain')
files = [x[2:].strip() for x in res.split('\n')]
files = [x for x in files if len(x) > 0 and (not x.startswith('extensions')) and (not x.startswith('wiki')) and (not x.endswith('.json')) and (not '.log' in x)]
files = [x for x in files if len(x) > 0 and (not x.startswith('extensions')) and (not x.startswith('wiki')) and (not x.endswith('.json')) and ('.log' not in x)]
if len(files) > 0:
log.warning(f'Modified files: {files}')
except Exception:

View File

@ -350,7 +350,7 @@ def run_modelconvert(model, checkpoint_formats, precision, conv_type, custom_nam
ema_k = "___"
try:
ema_k = "model_ema." + k[6:].replace(".", "")
except:
except Exception:
pass
if ema_k in state_dict:
_hf(k, state_dict[ema_k])

View File

@ -239,7 +239,7 @@ class StableDiffusionProcessing:
pass
def sample(self, conditioning, unconditional_conditioning, seeds, subseeds, subseed_strength, prompts):
raise NotImplementedError()
raise NotImplementedError
def close(self):
self.sampler = None # pylint: disable=attribute-defined-outside-init

View File

@ -6,7 +6,7 @@ import zipfile
import re
import torch
import numpy
import numpy as np
import _codecs
# PyTorch 1.13 and later have _TypedStorage renamed to TypedStorage
@ -43,9 +43,9 @@ class RestrictedUnpickler(pickle.Unpickler):
if module == 'torch.nn.modules.container' and name in ['ParameterDict']:
return getattr(torch.nn.modules.container, name)
if module == 'numpy.core.multiarray' and name in ['scalar', '_reconstruct']:
return getattr(numpy.core.multiarray, name)
return getattr(np.core.multiarray, name)
if module == 'numpy' and name in ['dtype', 'ndarray']:
return getattr(numpy, name)
return getattr(np, name)
if module == '_codecs' and name == 'encode':
return encode
if module == "pytorch_lightning.callbacks" and name == 'model_checkpoint':

View File

@ -33,7 +33,7 @@ class Script:
def title(self):
"""this function should return the title of the script. This is what will be displayed in the dropdown menu."""
raise NotImplementedError()
raise NotImplementedError
def ui(self, is_img2img):
"""this function should create gradio UI elements. See https://gradio.app/docs/#components

View File

@ -556,9 +556,9 @@ def create_ui():
with gr.TabItem('Batch', id='batch', elem_id="img2img_batch_tab") as tab_batch:
hidden = '<br>Disabled when launched with --hide-ui-dir-config.' if modules.shared.cmd_opts.hide_ui_dir_config else ''
gr.HTML(
"<p style='padding-bottom: 1em;' class=\"text-gray-500\">Process images in a directory on the same machine where the server is running." +
"<br>Use an empty output directory to save pictures normally instead of writing to the output directory." +
"<br>Add inpaint batch mask directory to enable inpaint batch processing."
"<p style='padding-bottom: 1em;' class=\"text-gray-500\">Process images in a directory on the same machine where the server is running" +
"<br>Use an empty output directory to save pictures normally instead of writing to the output directory" +
"<br>Add inpaint batch mask directory to enable inpaint batch processing"
f"{hidden}</p>"
)
img2img_batch_input_dir = gr.Textbox(label="Inpaint batch input directory", **modules.shared.hide_dirs, elem_id="img2img_batch_input_dir")

View File

@ -143,7 +143,7 @@ class ExtraNetworksPage:
return ''
def list_items(self):
raise NotImplementedError()
raise NotImplementedError
def allowed_directories_for_previews(self):
return []

View File

@ -1,25 +1,44 @@
[tool.ruff]
target-version = "py39"
extend-select = [
"B",
"C",
"I",
target-version = "py310"
select = [
"F",
"E",
"W",
"C",
"B",
"I",
"YTT",
"ASYNC",
"RUF",
"AIR",
"NPY",
"C4",
"T10",
"EXE",
"ISC",
"ICN",
"RSE",
"TCH",
"TID",
"INT",
"PLE",
# "FIX",
# "A",
# "T20",
# "S",
# "PL",
]
exclude = [
"extensions",
"extensions-disabled",
"extensions-builtin",
"modules/lora",
"modules/lycoris",
"modules/dml",
"modules/models/diffusion",
]
ignore = [
"C408", # Rewrite as a literal
"A003", # Class attirbute shadowing builtin
"C408", # Rewrite as a literal
"C901", # Function is too complex
"E501", # Line too long
"E731", # Do not assign a `lambda` expression, use a `def`
@ -27,6 +46,9 @@ ignore = [
"W605", # invalid escape sequence, messes with some docstrings
"E402", # Module level import not at top of file
"F401", # Imported but unused
"B905", # Without explicit scrict
"RUF005", # Consider concatenation
"ISC003", # Implicit string concatenation
]
[tool.ruff.flake8-bugbear]