Browse Source

Create a proper Pyhton packages for printer-linter

Such that it can be downloaded, installed and used locally and on other
repo's actions etc
jspijker 2 years ago
parent
commit
0c7807e0cd

+ 17 - 0
printer-linter/pyproject.toml

@@ -0,0 +1,17 @@
+[project]
+name = "printerlinter"
+description = "Cura UltiMaker printer linting tool"
+version = "0.1.0"
+authors = [
+    { name = "UltiMaker", email = "cura@ultimaker.com" }
+]
+dependencies = [
+    "pyyaml"
+]
+
+[project.scripts]
+printer-linter = "printerlinter.terminal:main"
+
+[build-system]
+requires = ["setuptools"]
+build-backend = "setuptools.build_meta"

+ 10 - 0
printer-linter/setup.cfg

@@ -0,0 +1,10 @@
+[metadata]
+name = printerlinter
+
+[options]
+package_dir=
+    =src
+packages=find:
+
+[options.packages.find]
+where=src

+ 6 - 0
printer-linter/setup.py

@@ -0,0 +1,6 @@
+#!/usr/bin/env python
+
+from setuptools import setup
+
+if __name__ == "__main__":
+    setup()

+ 0 - 0
printer-linter/tidy/__init__.py → printer-linter/src/printerlinter/__init__.py


+ 0 - 0
printer-linter/tidy/defintion.py → printer-linter/src/printerlinter/defintion.py


+ 0 - 0
printer-linter/tidy/diagnostic.py → printer-linter/src/printerlinter/diagnostic.py


+ 0 - 0
printer-linter/tidy/meshes.py → printer-linter/src/printerlinter/meshes.py


+ 0 - 0
printer-linter/tidy/profile.py → printer-linter/src/printerlinter/profile.py


+ 20 - 13
printer-linter/printer-linter.py → printer-linter/src/printerlinter/terminal.py

@@ -8,7 +8,7 @@ from pathlib import Path
 
 import yaml
 
-from tidy import create
+from . import create
 
 
 def examineFile(file, settings):
@@ -72,7 +72,24 @@ def formatFile(file: Path, settings):
             config.write(f, space_around_delimiters=settings["format"].get("format-profile-space-around-delimiters", True))
 
 
-def main(files, setting_path, to_format, to_fix, to_diagnose, report):
+def main():
+    parser = ArgumentParser(
+        description="UltiMaker Cura printer linting, static analysis and formatting of Cura printer definitions and other resources")
+    parser.add_argument("--setting", required=False, type=Path, help="Path to the `.printer-linter` setting file")
+    parser.add_argument("--report", required=False, type=Path, help="Path where the diagnostic report should be stored")
+    parser.add_argument("--format", action="store_true", help="Format the files")
+    parser.add_argument("--diagnose", action="store_true", help="Diagnose the files")
+    parser.add_argument("--fix", action="store_true", help="Attempt to apply the suggested fixes on the files")
+    parser.add_argument("Files", metavar="F", type=Path, nargs="+", help="Files or directories to format")
+
+    args = parser.parse_args()
+    files = args.Files
+    setting_path = args.setting
+    to_format = args.format
+    to_fix = args.fix
+    to_diagnose = args.diagnose
+    report = args.report
+
     if not setting_path:
         setting_path = Path(getcwd(), ".printer-linter")
 
@@ -118,14 +135,4 @@ def main(files, setting_path, to_format, to_fix, to_diagnose, report):
 
 
 if __name__ == "__main__":
-    parser = ArgumentParser(
-        description="UltiMaker Cura printer linting, static analysis and formatting of Cura printer definitions and other resources")
-    parser.add_argument("--setting", required=False, type=Path, help="Path to the `.printer-linter` setting file")
-    parser.add_argument("--report", required=False, type=Path, help="Path where the diagnostic report should be stored")
-    parser.add_argument("--format", action="store_true", help="Format the files")
-    parser.add_argument("--diagnose", action="store_true", help="Diagnose the files")
-    parser.add_argument("--fix", action="store_true", help="Attempt to apply the suggested fixes on the files")
-    parser.add_argument("Files", metavar="F", type=Path, nargs="+", help="Files or directories to format")
-
-    args = parser.parse_args()
-    main(args.Files, args.setting, args.format, args.fix, args.diagnose, args.report)
+    main()