From afa2f0259d0423afa46b01ccfb13368f43492848 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 21:49:50 -0700 Subject: [PATCH 1/9] re-export using "import x as x" --- g85/__init__.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/g85/__init__.py b/g85/__init__.py index 8df75f7..98598fe 100644 --- a/g85/__init__.py +++ b/g85/__init__.py @@ -1,6 +1,9 @@ -from .main import Map, Device -from .read import read -from .write import write +from .main import ( + Map as Map, + Device as Device, + ) +from .read import read as read +from .write import write as write __author__ = 'Jan Petykiewicz' __version__ = '0.6' From deb3460df3b155093e3ac56bea56308ab61dc159 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 21:50:06 -0700 Subject: [PATCH 2/9] rename altered loop variable --- g85/read.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/g85/read.py b/g85/read.py index 9fd2317..a19c41e 100644 --- a/g85/read.py +++ b/g85/read.py @@ -58,22 +58,24 @@ def read_devices(el_map: ElementTree.Element) -> list[Device]: device = Device(BinType=bin_type, NullBin=null_bin) - val: Any for key, val in el_device.attrib.items(): if key in ('BinType', 'NullBin'): continue + parsed_val: Any if key in ('WaferSize', 'DeviceSizeX', 'DeviceSizeY', 'Orientation'): - val = float(val) + parsed_val = float(val) elif key in ('OriginLocation',): - val = int(val) + parsed_val = int(val) 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(): - setattr(device, key, val) + setattr(device, key, parsed_val) else: - device.misc[key] = val + device.misc[key] = parsed_val for el_entry in el_device: tag = _tag(el_entry) From 0f68796831a606fc3b043b4efc21749a2f7c72be Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 21:50:17 -0700 Subject: [PATCH 3/9] use double quotes for docstring --- g85/read.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/g85/read.py b/g85/read.py index a19c41e..8c4a924 100644 --- a/g85/read.py +++ b/g85/read.py @@ -139,7 +139,7 @@ def read_row(el_row: ElementTree.Element) -> list[str]: def _tag(element: ElementTree.Element) -> str: - ''' + """ Get the element's tag, excluding any namespaces. - ''' + """ return element.tag.split('}')[-1] From a3773df853884abccffa3b34587add48b09b13d4 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 21:50:31 -0700 Subject: [PATCH 4/9] use subclassed Exception --- g85/write.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/g85/write.py b/g85/write.py index 06d4726..6960823 100644 --- a/g85/write.py +++ b/g85/write.py @@ -10,6 +10,10 @@ from .main import Map, Device logger = logging.getLogger(__name__) +class G85Error(Exception): + pass + + # Hack to directly pass through def _escape_cdata(text): if text.startswith(''): @@ -64,7 +68,7 @@ def write_devices(devices: Sequence[Device], el_map: ElementTree.Element) -> Non # Row data prep 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' row_texts, bin_length = prepare_data(device.map, decimal=is_decimal) From 5fb229c09fd3b61c5d046771abef2a46c791b3ef Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 21:50:44 -0700 Subject: [PATCH 5/9] improve type annotations --- g85/write.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/g85/write.py b/g85/write.py index 6960823..ebd07ae 100644 --- a/g85/write.py +++ b/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 math from dataclasses import fields @@ -15,7 +16,7 @@ class G85Error(Exception): # Hack to directly pass through -def _escape_cdata(text): +def _escape_cdata(text: str) -> str: if text.startswith(''): return text else: From eaef972c886a98259642f95f74a661a56730d927 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 21:50:57 -0700 Subject: [PATCH 6/9] flatten some indentation --- g85/write.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/g85/write.py b/g85/write.py index ebd07ae..e0c0bd3 100644 --- a/g85/write.py +++ b/g85/write.py @@ -19,8 +19,7 @@ class G85Error(Exception): def _escape_cdata(text: str) -> str: if text.startswith(''): return text - else: - return _original_escape_cdata(text) + return _original_escape_cdata(text) _original_escape_cdata = ElementTree._escape_cdata # type: ignore @@ -141,7 +140,7 @@ def prepare_data(data: list[list[str]] | list[list[int]], decimal: bool) -> tupl row_text = ' '.join(srow) + ' ' row_texts.append(row_text) return row_texts, char_len - else: + else: # noqa: RET505 data = cast(list[list[int]], data) max_value = max(max(rr) for rr in data) max_digits = math.ceil(math.log10(max_value)) From 763f09051a4173e0c49f7038a007709966079a5e Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 21:51:04 -0700 Subject: [PATCH 7/9] add ruff config --- pyproject.toml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 3d9e1e2..0fca8c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,3 +43,37 @@ dependencies = [ [tool.hatch.version] 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 + ] + From b3a4862e46c57bd1e1729cda08ae737cf1d5d37b Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 21:53:06 -0700 Subject: [PATCH 8/9] remove unused numpy dependency --- README.md | 1 - pyproject.toml | 1 - 2 files changed, 2 deletions(-) diff --git a/README.md b/README.md index 8dc93e1..d0a8815 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ Requirements: * python >= 3.10 (written and tested with 3.11) -* numpy Install with pip: diff --git a/pyproject.toml b/pyproject.toml index 0fca8c8..3aef2fb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,7 +38,6 @@ classifiers = [ requires-python = ">=3.10" dynamic = ["version"] dependencies = [ - "numpy~=1.21", ] [tool.hatch.version] From 90e30821ebbd9354cf4b16bf312b4bcfec0b94f1 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 21:54:00 -0700 Subject: [PATCH 9/9] bump version to v0.7 --- g85/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g85/__init__.py b/g85/__init__.py index 98598fe..69c0e4b 100644 --- a/g85/__init__.py +++ b/g85/__init__.py @@ -6,4 +6,4 @@ from .read import read as read from .write import write as write __author__ = 'Jan Petykiewicz' -__version__ = '0.6' +__version__ = '0.7'