mirror of
https://github.com/zensical/zensical.git
synced 2026-05-04 01:50:48 +00:00
zensical:chore - Apply Ruff fixes and lint code
Signed-off-by: pawamoy <dev@pawamoy.fr>
This commit is contained in:
Vendored
+17
-20
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user