Make gerbonara python3.8 compatible.

merge-requests/1/head v0.11.0
jaseg 2022-06-21 12:26:38 +02:00
rodzic ee233317f1
commit 218f9d9b1f
5 zmienionych plików z 44 dodań i 21 usunięć

Wyświetl plik

@ -17,7 +17,7 @@
# #
import math import math
from dataclasses import dataclass, replace, field, fields, InitVar, KW_ONLY from dataclasses import dataclass, replace, field, fields, InitVar
from .aperture_macros.parse import GenericMacros from .aperture_macros.parse import GenericMacros
from .utils import MM, Inch from .utils import MM, Inch
@ -60,16 +60,26 @@ class Length:
@dataclass @dataclass
class Aperture: class Aperture:
""" Base class for all apertures. """ """ Base class for all apertures. """
_ : KW_ONLY
#: :py:class:`gerbonara.utils.LengthUnit` used for all length fields of this aperture. # hackety hack: Work around python < 3.10 not having dataclasses.KW_ONLY.
unit : str = None #
#: GerberX2 attributes of this aperture. Note that this will only contain aperture attributes, not file attributes. # For details, refer to graphic_objects.py
#: File attributes are stored in the :py:attr:`~.GerberFile.attrs` of the :py:class:`.GerberFile`. def __init_subclass__(cls):
attrs : dict = field(default_factory=dict) #: :py:class:`gerbonara.utils.LengthUnit` used for all length fields of this aperture.
#: Aperture index this aperture had when it was read from the Gerber file. This field is purely informational since cls.unit = None
#: apertures are de-duplicated and re-numbered when writing a Gerber file. For `D10`, this field would be `10`. When #: GerberX2 attributes of this aperture. Note that this will only contain aperture attributes, not file attributes.
#: you programmatically create a new aperture, you do not have to set this. #: File attributes are stored in the :py:attr:`~.GerberFile.attrs` of the :py:class:`.GerberFile`.
original_number : int = None cls.attrs = field(default_factory=dict)
#: Aperture index this aperture had when it was read from the Gerber file. This field is purely informational since
#: apertures are de-duplicated and re-numbered when writing a Gerber file. For `D10`, this field would be `10`. When
#: you programmatically create a new aperture, you do not have to set this.
cls.original_number = None
d = {'unit': str, 'attrs': dict, 'original_number': int}
if hasattr(cls, '__annotations__'):
cls.__annotations__.update(d)
else:
cls.__annotations__ = d
@property @property
def hole_shape(self): def hole_shape(self):

Wyświetl plik

@ -18,7 +18,7 @@
import math import math
import copy import copy
from dataclasses import dataclass, KW_ONLY, astuple, replace, field, fields from dataclasses import dataclass, astuple, replace, field, fields
from .utils import MM, InterpMode, to_unit, rotate_point from .utils import MM, InterpMode, to_unit, rotate_point
from . import graphic_primitives as gp from . import graphic_primitives as gp
@ -45,6 +45,8 @@ class GraphicObject:
# hackety hack: Work around python < 3.10 not having dataclasses.KW_ONLY. Once we drop python 3.8 and 3.9, we can # hackety hack: Work around python < 3.10 not having dataclasses.KW_ONLY. Once we drop python 3.8 and 3.9, we can
# get rid of this, just set these as normal fields, and decorate GraphicObject with @dataclass. # get rid of this, just set these as normal fields, and decorate GraphicObject with @dataclass.
#
# See also: apertures.py, graphic_primitives.py
def __init_subclass__(cls): def __init_subclass__(cls):
#: bool representing the *color* of this feature: whether this is a *dark* or *clear* feature. Clear and dark are #: bool representing the *color* of this feature: whether this is a *dark* or *clear* feature. Clear and dark are
#: meant in the sense that they are used in the Gerber spec and refer to whether the transparency film that this #: meant in the sense that they are used in the Gerber spec and refer to whether the transparency film that this
@ -61,7 +63,11 @@ class GraphicObject:
#: which are stored in the :py:class:`.GerberFile` object instead. #: which are stored in the :py:class:`.GerberFile` object instead.
cls.attrs = field(default_factory=dict) cls.attrs = field(default_factory=dict)
cls.__annotations__.update({'polarity_dark' : bool, 'unit' : str, 'attrs': dict}) d = {'polarity_dark' : bool, 'unit' : str, 'attrs': dict}
if hasattr(cls, '__annotations__'):
cls.__annotations__.update(d)
else:
cls.__annotations__ = d
def converted(self, unit): def converted(self, unit):

Wyświetl plik

@ -19,7 +19,7 @@
import math import math
import itertools import itertools
from dataclasses import dataclass, KW_ONLY, replace from dataclasses import dataclass, replace
from .utils import * from .utils import *
@ -28,8 +28,18 @@ prec = lambda x: f'{float(x):.6}'
@dataclass @dataclass
class GraphicPrimitive: class GraphicPrimitive:
_ : KW_ONLY
polarity_dark : bool = True # hackety hack: Work around python < 3.10 not having dataclasses.KW_ONLY.
#
# For details, refer to graphic_objects.py
def __init_subclass__(cls):
cls.polarity_dark = True
d = {'polarity_dark': bool}
if hasattr(cls, '__annotations__'):
cls.__annotations__.update(d)
else:
cls.__annotations__ = d
def bounding_box(self): def bounding_box(self):
""" Return the axis-aligned bounding box of this feature. """ Return the axis-aligned bounding box of this feature.

Wyświetl plik

@ -23,7 +23,7 @@ import math
import re import re
from enum import Enum from enum import Enum
import warnings import warnings
from dataclasses import dataclass, KW_ONLY from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from .cam import CamFile, FileSettings from .cam import CamFile, FileSettings
@ -414,7 +414,6 @@ class TestRecord:
rotation : float = 0 rotation : float = 0
solder_mask : SoldermaskInfo = None solder_mask : SoldermaskInfo = None
lefover : str = None lefover : str = None
_ : KW_ONLY
unit : LengthUnit = None unit : LengthUnit = None
def __str__(self): def __str__(self):
@ -563,7 +562,6 @@ def format_coord_chain(line, settings, coords, cont, unit):
class Outline: class Outline:
outline_type : OutlineType outline_type : OutlineType
outline : [(float,)] outline : [(float,)]
_ : KW_ONLY
unit : LengthUnit = None unit : LengthUnit = None
@classmethod @classmethod
@ -596,7 +594,6 @@ class Conductor:
layer : int layer : int
aperture : (float,) aperture : (float,)
coords : [(float,)] coords : [(float,)]
_ : KW_ONLY
unit : LengthUnit = None unit : LengthUnit = None
@classmethod @classmethod

Wyświetl plik

@ -24,7 +24,7 @@ mkdir -p podman/testdata/git
git ls-tree --full-tree -r HEAD --name-only | rsync -lptgoDv --delete . --files-from - podman/testdata/git/ git ls-tree --full-tree -r HEAD --name-only | rsync -lptgoDv --delete . --files-from - podman/testdata/git/
#git clone --depth 1 . podman/testdata/git #git clone --depth 1 . podman/testdata/git
for distro in ubuntu arch for distro in ubuntu-old ubuntu arch
do do
podman build $NO_CACHE -t gerbonara-$distro-testenv -f podman/$distro-testenv podman build $NO_CACHE -t gerbonara-$distro-testenv -f podman/$distro-testenv
mkdir -p /tmp/gerbonara-test-out mkdir -p /tmp/gerbonara-test-out