mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-11-02 20:52:20 -07:00
printer-linter works of definitions, profiles and meshes;
It has various diagnostic checks. With possible suggestions for fixes.
It should also be able to fix certain diagnostic issues and it can be used
to format the files according to code-style.
It can output the diagnostics in a yaml file, which can then be used to comment
on PR's with suggestions to the author. Future PR.
The settings for the diagnostics and checks are defined in `.printer-linter`
and are very self explanatory.
```
checks:
diagnostic-mesh-file-extension: true
diagnostic-mesh-file-size: true
diagnostic-definition-redundant-override: true
fixes:
diagnostic-definition-redundant-override: true
format:
format-definition-bracket-newline: false
format-definition-paired-coordinate-array: true
format-definition-sort-keys: true
format-definition-indent: 4
format-profile-space-around-delimiters: true
format-profile-sort-keys: true
diagnostic-mesh-file-size: 1200000
```
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
from .diagnostic import Diagnostic
|
|
|
|
|
|
class Meshes:
|
|
def __init__(self, file, settings):
|
|
self._settings = settings
|
|
self._file = file
|
|
self._max_file_size = self._settings.get("diagnostic-mesh-file-size", 1e6)
|
|
|
|
def check(self):
|
|
if self._settings["checks"].get("diagnostic-mesh-file-extension", False):
|
|
for check in self.checkFileFormat():
|
|
yield check
|
|
|
|
if self._settings["checks"].get("diagnostic-mesh-file-size", False):
|
|
for check in self.checkFileSize():
|
|
yield check
|
|
|
|
yield
|
|
|
|
def checkFileFormat(self):
|
|
if self._file.suffix.lower() not in (".3mf", ".obj", ".stl"):
|
|
yield Diagnostic("diagnostic-mesh-file-extension",
|
|
f"Extension **{self._file.suffix}** not supported, use **3mf**, **obj** or **stl**",
|
|
self._file)
|
|
yield
|
|
|
|
def checkFileSize(self):
|
|
|
|
if self._file.stat().st_size > self._max_file_size:
|
|
yield Diagnostic("diagnostic-mesh-file-size",
|
|
f"Mesh file with a size **{self._file.stat().st_size}** is bigger then allowed maximum of **{self._max_file_size}**",
|
|
self._file)
|
|
yield
|