zensical:chore - Apply Ruff fixes and lint code

Signed-off-by: pawamoy <dev@pawamoy.fr>
This commit is contained in:
Timothée Mazzucotelli
2025-12-09 14:22:47 +01:00
parent 308364bf91
commit 16662405f0
13 changed files with 251 additions and 328 deletions
+17 -20
View File
@@ -25,11 +25,14 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
import os, re, sys, tomllib # noqa: E401
import os
import re
import sys
from dataclasses import dataclass
from glob import glob
import tomllib
# ----------------------------------------------------------------------------
# Classes
# ----------------------------------------------------------------------------
@@ -48,8 +51,7 @@ class TypeError(ValueError):
@dataclass
class Message:
"""
Commit message.
"""Commit message.
This class represents a commit message with a scope, type, and description.
It provides methods to parse and validate commit messages according to our
@@ -59,9 +61,7 @@ class Message:
@classmethod
def parse(cls, message: str) -> "Message":
"""
Parse a commit message string into an object.
"""
"""Parse a commit message string into an object."""
match = re.match(r"^([^:]+):([^\s]+) - (.+)$", message)
if not match:
raise ValueError("Required format: <scope>:<type> - <description>")
@@ -71,9 +71,7 @@ class Message:
return cls(scope=scope, type=type, description=description)
def validate(self, scopes: dict[str, str]) -> None:
"""
Validate the commit message against the given scopes and types.
"""
"""Validate the commit message against the given scopes and types."""
if self.scope not in scopes:
raise ScopeError(f"Invalid scope: {self.scope}")
@@ -119,8 +117,7 @@ class Message:
def resolve(directory: str) -> dict[str, str] | None:
"""
Return commit scopes for a cargo project.
"""Return commit scopes for a cargo project.
This function checks, if the given directory contains a `Cargo.toml` file,
and if so, parses it to extract the workspace members. It then resolves the
@@ -129,7 +126,7 @@ def resolve(directory: str) -> dict[str, str] | None:
"""
path = os.path.join(directory, "Cargo.toml")
if not os.path.isfile(path):
return
return None
# Open and parse the Cargo.toml file
with open(path, "rb") as f:
@@ -155,6 +152,8 @@ def resolve(directory: str) -> dict[str, str] | None:
if package and "name" in package:
return {package["name"]: directory}
return None
# ----------------------------------------------------------------------------
# Constants
@@ -199,10 +198,8 @@ ANSI escape code to reset formatting.
# ----------------------------------------------------------------------------
def main():
"""
Commit message linter.
"""
def main() -> None:
"""Commit message linter."""
if len(sys.argv) < 2:
print("No commit message provided.")
sys.exit(1)
@@ -210,7 +207,7 @@ def main():
# Commit message might be passed as string, or in a file
commit = sys.argv[1]
if os.path.isfile(commit):
with open(sys.argv[1], "r") as f:
with open(sys.argv[1]) as f:
message = f.read().strip()
else:
message = commit.strip()
@@ -229,9 +226,9 @@ def main():
# If an error happened, print it
except ValueError as e:
print(f"{FG_RED}{RESET} {BG_RED} Error {RESET} {e}")
print("")
print()
print(" Commit rejected.")
print("")
print()
# Exit with error
return sys.exit(1)
+5 -4
View File
@@ -25,16 +25,17 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
import os, shutil, subprocess # noqa: E401
import os
import shutil
import subprocess
# ----------------------------------------------------------------------------
# Program
# ----------------------------------------------------------------------------
def main():
"""
Set up development environment.
def main() -> None:
"""Set up development environment.
This script clones the Zensical UI repository, and symbolically links the
build artifacts into the Python package directory for development use.
+4 -5
View File
@@ -25,17 +25,16 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
import os, subprocess # noqa: E401
import os
import subprocess
# ----------------------------------------------------------------------------
# Program
# ----------------------------------------------------------------------------
def main():
"""
Prepare production build.
"""
def main() -> None:
"""Prepare production build."""
os.makedirs("tmp", exist_ok=True)
# Clone UI repository into tmp directory