From b401ecee0221324d9effd94a621b2baa167f014c Mon Sep 17 00:00:00 2001 From: jellespijker Date: Fri, 22 Sep 2023 01:29:22 +0200 Subject: [PATCH] Add MacOS directory naming linting A new Linter subclass - 'Directory' has been created and integrated into the linting process to handle directory naming conventions, specifically for MacOS. MacOS has issues when signing and notarizing directories with '.' in their names. The new class will trigger an 'Error' level diagnostic if this convention is violated. The linter will become a required check with this update, as its new check configuration was added to '.printer-linter'. The version number in 'pyproject.toml' was also incremented to reflect these changes. Contributes to CURA-11014 --- .printer-linter | 1 + printer-linter/pyproject.toml | 2 +- printer-linter/src/printerlinter/factory.py | 13 ++++---- .../src/printerlinter/linters/directory.py | 32 +++++++++++++++++++ printer-linter/src/terminal.py | 10 ++++-- 5 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 printer-linter/src/printerlinter/linters/directory.py diff --git a/.printer-linter b/.printer-linter index 2ead01ffb1..3a42a5c033 100644 --- a/.printer-linter +++ b/.printer-linter @@ -2,6 +2,7 @@ checks: diagnostic-mesh-file-extension: true diagnostic-mesh-file-size: true diagnostic-definition-redundant-override: true + diagnostic-resources-macos-app-directory-name: true fixes: diagnostic-definition-redundant-override: true format: diff --git a/printer-linter/pyproject.toml b/printer-linter/pyproject.toml index 74c6531c87..c346dc0496 100644 --- a/printer-linter/pyproject.toml +++ b/printer-linter/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "printerlinter" description = "Cura UltiMaker printer linting tool" -version = "0.1.0" +version = "0.1.1" authors = [ { name = "UltiMaker", email = "cura@ultimaker.com" } ] diff --git a/printer-linter/src/printerlinter/factory.py b/printer-linter/src/printerlinter/factory.py index d27f82244b..4473fb9a4e 100644 --- a/printer-linter/src/printerlinter/factory.py +++ b/printer-linter/src/printerlinter/factory.py @@ -1,26 +1,27 @@ from pathlib import Path -from typing import Optional +from typing import Optional, List from .linters.profile import Profile from .linters.defintion import Definition from .linters.linter import Linter from .linters.meshes import Meshes +from .linters.directory import Directory -def getLinter(file: Path, settings: dict) -> Optional[Linter]: +def getLinter(file: Path, settings: dict) -> Optional[List[Linter]]: """ Returns a Linter depending on the file format """ if not file.exists(): return None if ".inst" in file.suffixes and ".cfg" in file.suffixes: - return Profile(file, settings) + return [Directory(file, settings), Profile(file, settings)] if ".def" in file.suffixes and ".json" in file.suffixes: if file.stem in ("fdmprinter.def", "fdmextruder.def"): return None - return Definition(file, settings) + return [Directory(file, settings), Definition(file, settings)] if file.parent.stem == "meshes": - return Meshes(file, settings) + return [Meshes(file, settings)] - return None + return [Directory(file, settings)] diff --git a/printer-linter/src/printerlinter/linters/directory.py b/printer-linter/src/printerlinter/linters/directory.py new file mode 100644 index 0000000000..1e81be4ded --- /dev/null +++ b/printer-linter/src/printerlinter/linters/directory.py @@ -0,0 +1,32 @@ +from pathlib import Path +from typing import Iterator + +from ..diagnostic import Diagnostic +from .linter import Linter + + +class Directory(Linter): + def __init__(self, file: Path, settings: dict) -> None: + """ Finds issues in the parent directory""" + super().__init__(file, settings) + + def check(self) -> Iterator[Diagnostic]: + if self._settings["checks"].get("diagnostic-resources-macos-app-directory-name", False): + for check in self.checkForDotInDirName(): + yield check + + yield + + def checkForDotInDirName(self) -> Iterator[Diagnostic]: + """ Check if there is a dot in the directory name, MacOS has trouble signing and notarizing otherwise """ + if any("." in p for p in self._file.parent.parts): + print("bghkgh") + yield Diagnostic( + file = self._file, + diagnostic_name = "diagnostic-resources-macos-app-directory-name", + message = f"Directory name containing a `.` not allowed {self._file.suffix}, rename directory containing this file e.q: `_`", + level = "Error", + offset = 1 + ) + yield + diff --git a/printer-linter/src/terminal.py b/printer-linter/src/terminal.py index 71103a0db2..fb5ee36bd0 100644 --- a/printer-linter/src/terminal.py +++ b/printer-linter/src/terminal.py @@ -71,12 +71,16 @@ def main() -> None: def diagnoseIssuesWithFile(file: Path, settings: dict) -> List[Diagnostic]: """ For file, runs all diagnostic checks in settings and returns a list of diagnostics """ - linter = factory.getLinter(file, settings) + linters = factory.getLinter(file, settings) - if not linter: + if not linters: return [] - return list(filter(lambda d: d is not None, linter.check())) + linter_results = [] + for linter in linters: + linter_results.extend(list(filter(lambda d: d is not None, linter.check()))) + + return linter_results def applyFixesToFile(file, settings, full_body_check) -> None: