Skip to content

Commit

Permalink
Add pre-commit-config, Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
30350n committed Jan 23, 2024
1 parent a7b2de5 commit c60f181
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 47 deletions.
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.5.0"
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: mixed-line-ending
- repo: https://github.com/hhatto/autopep8
rev: "v2.0.4"
hooks:
- id: autopep8
- repo: https://github.com/pycqa/isort
rev: "5.12.0"
hooks:
- id: isort
- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
hooks:
- id: codespell
additional_dependencies:
- tomli
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ them, after last minute board revisions.
`Edit -> Preferences -> Add-ons -> Install`<br>
(you need to install the actual zip file, don't unpack it!)
and enable it (enabling the addon for the first time will take a few minutes).

### Note on python version (Linux and macOS)

On Windows, KiCad and Blender both ship with their own bundled python version
Expand Down
12 changes: 7 additions & 5 deletions generate_release.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/usr/bin/env python3

from pathlib import Path
from git import Repo
from zipfile import ZipFile, ZIP_DEFLATED
import json, re, shutil, sys
from hashlib import sha256
from itertools import chain
from pathlib import Path
from unittest.mock import patch
from zipfile import ZIP_DEFLATED, ZipFile

import requests
from autopep8 import main as autopep8
from git import Repo
from pytest import main as pytest
from unittest.mock import patch
import json, shutil, requests, re, sys

RELEASE_DIRECTORY = Path("release")
ARCHIVE_DIRECTORY = RELEASE_DIRECTORY / "archive"
Expand Down
5 changes: 3 additions & 2 deletions pcb2blender_exporter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pcbnew, wx
from pathlib import Path

from .ui import SettingsDialog
import pcbnew, wx

from .export import export_pcb3d, get_boarddefs
from .ui import SettingsDialog

__version__ = "2.8"

Expand Down
14 changes: 7 additions & 7 deletions pcb2blender_exporter/export.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pcbnew
from pcbnew import ToMM, PLOT_CONTROLLER, PLOT_FORMAT_SVG, DRILL_MARKS_NO_DRILL_SHAPE

import tempfile, shutil, struct, re
from pathlib import Path
from zipfile import ZipFile, ZIP_DEFLATED
import re, shutil, struct, tempfile
from dataclasses import dataclass, field
from enum import IntEnum
from pathlib import Path
from typing import List, Tuple
from zipfile import ZIP_DEFLATED, ZipFile

import pcbnew
from pcbnew import DRILL_MARKS_NO_DRILL_SHAPE, PLOT_CONTROLLER, PLOT_FORMAT_SVG, ToMM

PCB = "pcb.wrl"
COMPONENTS = "components"
Expand Down Expand Up @@ -290,7 +290,7 @@ def init_tempdir():
file.unlink()
shutil.rmtree(tempdir)
except OSError:
# if this stil doesn't work, fuck it
# if this still doesn't work, fuck it
return
tempdir.mkdir()

Expand Down
3 changes: 2 additions & 1 deletion pcb2blender_exporter/ui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import wx
from pathlib import Path

import wx

class SettingsDialog(wx.Dialog):
def __init__(self, parent, boarddefs, ignored):
wx.Dialog.__init__(self, parent, title="Export to Blender")
Expand Down
37 changes: 20 additions & 17 deletions pcb2blender_importer/importer.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import bpy, bmesh, addon_utils
from bpy_extras.io_utils import ImportHelper, orientation_helper, axis_conversion
from bpy.props import *
from mathutils import Vector, Matrix

import tempfile, random, shutil, re, struct, io
from math import inf, radians
from pathlib import Path
from zipfile import ZipFile, BadZipFile, Path as ZipPath
import io, random, re, shutil, struct, tempfile
from dataclasses import dataclass
from enum import Enum
import numpy as np
from math import inf, radians
from pathlib import Path
from zipfile import BadZipFile, Path as ZipPath, ZipFile

from skia import SVGDOM, Stream, Surface, Color4f
SKIA_MAGIC = 0.282222222
import numpy as np
from PIL import Image, ImageOps
from skia import SVGDOM, Color4f, Stream, Surface

import addon_utils, bmesh, bpy
from bpy.props import *
from bpy_extras.io_utils import ImportHelper, axis_conversion, orientation_helper
from io_scene_x3d import (
ImportX3D, X3D_PT_import_transform, import_x3d,
menu_func_import as menu_func_import_x3d_original
)
from mathutils import Matrix, Vector

from .blender_addon_utils import ErrorHelper
from .materials import *

from io_scene_x3d import ImportX3D, X3D_PT_import_transform, import_x3d
from io_scene_x3d import menu_func_import as menu_func_import_x3d_original

PCB = "pcb.wrl"
COMPONENTS = "components"
LAYERS = "layers"
Expand Down Expand Up @@ -396,7 +396,7 @@ def import_pcb3d(self, context, filepath):

# cut boards

# TODO: maybe handle this differently by always providing atleast one board def?
# TODO: maybe handle this differently by always providing at least one board def?
if not (has_multiple_boards := bool(pcb.boards and self.cut_boards)):
name = f"PCB_{filepath.stem}"
pcb_object.name = pcb_object.data.name = name
Expand Down Expand Up @@ -864,8 +864,11 @@ def apply_transformation(obj, matrix):
@staticmethod
def svg2img(svg_path, dpi):
svg = SVGDOM.MakeFromStream(Stream.MakeFromFile(str(svg_path)))
width, height = svg.containerSize()

SKIA_MAGIC = 0.282222222
dpmm = dpi * INCH_TO_MM * SKIA_MAGIC

width, height = svg.containerSize()
pixels_width, pixels_height = round(width * dpmm), round(height * dpmm)
surface = Surface(pixels_width, pixels_height)

Expand Down
13 changes: 6 additions & 7 deletions pcb2blender_importer/materials.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from .mat4cad.core import Material, rgb2hex, hex2rgb, srgb2lin, lin2srgb
from .mat4cad.colors import PCB_YELLOW
from .mat4cad.blender import register as register_mat4cad, unregister as unregister_mat4cad
from .custom_node_utils import *

import bpy
from bl_ui import node_add_menu
from bpy.props import EnumProperty
from mathutils import Vector, Color

from bpy.types import Menu, NodeTree, ShaderNodeCustomGroup
from mathutils import Color, Vector

from .custom_node_utils import *
from .mat4cad.blender import register as register_mat4cad, unregister as unregister_mat4cad
from .mat4cad.colors import PCB_YELLOW
from .mat4cad.core import Material, hex2rgb, lin2srgb, rgb2hex, srgb2lin

LAYER_BOARD_EDGE = "pcb_board_edge"
LAYER_THROUGH_HOLES = "pcb_through_holes"
Expand Down
6 changes: 3 additions & 3 deletions pcb2blender_importer/solder_joints.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import numpy as np

import bpy
from bpy.props import *

import numpy as np

from .importer import MM_TO_M
from .custom_node_utils import setup_node_tree
from .importer import MM_TO_M

class PCB2BLENDER_OT_solder_joint_add(bpy.types.Operator):
"""Add a solder joint"""
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,20 @@ max_line_length = 96
ignore = "E12,E13,E201,E202,E221,E241,E261,E302,E305,E401,E402"
exclude = "site-packages"

[tool.isort]
line_length = 96
lines_after_imports = 1
combine_as_imports = true
combine_straight_imports = true
multi_line_output = 5
known_blender = [
"addon_utils", "bpy", "bpy_extras", "bl_ui", "bmesh", "io_scene_x3d", "mathutils"
]
known_pcbnew = ["pcbnew", "wx"]
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "BLENDER", "PCBNEW", "FIRSTPARTY", "LOCALFOLDER"]

[tool.pytest.ini_options]
addopts = "--ignore-glob=*site-packages*"

[tool.codespell]
ignore-words-list = "tht"
6 changes: 3 additions & 3 deletions tests/test_importer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import bpy

from itertools import product, chain
from itertools import chain, product
from pathlib import Path
from tempfile import gettempdir

import pytest

import bpy

test_filepaths = list((Path(__file__).parent / "test_pcbs").resolve().glob("**/*.pcb3d"))

kwargs_test_permutations = {
Expand Down

0 comments on commit c60f181

Please sign in to comment.