Compare commits
9 Commits
b450fd10fe
...
90e30821eb
Author | SHA1 | Date | |
---|---|---|---|
90e30821eb | |||
b3a4862e46 | |||
763f09051a | |||
eaef972c88 | |||
5fb229c09f | |||
a3773df853 | |||
0f68796831 | |||
deb3460df3 | |||
afa2f0259d |
@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
Requirements:
|
Requirements:
|
||||||
* python >= 3.10 (written and tested with 3.11)
|
* python >= 3.10 (written and tested with 3.11)
|
||||||
* numpy
|
|
||||||
|
|
||||||
|
|
||||||
Install with pip:
|
Install with pip:
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
from .main import Map, Device
|
from .main import (
|
||||||
from .read import read
|
Map as Map,
|
||||||
from .write import write
|
Device as Device,
|
||||||
|
)
|
||||||
|
from .read import read as read
|
||||||
|
from .write import write as write
|
||||||
|
|
||||||
__author__ = 'Jan Petykiewicz'
|
__author__ = 'Jan Petykiewicz'
|
||||||
__version__ = '0.6'
|
__version__ = '0.7'
|
||||||
|
18
g85/read.py
18
g85/read.py
@ -58,22 +58,24 @@ def read_devices(el_map: ElementTree.Element) -> list[Device]:
|
|||||||
|
|
||||||
device = Device(BinType=bin_type, NullBin=null_bin)
|
device = Device(BinType=bin_type, NullBin=null_bin)
|
||||||
|
|
||||||
val: Any
|
|
||||||
for key, val in el_device.attrib.items():
|
for key, val in el_device.attrib.items():
|
||||||
if key in ('BinType', 'NullBin'):
|
if key in ('BinType', 'NullBin'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
parsed_val: Any
|
||||||
if key in ('WaferSize', 'DeviceSizeX', 'DeviceSizeY', 'Orientation'):
|
if key in ('WaferSize', 'DeviceSizeX', 'DeviceSizeY', 'Orientation'):
|
||||||
val = float(val)
|
parsed_val = float(val)
|
||||||
elif key in ('OriginLocation',):
|
elif key in ('OriginLocation',):
|
||||||
val = int(val)
|
parsed_val = int(val)
|
||||||
elif key == 'CreateDate':
|
elif key == 'CreateDate':
|
||||||
val = datetime.datetime.strptime(val + '000', '%Y%m%d%H%M%S%f')
|
parsed_val = datetime.datetime.strptime(val + '000', '%Y%m%d%H%M%S%f')
|
||||||
|
else:
|
||||||
|
parsed_val = val
|
||||||
|
|
||||||
if key in dev_fields and key[0].isupper():
|
if key in dev_fields and key[0].isupper():
|
||||||
setattr(device, key, val)
|
setattr(device, key, parsed_val)
|
||||||
else:
|
else:
|
||||||
device.misc[key] = val
|
device.misc[key] = parsed_val
|
||||||
|
|
||||||
for el_entry in el_device:
|
for el_entry in el_device:
|
||||||
tag = _tag(el_entry)
|
tag = _tag(el_entry)
|
||||||
@ -137,7 +139,7 @@ def read_row(el_row: ElementTree.Element) -> list[str]:
|
|||||||
|
|
||||||
|
|
||||||
def _tag(element: ElementTree.Element) -> str:
|
def _tag(element: ElementTree.Element) -> str:
|
||||||
'''
|
"""
|
||||||
Get the element's tag, excluding any namespaces.
|
Get the element's tag, excluding any namespaces.
|
||||||
'''
|
"""
|
||||||
return element.tag.split('}')[-1]
|
return element.tag.split('}')[-1]
|
||||||
|
16
g85/write.py
16
g85/write.py
@ -1,4 +1,5 @@
|
|||||||
from typing import Sequence, TextIO, cast
|
from typing import TextIO, cast
|
||||||
|
from collections.abc import Sequence
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
from dataclasses import fields
|
from dataclasses import fields
|
||||||
@ -10,12 +11,15 @@ from .main import Map, Device
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class G85Error(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Hack to directly pass through <![CDATA[...]]>
|
# Hack to directly pass through <![CDATA[...]]>
|
||||||
def _escape_cdata(text):
|
def _escape_cdata(text: str) -> str:
|
||||||
if text.startswith('<![CDATA[') and text.endswith(']]>'):
|
if text.startswith('<![CDATA[') and text.endswith(']]>'):
|
||||||
return text
|
return text
|
||||||
else:
|
return _original_escape_cdata(text)
|
||||||
return _original_escape_cdata(text)
|
|
||||||
|
|
||||||
|
|
||||||
_original_escape_cdata = ElementTree._escape_cdata # type: ignore
|
_original_escape_cdata = ElementTree._escape_cdata # type: ignore
|
||||||
@ -64,7 +68,7 @@ def write_devices(devices: Sequence[Device], el_map: ElementTree.Element) -> Non
|
|||||||
|
|
||||||
# Row data prep
|
# Row data prep
|
||||||
if device.map is None:
|
if device.map is None:
|
||||||
raise Exception(f'No _data for device pformat({device})')
|
raise G85Error(f'No _data for device pformat({device})')
|
||||||
|
|
||||||
is_decimal = device.BinType == 'Decimal'
|
is_decimal = device.BinType == 'Decimal'
|
||||||
row_texts, bin_length = prepare_data(device.map, decimal=is_decimal)
|
row_texts, bin_length = prepare_data(device.map, decimal=is_decimal)
|
||||||
@ -136,7 +140,7 @@ def prepare_data(data: list[list[str]] | list[list[int]], decimal: bool) -> tupl
|
|||||||
row_text = ' '.join(srow) + ' '
|
row_text = ' '.join(srow) + ' '
|
||||||
row_texts.append(row_text)
|
row_texts.append(row_text)
|
||||||
return row_texts, char_len
|
return row_texts, char_len
|
||||||
else:
|
else: # noqa: RET505
|
||||||
data = cast(list[list[int]], data)
|
data = cast(list[list[int]], data)
|
||||||
max_value = max(max(rr) for rr in data)
|
max_value = max(max(rr) for rr in data)
|
||||||
max_digits = math.ceil(math.log10(max_value))
|
max_digits = math.ceil(math.log10(max_value))
|
||||||
|
@ -38,8 +38,41 @@ classifiers = [
|
|||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
dynamic = ["version"]
|
dynamic = ["version"]
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"numpy~=1.21",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.hatch.version]
|
[tool.hatch.version]
|
||||||
path = "g85/__init__.py"
|
path = "g85/__init__.py"
|
||||||
|
|
||||||
|
|
||||||
|
[tool.ruff]
|
||||||
|
exclude = [
|
||||||
|
".git",
|
||||||
|
"dist",
|
||||||
|
]
|
||||||
|
line-length = 145
|
||||||
|
indent-width = 4
|
||||||
|
lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
|
||||||
|
lint.select = [
|
||||||
|
"NPY", "E", "F", "W", "B", "ANN", "UP", "SLOT", "SIM", "LOG",
|
||||||
|
"C4", "ISC", "PIE", "PT", "RET", "TCH", "PTH", "INT",
|
||||||
|
"ARG", "PL", "R", "TRY",
|
||||||
|
"G010", "G101", "G201", "G202",
|
||||||
|
"Q002", "Q003", "Q004",
|
||||||
|
]
|
||||||
|
lint.ignore = [
|
||||||
|
#"ANN001", # No annotation
|
||||||
|
"ANN002", # *args
|
||||||
|
"ANN003", # **kwargs
|
||||||
|
"ANN401", # Any
|
||||||
|
"ANN101", # self: Self
|
||||||
|
"SIM108", # single-line if / else assignment
|
||||||
|
"RET504", # x=y+z; return x
|
||||||
|
"PIE790", # unnecessary pass
|
||||||
|
"ISC003", # non-implicit string concatenation
|
||||||
|
"C408", # dict(x=y) instead of {'x': y}
|
||||||
|
"PLR09", # Too many xxx
|
||||||
|
"PLR2004", # magic number
|
||||||
|
"PLC0414", # import x as x
|
||||||
|
"TRY003", # Long exception message
|
||||||
|
]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user