mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-12 17:27:51 -06:00
Update readme with instruction for developing.
Change DiagnosticGenerator -> Linter since this is much easier to understand.
This commit is contained in:
parent
8e027c4af9
commit
e83ed933e2
10 changed files with 39 additions and 19 deletions
|
@ -8,4 +8,26 @@ From the Cura root folder.
|
||||||
```python3 printer-linter/src/terminal.py "flashforge_dreamer_nx.def.json" "flashforge_base.def.json" --fix --format```
|
```python3 printer-linter/src/terminal.py "flashforge_dreamer_nx.def.json" "flashforge_base.def.json" --fix --format```
|
||||||
|
|
||||||
## Developing
|
## Developing
|
||||||
|
### Printer Linter Rules
|
||||||
|
Inside ```.printer-linter``` you can find a list of rules. These are seperated into roughly three categories.
|
||||||
|
|
||||||
|
1. Checks
|
||||||
|
1. These rules are about checking if a file meets some requirements that can't be fixed by replacing its content.
|
||||||
|
2. An example of a check is ```diagnostic-mesh-file-extension``` this checks if a mesh file extension is acceptable.
|
||||||
|
2. Format
|
||||||
|
1. These rules are purely about how a file is structured, not content.
|
||||||
|
2. An example of a format rule is ```format-definition-bracket-newline``` This rule says that when assigning a dict value the bracket should go on a new line.
|
||||||
|
3. Fixes
|
||||||
|
1. These are about the content of the file.
|
||||||
|
2. An example of a fix is ```diagnostic-definition-redundant-override``` This removes settings that have already been defined by a parent definition
|
||||||
|
|
||||||
|
### Linters
|
||||||
|
Linters find issues within a file. There are separate linters for each type of file. The linter that is used is decided by the create function in factory.py. All linters implement the abstract class Linter.
|
||||||
|
|
||||||
|
A Linter class returns an iterator of Diagnostics, each diagnostic is an issue with the file. The diagnostics can also contain suggested fixes.
|
||||||
|
|
||||||
|
### Formatters
|
||||||
|
Formatters load a file reformat it and write it to disk. There are separate formatters for each file type. All formatters implement the abstract class Formatter.
|
||||||
|
|
||||||
|
Formatters should format based on the Format rules in .printer-linter
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from .diagnostic import Diagnostic
|
from .diagnostic import Diagnostic
|
||||||
from .factory import create
|
from .factory import getLinter
|
||||||
|
|
||||||
__all__ = ["Diagnostic", "create"]
|
__all__ = ["Diagnostic", "getLinter"]
|
||||||
|
|
|
@ -3,12 +3,12 @@ from typing import Optional
|
||||||
|
|
||||||
from .linters.profile import Profile
|
from .linters.profile import Profile
|
||||||
from .linters.defintion import Definition
|
from .linters.defintion import Definition
|
||||||
from .linters.diagnostic_generator import DiagnosticGenerator
|
from .linters.linter import Linter
|
||||||
from .linters.meshes import Meshes
|
from .linters.meshes import Meshes
|
||||||
|
|
||||||
|
|
||||||
def create(file: Path, settings: dict) -> Optional[DiagnosticGenerator]:
|
def getLinter(file: Path, settings: dict) -> Optional[Linter]:
|
||||||
""" Returns a DiagnosticGenerator depending on the file format """
|
""" Returns a Linter depending on the file format """
|
||||||
if not file.exists():
|
if not file.exists():
|
||||||
return None
|
return None
|
||||||
elif ".inst" in file.suffixes and ".cfg" in file.suffixes:
|
elif ".inst" in file.suffixes and ".cfg" in file.suffixes:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from .profile import Profile
|
from .profile import Profile
|
||||||
from .meshes import Meshes
|
from .meshes import Meshes
|
||||||
from .diagnostic_generator import DiagnosticGenerator
|
from .linter import Linter
|
||||||
from .defintion import Definition
|
from .defintion import Definition
|
||||||
|
|
||||||
__all__ = ["Profile", "Meshes", "DiagnosticGenerator", "Definition"]
|
__all__ = ["Profile", "Meshes", "Linter", "Definition"]
|
|
@ -4,11 +4,11 @@ from pathlib import Path
|
||||||
from typing import Iterator
|
from typing import Iterator
|
||||||
|
|
||||||
from ..diagnostic import Diagnostic
|
from ..diagnostic import Diagnostic
|
||||||
from .diagnostic_generator import DiagnosticGenerator
|
from .linter import Linter
|
||||||
from ..replacement import Replacement
|
from ..replacement import Replacement
|
||||||
|
|
||||||
|
|
||||||
class Definition(DiagnosticGenerator):
|
class Definition(Linter):
|
||||||
""" Finds issues in definition files, such as overriding default parameters """
|
""" Finds issues in definition files, such as overriding default parameters """
|
||||||
def __init__(self, file: Path, settings: dict) -> None:
|
def __init__(self, file: Path, settings: dict) -> None:
|
||||||
super().__init__(file, settings)
|
super().__init__(file, settings)
|
||||||
|
|
|
@ -5,7 +5,7 @@ from typing import Iterator
|
||||||
from ..diagnostic import Diagnostic
|
from ..diagnostic import Diagnostic
|
||||||
|
|
||||||
|
|
||||||
class DiagnosticGenerator(ABC):
|
class Linter(ABC):
|
||||||
def __init__(self, file: Path, settings: dict) -> None:
|
def __init__(self, file: Path, settings: dict) -> None:
|
||||||
""" Yields Diagnostics for file, these are issues with the file such as bad text format or too large file size.
|
""" Yields Diagnostics for file, these are issues with the file such as bad text format or too large file size.
|
||||||
|
|
|
@ -2,10 +2,10 @@ from pathlib import Path
|
||||||
from typing import Iterator
|
from typing import Iterator
|
||||||
|
|
||||||
from ..diagnostic import Diagnostic
|
from ..diagnostic import Diagnostic
|
||||||
from .diagnostic_generator import DiagnosticGenerator
|
from .linter import Linter
|
||||||
|
|
||||||
|
|
||||||
class Meshes(DiagnosticGenerator):
|
class Meshes(Linter):
|
||||||
def __init__(self, file: Path, settings: dict) -> None:
|
def __init__(self, file: Path, settings: dict) -> None:
|
||||||
""" Finds issues in model files, such as incorrect file format or too large size """
|
""" Finds issues in model files, such as incorrect file format or too large size """
|
||||||
super().__init__(file, settings)
|
super().__init__(file, settings)
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from typing import Iterator
|
from typing import Iterator
|
||||||
|
|
||||||
from ..diagnostic import Diagnostic
|
from ..diagnostic import Diagnostic
|
||||||
from .diagnostic_generator import DiagnosticGenerator
|
from .linter import Linter
|
||||||
|
|
||||||
|
|
||||||
class Profile(DiagnosticGenerator):
|
class Profile(Linter):
|
||||||
def check(self) -> Iterator[Diagnostic]:
|
def check(self) -> Iterator[Diagnostic]:
|
||||||
yield
|
yield
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class Replacement:
|
class Replacement:
|
||||||
def __init__(self, file: Path, offset: int, length: int, replacement_text: str):
|
def __init__(self, file: Path, offset: int, length: int, replacement_text: str):
|
||||||
""" Replacement text for file between offset and offset+length.
|
""" Replacement text for file between offset and offset+length.
|
||||||
|
|
|
@ -65,13 +65,12 @@ def main() -> None:
|
||||||
|
|
||||||
def diagnoseIssuesWithFile(file: Path, settings: dict) -> List[Diagnostic]:
|
def diagnoseIssuesWithFile(file: Path, settings: dict) -> List[Diagnostic]:
|
||||||
""" For file, runs all diagnostic checks in settings and returns a list of diagnostics """
|
""" For file, runs all diagnostic checks in settings and returns a list of diagnostics """
|
||||||
# Find correct diagnostic generator for file
|
linter = factory.getLinter(file, settings)
|
||||||
diagnostic_generator = factory.create(file, settings)
|
|
||||||
|
|
||||||
if not diagnostic_generator:
|
if not linter:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
return list(filter(lambda d: d is not None, diagnostic_generator.check()))
|
return list(filter(lambda d: d is not None, linter.check()))
|
||||||
|
|
||||||
|
|
||||||
def applyFixesToFile(file, settings, full_body_check) -> None:
|
def applyFixesToFile(file, settings, full_body_check) -> None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue