mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-15 20:35:59 +08:00
Move linters into seperate module.
Give linters an abstract type to inherit, since they share an interface. Add empty README
This commit is contained in:
parent
91daf89c2d
commit
a470f02373
0
printer-linter/README.md
Normal file
0
printer-linter/README.md
Normal file
@ -1,7 +1,4 @@
|
||||
from .defintion import Definition
|
||||
from .diagnostic import Diagnostic
|
||||
from .factory import create
|
||||
from .meshes import Meshes
|
||||
from .profile import Profile
|
||||
|
||||
__all__ = ["Profile", "Definition", "Meshes", "Diagnostic", "create"]
|
||||
__all__ = ["Diagnostic", "create"]
|
||||
|
@ -1,9 +1,12 @@
|
||||
from .profile import Profile
|
||||
from .defintion import Definition
|
||||
from .meshes import Meshes
|
||||
from typing import Optional
|
||||
|
||||
from .linters.profile import Profile
|
||||
from .linters.defintion import Definition
|
||||
from .linters.diagnostic_generator import DiagnosticGenerator
|
||||
from .linters.meshes import Meshes
|
||||
|
||||
|
||||
def create(file, settings):
|
||||
def create(file, settings) -> Optional[DiagnosticGenerator]:
|
||||
if not file.exists():
|
||||
return None
|
||||
if ".inst" in file.suffixes and ".cfg" in file.suffixes:
|
||||
|
6
printer-linter/src/printerlinter/linters/__init__.py
Normal file
6
printer-linter/src/printerlinter/linters/__init__.py
Normal file
@ -0,0 +1,6 @@
|
||||
from .profile import Profile
|
||||
from .meshes import Meshes
|
||||
from .diagnostic_generator import DiagnosticGenerator
|
||||
from .defintion import Definition
|
||||
|
||||
__all__ = ["Profile", "Meshes", "DiagnosticGenerator", "Definition"]
|
@ -1,15 +1,16 @@
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Iterator
|
||||
|
||||
from .diagnostic import Diagnostic
|
||||
from .replacement import Replacement
|
||||
from ..diagnostic import Diagnostic
|
||||
from .diagnostic_generator import DiagnosticGenerator
|
||||
from ..replacement import Replacement
|
||||
|
||||
|
||||
class Definition:
|
||||
class Definition(DiagnosticGenerator):
|
||||
def __init__(self, file, settings) -> None:
|
||||
self._settings = settings
|
||||
self._file = file
|
||||
super().__init__(file, settings)
|
||||
self._defs = {}
|
||||
self._getDefs(file)
|
||||
|
||||
@ -20,7 +21,7 @@ class Definition:
|
||||
self._getSetting(k, v, settings)
|
||||
self._defs["fdmprinter"] = {"overrides": settings}
|
||||
|
||||
def check(self) -> None:
|
||||
def check(self) -> Iterator[Diagnostic]:
|
||||
if self._settings["checks"].get("diagnostic-definition-redundant-override", False):
|
||||
for check in self.checkRedefineOverride():
|
||||
yield check
|
@ -0,0 +1,14 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Iterator
|
||||
|
||||
from ..diagnostic import Diagnostic
|
||||
|
||||
|
||||
class DiagnosticGenerator(ABC):
|
||||
def __init__(self, file, settings) -> None:
|
||||
self._settings = settings
|
||||
self._file = file
|
||||
|
||||
@abstractmethod
|
||||
def check(self) -> Iterator[Diagnostic]:
|
||||
pass
|
@ -1,13 +1,14 @@
|
||||
from .diagnostic import Diagnostic
|
||||
from typing import Iterator
|
||||
|
||||
from ..diagnostic import Diagnostic
|
||||
|
||||
|
||||
class Meshes:
|
||||
def __init__(self, file, settings) -> None:
|
||||
self._settings = settings
|
||||
self._file = file
|
||||
super().__init__(file, settings)
|
||||
self._max_file_size = self._settings.get("diagnostic-mesh-file-size", 1e6)
|
||||
|
||||
def check(self) -> None:
|
||||
def check(self) -> Iterator[Diagnostic]:
|
||||
if self._settings["checks"].get("diagnostic-mesh-file-extension", False):
|
||||
for check in self.checkFileFormat():
|
||||
yield check
|
9
printer-linter/src/printerlinter/linters/profile.py
Normal file
9
printer-linter/src/printerlinter/linters/profile.py
Normal file
@ -0,0 +1,9 @@
|
||||
from typing import Iterator
|
||||
|
||||
from ..diagnostic import Diagnostic
|
||||
from .diagnostic_generator import DiagnosticGenerator
|
||||
|
||||
|
||||
class Profile(DiagnosticGenerator):
|
||||
def check(self) -> Iterator[Diagnostic]:
|
||||
yield
|
@ -1,7 +0,0 @@
|
||||
class Profile:
|
||||
def __init__(self, file, settings) -> None:
|
||||
self._settings = settings
|
||||
self._file = file
|
||||
|
||||
def check(self) -> None:
|
||||
yield
|
Loading…
x
Reference in New Issue
Block a user