strict linting template

pull/143/head
Vladimir Mandic 2023-04-14 21:27:29 -04:00
parent b28b7c7a98
commit bf949a5307
8 changed files with 258 additions and 90 deletions

View File

@ -1,28 +1,11 @@
# Please read the [contributing wiki page](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Contributing) before submitting a pull request!
## Description
If you have a large change, pay special attention to this paragraph:
A clear and concise description of what you're trying to accomplish with this, so your intent doesn't have to be extracted from your code
> Before making changes, if you think that your feature will result in more than 100 lines changing, find me and talk to me about the feature you are proposing. It pains me to reject the hard work someone else did, but I won't add everything to the repo, and it's better if the rejection happens before you have to waste time working on the feature.
## Notes
Otherwise, after making sure you're following the rules described in wiki page, remove this section and continue on.
More technical discussion about your changes go here, plus anything that a maintainer might have to specifically take a look at, or be wary of
**Describe what this pull request is trying to achieve.**
## Environment and Testing
A clear and concise description of what you're trying to accomplish with this, so your intent doesn't have to be extracted from your code.
**Additional notes and description of your changes**
More technical discussion about your changes go here, plus anything that a maintainer might have to specifically take a look at, or be wary of.
**Environment this was tested in**
List the environment you have developed / tested this on. As per the contributing page, changes should be able to work on Windows out of the box.
- OS: [e.g. Windows, Linux]
- Browser: [e.g. chrome, safari]
- Graphics card: [e.g. NVIDIA RTX 2080 8GB, AMD RX 6600 8GB]
**Screenshots or videos of your changes**
If applicable, screenshots or a video showing off your changes. If it edits an existing UI, it should ideally contain a comparison of what used to be there, before your changes were made.
This is **required** for anything that touches the user interface.
List the environment you have developed / tested this on

View File

@ -18,13 +18,12 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Python 3.10
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.10.6
cache: pip
cache-dependency-path: |
**/requirements*txt
cache-dependency-path: requirements*txt
- name: Install PyLint
run: |
python -m pip install --upgrade pip

View File

@ -10,20 +10,11 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Python 3.10
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.10.6
cache: pip
cache-dependency-path: |
**/requirements*txt
cache-dependency-path: requirements.txt
- name: Run tests
run: python launch.py --tests test --no-half --disable-opt-split-attention --use-cpu all --skip-torch-cuda-test
- name: Upload main app stdout-stderr
uses: actions/upload-artifact@v3
if: always()
with:
name: stdout-stderr
path: |
test/stdout.txt
test/stderr.txt
run: python launch.py

202
.pylintrc
View File

@ -1,3 +1,201 @@
# See https://pylint.pycqa.org/en/latest/user_guide/messages/message_control.html
[MAIN]
analyse-fallback-blocks=no
clear-cache-post-run=no
#enable-all-extensions=
#errors-only=
#exit-zero=
extension-pkg-allow-list=
extension-pkg-whitelist=
fail-on=
fail-under=10
ignore=CVS
ignore-paths=
ignore-patterns=^\.#
ignored-modules=
jobs=0
limit-inference-results=100
load-plugins=
persistent=yes
py-version=3.10
recursive=no
source-roots=
suggestion-mode=yes
unsafe-load-any-extension=no
#verbose=
[BASIC]
argument-naming-style=snake_case
#argument-rgx=
attr-naming-style=snake_case
#attr-rgx=
bad-names=foo, bar, baz, toto, tutu, tata
bad-names-rgxs=
class-attribute-naming-style=any
class-const-naming-style=UPPER_CASE
#class-const-rgx=
class-naming-style=PascalCase
#class-rgx=
const-naming-style=snake_case
#const-rgx=
docstring-min-length=-1
function-naming-style=snake_case
#function-rgx=
# Good variable names which should always be accepted, separated by a comma.
good-names=i,j,k,e,ex,ok,p
good-names-rgxs=
include-naming-hint=no
inlinevar-naming-style=any
#inlinevar-rgx=
method-naming-style=snake_case
#method-rgx=
module-naming-style=snake_case
#module-rgx=
name-group=
no-docstring-rgx=^_
property-classes=abc.abstractproperty
#typealias-rgx=
#typevar-rgx=
variable-naming-style=snake_case
#variable-rgx=
[CLASSES]
check-protected-access-in-special-methods=no
defining-attr-methods=__init__,
__new__,
setUp,
asyncSetUp,
__post_init__
exclude-protected=_asdict,_fields,_replace,_source,_make,os._exit
valid-classmethod-first-arg=cls
valid-metaclass-classmethod-first-arg=mcs
[DESIGN]
exclude-too-few-public-methods=
ignored-parents=
max-args=5
max-attributes=7
max-bool-expr=5
max-branches=12
max-locals=15
max-parents=7
max-public-methods=20
max-returns=6
max-statements=50
min-public-methods=2
[EXCEPTIONS]
overgeneral-exceptions=builtins.BaseException,builtins.Exception
[FORMAT]
expected-line-ending-format=
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
indent-after-paren=4
indent-string=' '
max-line-length=200
max-module-lines=9999
single-line-class-stmt=no
single-line-if-stmt=no
[IMPORTS]
allow-any-import-level=
allow-reexport-from-package=no
allow-wildcard-with-all=no
deprecated-modules=
ext-import-graph=
import-graph=
int-import-graph=
known-standard-library=
known-third-party=enchant
preferred-modules=
[LOGGING]
logging-format-style=new
logging-modules=logging
[MESSAGES CONTROL]
disable=C,R,W
confidence=HIGH,
CONTROL_FLOW,
INFERENCE,
INFERENCE_FAILURE,
UNDEFINED
# disable=C,R,W
disable=raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
line-too-long,
missing-function-docstring,
missing-module-docstring,
missing-class-docstring,
logging-fstring-interpolation,
import-outside-toplevel,
enable=c-extension-no-member
[METHOD_ARGS]
timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request
[MISCELLANEOUS]
notes=FIXME,
XXX,
TODO
notes-rgx=
[REFACTORING]
max-nested-blocks=5
never-returning-functions=sys.exit,argparse.parse_error
[REPORTS]
evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10))
msg-template=
#output-format=
reports=no
score=no
[SIMILARITIES]
ignore-comments=yes
ignore-docstrings=yes
ignore-imports=yes
ignore-signatures=yes
min-similarity-lines=4
[SPELLING]
max-spelling-suggestions=4
spelling-dict=
spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy:
spelling-ignore-words=
spelling-private-dict-file=
spelling-store-unknown-words=no
[STRING]
check-quote-consistency=no
check-str-concat-over-line-jumps=no
[TYPECHECK]
contextmanager-decorators=contextlib.contextmanager
generated-members=numpy.*,torch.*,cv2.*
ignore-none=yes
ignore-on-opaque-inference=yes
ignored-checks-for-mixins=no-member,
not-async-context-manager,
not-context-manager,
attribute-defined-outside-init
ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace
missing-member-hint=yes
missing-member-hint-distance=1
missing-member-max-choices=1
mixin-class-rgx=.*[Mm]ixin
signature-mutators=
[VARIABLES]
additional-builtins=
allow-global-unused-variables=yes
allowed-redefined-builtins=
callbacks=cb_,
dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_
ignored-argument-names=_.*|^ignored_|^unused_
init-import=no
redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io

@ -1 +1 @@
Subproject commit 87e4dc6bef09b6e46a15e79da3faaa735b6e628b
Subproject commit fc50810f5fbc3be86fad55a3e13327e77730e321

View File

@ -37,11 +37,11 @@ def run(command, desc=None, errdesc=None, custom_env=None, live=False):
if desc is not None:
print(desc)
if live:
result = subprocess.run(command, shell=True, env=os.environ if custom_env is None else custom_env)
result = subprocess.run(command, check=False, shell=True, env=os.environ if custom_env is None else custom_env)
if result.returncode != 0:
raise RuntimeError(f"""{errdesc or 'Error running command'} Command: {command} Error code: {result.returncode}""")
return ''
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ if custom_env is None else custom_env)
result = subprocess.run(command, stdout=subprocess.PIPE, check=False, stderr=subprocess.PIPE, shell=True, env=os.environ if custom_env is None else custom_env)
if result.returncode != 0:
raise RuntimeError(f"""{errdesc or 'Error running command'}: {command} code: {result.returncode}
{result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stdout)>0 else ''}
@ -51,7 +51,7 @@ def run(command, desc=None, errdesc=None, custom_env=None, live=False):
def check_run(command):
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
result = subprocess.run(command, check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
return result.returncode == 0
@ -67,21 +67,21 @@ def run_python(code, desc=None, errdesc=None):
return run(f'"{sys.executable}" -c "{code}"', desc, errdesc)
def run_pip(args, desc=None):
def run_pip(pkg, desc=None):
index_url_line = f' --index-url {index_url}' if index_url != '' else ''
return run(f'"{sys.executable}" -m pip {args} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}")
return run(f'"{sys.executable}" -m pip {pkg} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}")
def check_run_python(code):
return check_run(f'"{sys.executable}" -c "{code}"')
def git_clone(url, dir, name, commithash=None):
setup.clone(url, dir, commithash)
def git_clone(url, tgt, _name, commithash=None):
setup.clone(url, tgt, commithash)
def run_extension_installer(dir):
setup.run_extension_installer(dir)
def run_extension_installer(ext_dir):
setup.run_extension_installer(ext_dir)
if __name__ == "__main__":

View File

@ -28,7 +28,6 @@ def setup_logging():
pass
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s | %(levelname)s | %(pathname)s | %(message)s', filename='setup.log', filemode='a', encoding='utf-8', force=True)
try: # we may not have rich on the first run
from rich import print
from rich.theme import Theme
from rich.logging import RichHandler
from rich.console import Console
@ -44,7 +43,6 @@ def setup_logging():
rh = RichHandler(show_time=True, omit_repeated_times=False, show_level=True, show_path=False, markup=False, rich_tracebacks=True, log_time_format='%H:%M:%S-%f', level=logging.DEBUG if args.debug else logging.INFO, console=console)
log.addHandler(rh)
except:
pass
sh = logging.StreamHandler()
sh.setLevel(logging.DEBUG if args.debug else logging.INFO)
log.addHandler(sh)
@ -81,7 +79,7 @@ def installed(package):
def install(package):
def pip(args: str):
log.debug(f"Running pip: {args}")
result = subprocess.run(f'"{sys.executable}" -m pip {args}', shell=True, env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = subprocess.run(f'"{sys.executable}" -m pip {args}', shell=True, check=False, env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
txt = result.stdout.decode(encoding="utf8", errors="ignore")
if len(result.stderr) > 0:
txt = txt + '\n' + result.stderr.decode(encoding="utf8", errors="ignore")
@ -98,7 +96,7 @@ def install(package):
def git(args: str):
# log.debug(f"Running git: {args}")
git_cmd = os.environ.get('GIT', "git")
result = subprocess.run(f'"{git_cmd}" {args}', shell=True, env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = subprocess.run(f'"{git_cmd}" {args}', check=False, shell=True, env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
txt = result.stdout.decode(encoding="utf8", errors="ignore")
if len(result.stderr) > 0:
txt = txt + '\n' + result.stderr.decode(encoding="utf8", errors="ignore")
@ -153,9 +151,9 @@ def check_python():
# check torch version
def check_torch():
install(f'torch torchaudio torchvision --index-url https://download.pytorch.org/whl/cu118')
install('torch torchaudio torchvision --index-url https://download.pytorch.org/whl/cu118')
try:
import torch;
import torch
log.info(f'Torch {torch.__version__}')
if not torch.cuda.is_available():
log.warning("Torch repoorts CUDA not available")
@ -167,7 +165,7 @@ def check_torch():
elif torch.version.hip:
log.info(f'Torch backend: AMD ROCm HIP {torch.version.hip}')
else:
log.warning(f'Unknown Torch backend')
log.warning('Unknown Torch backend')
for device in [torch.cuda.device(i) for i in range(torch.cuda.device_count())]:
log.info(f'Torch detected GPU: {torch.cuda.get_device_name(device)} VRAM {round(torch.cuda.get_device_properties(device).total_memory / 1024 / 1024)} Arch {torch.cuda.get_device_capability(device)} Cores {torch.cuda.get_device_properties(device).multi_processor_count}')
except:
@ -187,7 +185,7 @@ def install_packages():
xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers')
install(f'--no-deps {xformers_package}')
except Exception as e:
log.error('Cannot install xformers package: {e}')
log.error(f'Cannot install xformers package: {e}')
# clone required repositories
@ -223,7 +221,7 @@ def run_extension_installer(extension_dir):
log.debug(f"Running extension installer: {path_installer}")
env = os.environ.copy()
env['PYTHONPATH'] = os.path.abspath(".")
result = subprocess.run(f'"{sys.executable}" "{path_installer}"', shell=True, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = subprocess.run(f'"{sys.executable}" "{path_installer}"', shell=True, env=env, check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode != 0:
txt = result.stdout.decode(encoding="utf8", errors="ignore")
if len(result.stderr) > 0:
@ -241,15 +239,14 @@ def install_extensions():
with open('config.json', "r", encoding="utf8") as file:
settings = json.load(file)
def list_extensions(dir):
def list_extensions(folder):
if settings.get('disable_all_extensions', 'none') != 'none':
log.debug(f'Disabled extensions: all')
log.debug('Disabled extensions: all')
return []
else:
disabled_extensions = set(settings.get('disabled_extensions', []))
if len(disabled_extensions) > 0:
log.debug(f'Disabled extensions: {disabled_extensions}')
return [x for x in os.listdir(dir) if x not in disabled_extensions and not x.startswith('.')]
return [x for x in os.listdir(folder) if x not in disabled_extensions and not x.startswith('.')]
extensions_builtin_dir = os.path.join(os.path.dirname(__file__), 'extensions-builtin')
extensions = list_extensions(extensions_builtin_dir)
@ -274,7 +271,7 @@ def install_extensions():
# initialize and optionally update submodules
def install_submodules():
log.info('Installing submodules')
git(f'submodule --quiet update --init --recursive')
git('submodule --quiet update --init --recursive')
if not args.noupdate:
log.info('Updating submodules')
submodules = git('submodule').splitlines()
@ -288,7 +285,7 @@ def install_requirements():
if args.skip_requirements:
return
log.info('Installing requirements')
f = open('requirements.txt', 'r')
with open('requirements.txt', 'r', encoding='utf8') as f:
lines = [line.strip() for line in f.readlines() if line.strip() != '']
for line in lines:
install(line)
@ -316,14 +313,14 @@ def set_environment():
def check_version():
ver = git('log -1 --pretty=format:"%h %ad"')
log.info(f'Version: {ver}')
hash = git('rev-parse HEAD')
commit = git('rev-parse HEAD')
try:
import requests
except ImportError:
return
logging.getLogger("urllib3").setLevel(logging.WARNING)
commits = requests.get('https://api.github.com/repos/vladmandic/automatic/branches/master').json()
if commits['commit']['sha'] != hash:
commits = requests.get('https://api.github.com/repos/vladmandic/automatic/branches/master', timeout=10).json()
if commits['commit']['sha'] != commit:
if args.upgrade:
update('.')
ver = git('log -1 --pretty=format:"%h %ad"')

View File

@ -2,13 +2,13 @@ import os
import time
import signal
import re
import logging
import warnings
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.gzip import GZipMiddleware
from setup import log # pylint: disable=E0611
from setup import log
import logging
logging.getLogger("xformers").addFilter(lambda record: 'A matching Triton is not available' not in record.getMessage())
from modules import paths, timer, errors
errors.install()
@ -17,6 +17,7 @@ startup_timer = timer.Timer()
import torch
import torchvision
import pytorch_lightning # pytorch_lightning should be imported after torch, but it re-enables warnings on import so import once to disable them
logging.getLogger("xformers").addFilter(lambda record: 'A matching Triton is not available' not in record.getMessage())
warnings.filterwarnings(action="ignore", category=DeprecationWarning, module="pytorch_lightning")
warnings.filterwarnings(action="ignore", category=UserWarning, module="torchvision")
startup_timer.record("torch")
@ -52,7 +53,6 @@ import modules.ui
from modules import modelloader
from modules.shared import cmd_opts, opts
import modules.hypernetworks.hypernetwork
startup_timer.record("libraries")
if cmd_opts.server_name:
@ -130,7 +130,7 @@ def load_model():
modules.sd_models.load_model()
except Exception as e:
errors.display(e, "loading stable diffusion model")
log.error(f"Stable diffusion model failed to load")
log.error("Stable diffusion model failed to load")
exit(1)
if shared.sd_model is None:
log.error("No stable diffusion model loaded")