This commit is contained in:
Elliot Simpson 2025-07-31 04:44:32 +00:00 committed by GitHub
commit faacc2319d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 28 additions and 36 deletions

View file

@ -16,7 +16,7 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# ruff version should match the one in pyproject.toml
rev: v0.12.2
rev: v0.12.7
hooks:
- id: ruff-check
args: [--fix, --exit-non-zero-on-fix]

View file

@ -37,7 +37,7 @@ from pelican.writers import Writer
try:
__version__ = importlib.metadata.version("pelican")
except Exception:
except importlib.metadata.PackageNotFoundError:
__version__ = "unknown"
DEFAULT_CONFIG_NAME = "pelicanconf.py"
@ -78,11 +78,10 @@ class Pelican:
try:
plugin.register()
self.plugins.append(plugin)
except Exception as e:
logger.error(
"Cannot register plugin `%s`\n%s",
except Exception:
logger.exception(
"Cannot register plugin `%s`",
name,
e,
stacklevel=2,
)
if self.settings.get("DEBUG", False):
@ -258,7 +257,7 @@ class PrintSettings(argparse.Action):
try:
instance, settings = get_instance(namespace)
except Exception as e:
logger.critical("%s: %s", e.__class__.__name__, e)
logger.critical("%s", e.__class__.__name__, exc_info=True)
console.print_exception()
sys.exit(getattr(e, "exitcode", 1))
@ -621,7 +620,8 @@ def listen(server, port, output, excqueue=None):
except Exception as e:
if excqueue is not None:
excqueue.put(traceback.format_exception_only(type(e), e)[-1])
return
else:
logging.exception("Listening aborted unexpectedly.")
except KeyboardInterrupt:
httpd.socket.close()
@ -680,7 +680,7 @@ def main(argv=None):
except KeyboardInterrupt:
logger.warning("Keyboard interrupt received. Exiting.")
except Exception as e:
logger.critical("%s: %s", e.__class__.__name__, e)
logger.critical("%s: %s", e.__class__.__name__, e, exc_info=True)
if args.verbosity == logging.DEBUG:
console.print_exception()

View file

@ -681,11 +681,10 @@ class ArticlesGenerator(CachingGenerator):
context_signal=signals.article_generator_context,
context_sender=self,
)
except Exception as e:
logger.error(
"Could not process %s\n%s",
except Exception:
logger.exception(
"Could not process %s",
f,
e,
exc_info=self.settings.get("DEBUG", False),
)
self._add_failed_source_path(f)
@ -896,11 +895,10 @@ class PagesGenerator(CachingGenerator):
context_signal=signals.page_generator_context,
context_sender=self,
)
except Exception as e:
logger.error(
"Could not process %s\n%s",
except Exception:
logger.exception(
"Could not process %s",
f,
e,
exc_info=self.settings.get("DEBUG", False),
)
self._add_failed_source_path(f)

View file

@ -241,7 +241,7 @@ def install(path, v=False, u=False):
f"or directory in `{theme_path}':\n{e!s}",
die=False,
)
except Exception as e:
except OSError as e:
err(f"Cannot copy `{path}' to `{theme_path}':\n{e!s}")
@ -262,7 +262,7 @@ def symlink(path, v=False):
print(f"Linking `{path}' to `{theme_path}' ...")
try:
os.symlink(path, theme_path)
except Exception as e:
except OSError as e:
err(f"Cannot link `{path}' to `{theme_path}':\n{e!s}")

View file

@ -378,8 +378,8 @@ def clean_output_dir(path: str, retention: Iterable[str]) -> None:
if not os.path.isdir(path):
try:
os.remove(path)
except Exception as e:
logger.error("Unable to delete file %s; %s", path, e)
except Exception:
logger.exception("Unable to delete file %s", path)
return
# remove existing content from output folder unless in retention list
@ -393,14 +393,14 @@ def clean_output_dir(path: str, retention: Iterable[str]) -> None:
try:
shutil.rmtree(file)
logger.debug("Deleted directory %s", file)
except Exception as e:
logger.error("Unable to delete directory %s; %s", file, e)
except Exception:
logger.exception("Unable to delete directory %s", file)
elif os.path.isfile(file) or os.path.islink(file):
try:
os.remove(file)
logger.debug("Deleted file/link %s", file)
except Exception as e:
logger.error("Unable to delete file %s; %s", file, e)
except Exception:
logger.exception("Unable to delete file %s", file)
else:
logger.error("Unable to delete %s, file type unknown", file)
@ -764,7 +764,7 @@ def order_content(
try:
content_list.sort(key=order_by)
except Exception:
logger.error("Error sorting with function %s", order_by)
logger.exception("Error sorting with function %s", order_by)
elif isinstance(order_by, str):
if order_by.startswith("reversed-"):
order_reversed = True

View file

@ -161,10 +161,7 @@ class Writer:
if path:
complete_path = sanitised_join(self.output_path, path)
try:
os.makedirs(os.path.dirname(complete_path))
except Exception:
pass
os.makedirs(os.path.dirname(complete_path), exist_ok=True)
with self._open_w(complete_path, "utf-8", override_output) as fp:
feed.write(fp, "utf-8")
@ -215,10 +212,7 @@ class Writer:
output = template.render(localcontext)
path = sanitised_join(output_path, name)
try:
os.makedirs(os.path.dirname(path))
except Exception:
pass
os.makedirs(os.path.dirname(path), exist_ok=True)
with self._open_w(path, "utf-8", override=override) as f:
f.write(output)

View file

@ -96,7 +96,7 @@ dev = [
"tox>=4.11.3",
"invoke>=2.2.0",
# ruff version should match the one in .pre-commit-config.yaml
"ruff==0.12.2",
"ruff==0.12.7",
"tomli>=2.0.1; python_version < \"3.11\"",
]
@ -127,7 +127,7 @@ select = [
"A", # flake8-builtins
"ARG", # flake8-unused-arguments
"B", # flake8-bugbear
# TODO: "BLE", # flake8-blind-except
"BLE", # flake8-blind-except
# TODO: Do I want "COM", # flake8-commas
"C4", # flake8-comprehensions
# TODO: "DJ", # flake8-django