Skip to content

Commit

Permalink
stricter lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmandic committed Jun 27, 2023
1 parent f7ff5bc commit c80b1eb
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 24 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/on_pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ignore-paths=^repositories/.*$,
^extensions/.*$,
^extensions-builtin/.*$,
/usr/lib/.*$,
^modules/dml/.*$,
^modules/models/diffusion/.*$,
ignore-patterns=
ignored-modules=
jobs=0
Expand Down
2 changes: 1 addition & 1 deletion installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion modules/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def _hf(wk: str, t: torch.Tensor):
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])
Expand Down
2 changes: 1 addition & 1 deletion modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def init(self, all_prompts, all_seeds, all_subseeds):
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
Expand Down
6 changes: 3 additions & 3 deletions modules/safe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re

import torch
import numpy
import numpy as np
import _codecs

# PyTorch 1.13 and later have _TypedStorage renamed to TypedStorage
Expand Down Expand Up @@ -43,9 +43,9 @@ def find_class(self, module, name):
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':
Expand Down
2 changes: 1 addition & 1 deletion modules/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions modules/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,9 @@ def update_orig(image, state):
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")
Expand Down
2 changes: 1 addition & 1 deletion modules/ui_extra_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def create_html(self, tabname):
return ''

def list_items(self):
raise NotImplementedError()
raise NotImplementedError

def allowed_directories_for_previews(self):
return []
Expand Down
42 changes: 32 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
[tool.ruff]

target-version = "py39"

extend-select = [
"B",
target-version = "py310"
select = [
"F",
"E",
"W",
"C",
"B",
"I",
"W",
"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`
"I001", # Import block is un-sorted or un-formatted
"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]
Expand Down

0 comments on commit c80b1eb

Please sign in to comment.