* Grid: wrong path to static folder (for fonts) * FileQueue: allow symlinks
This commit is contained in:
@@ -4,6 +4,12 @@
|
||||
|
||||
## v0.0
|
||||
|
||||
## v0.0.3 (2025-01-23): bugfix #6
|
||||
|
||||
- fix bugs (issue #6)
|
||||
- Grid: wrong path to `static` folder (for fonts)
|
||||
- FileQueue: allow symlinks
|
||||
|
||||
## v0.0.2 (2025-01-22): more wiki
|
||||
|
||||
- init main README
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "confylab-pack",
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.3",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"watch": "tsc-watch -p tsconfig.json --onSuccess 'tsc-alias -p tsconfig.json -r build/replacers.js/mock.js'",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
[project]
|
||||
name = "comfylab-pack"
|
||||
description = "A collection of carefully experimented nodes, to improve your Comfy UX."
|
||||
version = "0.0.2"
|
||||
version = "0.0.3"
|
||||
authors = [{ name = "bugltd" }]
|
||||
license = {file = "LICENSE"}
|
||||
readme = "README.md"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from typing import Any
|
||||
from pathlib import Path
|
||||
import glob
|
||||
from PIL import Image
|
||||
|
||||
|
||||
@@ -96,11 +97,12 @@ class FileQueue:
|
||||
def scan_folder(
|
||||
self, folder: str, pattern: str, recursive: bool
|
||||
) -> tuple[Path, list[Path], int]:
|
||||
self.root = Path(folder)
|
||||
self.files = []
|
||||
self.total = -1
|
||||
|
||||
if not self.root.exists():
|
||||
# do not resolve, to ensure relative path is accurate
|
||||
self.root = Path(folder)
|
||||
if not self.root.exists(): # follows symlinks
|
||||
raise Exception("Path '{}' does not exist".format(self.root))
|
||||
if not self.root.is_dir():
|
||||
raise Exception("'{}' is not a directory".format(self.root))
|
||||
@@ -108,8 +110,17 @@ class FileQueue:
|
||||
patterns = pattern.split(',')
|
||||
self.files = []
|
||||
for p in patterns:
|
||||
it = self.root.rglob(p.strip()) if recursive else self.root.glob(p.strip())
|
||||
self.files += [file for file in it if file.is_file()]
|
||||
# it = self.root.rglob(p.strip()) if recursive else self.root.glob(p.strip())
|
||||
# self.files += [file for file in it if file.is_file()]
|
||||
|
||||
# TODO: go back to Path().glob() with recurse_symlinks=True when Python version is > 3.13
|
||||
# in the meantime, we use glob as it follows links by default
|
||||
glob_pattern = self.root / '**' / p if recursive else self.root / p
|
||||
matches = glob.glob(str(glob_pattern), recursive=recursive)
|
||||
for match in matches:
|
||||
file = Path(match)
|
||||
if file.is_file():
|
||||
self.files.append(file)
|
||||
# remove duplicates
|
||||
self.files = list(set(self.files))
|
||||
# list files in current folder first
|
||||
@@ -134,7 +145,8 @@ class FileQueue:
|
||||
return {
|
||||
'result': (
|
||||
str(file.name) if with_extension else file.stem,
|
||||
str(file.resolve()),
|
||||
# do not resolve, to ensure relative path is accurate
|
||||
str(file),
|
||||
str(file.relative_to(self.root)),
|
||||
index + 1,
|
||||
self.total,
|
||||
|
||||
@@ -6,7 +6,7 @@ from dataclasses import asdict
|
||||
|
||||
from .plot_data import PlotConfigGridData, PlotConfigHFData, PlotVars
|
||||
|
||||
STATIC_DIR = Path(__file__).parent.parent.parent / 'static'
|
||||
STATIC_DIR = (Path(__file__).parent.parent.parent.parent / 'static').resolve()
|
||||
|
||||
|
||||
class Grid:
|
||||
@@ -133,13 +133,16 @@ class Grid:
|
||||
return image
|
||||
|
||||
def _load_font(self, font_name: str, font_size: int) -> ImageFont:
|
||||
if not Path(font_name).is_absolute():
|
||||
font = ImageFont.truetype(
|
||||
str(STATIC_DIR / font_name),
|
||||
size=font_size,
|
||||
)
|
||||
else:
|
||||
font = ImageFont.truetype(str(Path(font_name)), size=font_size)
|
||||
full_path = (
|
||||
STATIC_DIR / font_name
|
||||
if not Path(font_name).is_absolute()
|
||||
else Path(font_name)
|
||||
)
|
||||
try:
|
||||
full_path = full_path.resolve(strict=True)
|
||||
except:
|
||||
raise Exception("TTF font not found: '{}'".format(full_path))
|
||||
font = ImageFont.truetype(str(full_path), size=font_size)
|
||||
return font
|
||||
|
||||
def _normalize_headers(self, headers: list[str], wrap: int) -> list[str]:
|
||||
|
||||
Reference in New Issue
Block a user