diff --git a/.github/workflows/on_pull_request.yaml b/.github/workflows/on_pull_request.yaml index 6cb1005b0..c6111da58 100644 --- a/.github/workflows/on_pull_request.yaml +++ b/.github/workflows/on_pull_request.yaml @@ -1,35 +1,27 @@ -# See https://github.com/actions/starter-workflows/blob/1067f16ad8a1eac328834e4b0ae24f7d206f810d/ci/pylint.yml for original reference file name: Run Linting/Formatting on Pull Requests on: - push - pull_request - # See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpull_requestpull_request_targetbranchesbranches-ignore for syntax docs - # if you want to filter out branches, delete the `- pull_request` and uncomment these lines : - # pull_request: - # branches: - # - master - # branches-ignore: - # - development jobs: lint: runs-on: ubuntu-latest steps: - - name: Checkout Code + - name: checkout-code uses: actions/checkout@v3 - - name: Set up Python + - name: setup-python uses: actions/setup-python@v4 with: python-version: 3.10.6 cache: pip cache-dependency-path: requirements.txt - - name: Test Startup - run: | - export COMMANDLINE_ARGS="--debug --test" - python launch.py - - name: Linting + - name: run-lint run: | python -m pip install --upgrade pip pip install pylint pylint $(git ls-files '*.py') + - name: test-startup + run: | + export COMMANDLINE_ARGS="--debug --test" + python launch.py diff --git a/.github/workflows/run_tests.yaml b/.github/workflows/run_tests.yaml deleted file mode 100644 index 18b90660a..000000000 --- a/.github/workflows/run_tests.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: Run basic features tests on CPU with empty SD model - -on: - - push - - pull_request - -jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Checkout Code - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.10.6 - cache: pip - cache-dependency-path: requirements.txt - - name: Run tests - run: python launch.py diff --git a/modules/styles.py b/modules/styles.py index 2ae580355..59169294a 100644 --- a/modules/styles.py +++ b/modules/styles.py @@ -4,8 +4,8 @@ import csv import os import os.path import typing -import tempfile -import shutil +from installer import log + if typing.TYPE_CHECKING: # Only import this when code is being type-checked, it doesn't have any effect at runtime @@ -24,14 +24,12 @@ def merge_prompts(style_prompt: str, prompt: str) -> str: else: parts = filter(None, (prompt.strip(), style_prompt.strip())) res = ", ".join(parts) - return res def apply_styles_to_prompt(prompt, styles): for style in styles: prompt = merge_prompts(style, prompt) - return prompt @@ -40,15 +38,12 @@ class StyleDatabase: self.no_style = PromptStyle("None", "", "") self.styles = {} self.path = path - self.reload() def reload(self): self.styles.clear() - if not os.path.exists(self.path): self.save_styles(self.path) - with open(self.path, "r", encoding="utf-8-sig", newline='') as file: reader = csv.DictReader(file, skipinitialspace=True) for row in reader: @@ -58,6 +53,7 @@ class StyleDatabase: self.styles[row["name"]] = PromptStyle(row["name"], prompt, negative_prompt) except Exception: pass + log.debug(f'Loaded styles: {self.path} {len(self.styles.keys())}') def get_style_prompts(self, styles): return [self.styles.get(x, self.no_style).prompt for x in styles] @@ -72,15 +68,11 @@ class StyleDatabase: return apply_styles_to_prompt(prompt, [self.styles.get(x, self.no_style).negative_prompt for x in styles]) def save_styles(self, path: str) -> None: - # Write to temporary file first, so we don't nuke the file if something goes wrong basedir = os.path.dirname(path) if basedir is not None and len(basedir) > 0: os.makedirs(basedir, exist_ok=True) - fd, temp_path = tempfile.mkstemp(".csv") - with os.fdopen(fd, "w", encoding="utf-8-sig", newline='') as file: - # _fields is actually part of the public API: typing.NamedTuple is a replacement for collections.NamedTuple, - # and collections.NamedTuple has explicit documentation for accessing _fields. Same goes for _asdict() + with os.fdopen(path, "w", encoding="utf-8-sig", newline='') as file: writer = csv.DictWriter(file, fieldnames=PromptStyle._fields) writer.writeheader() writer.writerows(style._asdict() for k, style in self.styles.items()) - shutil.move(temp_path, path) + log.debug(f'Saved styles: {path} {len(self.styles.keys())}')