Compare commits

...

5 Commits
master ... wip

@ -27,3 +27,4 @@ ignore =
per-file-ignores =
# F401 import without use
*/__init__.py: F401,
__init__.py: F401,

@ -3,6 +3,8 @@
**fatamorgana** is a Python package for reading and writing OASIS format layout files.
**Homepage:** https://mpxd.net/code/jan/fatamorgana
* [PyPI](https://pypi.org/project/fatamorgana)
* [Github mirror](https://github.com/anewusername/fatamorgana)
**Capabilities:**
* This package is a work-in-progress and is largely untested -- it works for
@ -20,7 +22,7 @@
## Installation
**Dependencies:**
* python 3.5 or newer
* python >=3.10
* (optional) numpy

File diff suppressed because it is too large Load Diff

@ -3,7 +3,7 @@ This module contains data structures and functions for reading from and
writing to whole OASIS layout files, and provides a few additional
abstractions for the data contained inside them.
"""
from typing import List, Dict, Union, Optional, Type
from typing import Type, IO
import io
import logging
@ -27,20 +27,20 @@ class FileModals:
"""
File-scoped modal variables
"""
cellname_implicit: Optional[bool] = None
propname_implicit: Optional[bool] = None
xname_implicit: Optional[bool] = None
textstring_implicit: Optional[bool] = None
propstring_implicit: Optional[bool] = None
cellname_implicit: bool | None = None
propname_implicit: bool | None = None
xname_implicit: bool | None = None
textstring_implicit: bool | None = None
propstring_implicit: bool | None = None
property_target: List[records.Property]
property_target: list[records.Property]
within_cell: bool = False
within_cblock: bool = False
end_has_offset_table: bool = False
started: bool = False
def __init__(self, property_target: List[records.Property]):
def __init__(self, property_target: list[records.Property]) -> None:
self.property_target = property_target
@ -53,43 +53,49 @@ class OasisLayout:
record objects.
Cells are stored using `Cell` objects (different from `records.Cell`
record objects).
Attributes:
(File properties)
version (AString): Version string ('1.0')
unit (real_t): grid steps per micron
validation (Validation): checksum data
(Names)
cellnames (Dict[int, CellName]): Cell names
propnames (Dict[int, NString]): Property names
xnames (Dict[int, XName]): Custom names
(Strings)
textstrings (Dict[int, AString]): Text strings
propstrings (Dict[int, AString]): Property strings
(Data)
layers (List[records.LayerName]): Layer definitions
properties (List[records.Property]): Property values
cells (List[Cell]): Layout cells
"""
# File properties
version: AString
"""File format version string ('1.0')"""
unit: real_t
"""grid steps per micron"""
validation: Validation
"""checksum data"""
properties: List[records.Property]
cells: List['Cell']
# Data
properties: list[records.Property]
"""Property values"""
cellnames: Dict[int, 'CellName']
propnames: Dict[int, NString]
xnames: Dict[int, 'XName']
cells: list['Cell']
"""Layout cells"""
textstrings: Dict[int, AString]
propstrings: Dict[int, AString]
layers: List[records.LayerName]
layers: list[records.LayerName]
"""Layer definitions"""
def __init__(self, unit: real_t, validation: Validation = None):
# Names
cellnames: dict[int, 'CellName']
"""Cell names"""
propnames: dict[int, NString]
"""Property names"""
xnames: dict[int, 'XName']
"""Custom names"""
# String storage
textstrings: dict[int, AString]
"""Text strings"""
propstrings: dict[int, AString]
"""Property strings"""
def __init__(
self,
unit: real_t,
validation: Validation | None = None,
) -> None:
"""
Args:
unit: Real number (i.e. int, float, or `Fraction`), grid steps per micron.
@ -112,7 +118,7 @@ class OasisLayout:
self.layers = []
@staticmethod
def read(stream: io.BufferedIOBase) -> 'OasisLayout':
def read(stream: IO[bytes]) -> 'OasisLayout':
"""
Read an entire .oas file into an `OasisLayout` object.
@ -132,8 +138,9 @@ class OasisLayout:
pass
return layout
def read_record(self,
stream: io.BufferedIOBase,
def read_record(
self,
stream: IO[bytes],
modals: Modals,
file_state: FileModals
) -> bool:
@ -162,7 +169,7 @@ class OasisLayout:
else:
raise e
logger.info('read_record of type {} at position 0x{:x}'.format(record_id, stream.tell()))
logger.info(f'read_record of type {record_id} at position 0x{stream.tell():x}')
record: Record
@ -182,7 +189,7 @@ class OasisLayout:
# Make sure order is valid (eg, no out-of-cell geometry)
if not file_state.started and record_id != 1:
raise InvalidRecordError('Non-Start record {} before Start'.format(record_id))
raise InvalidRecordError(f'Non-Start record {record_id} before Start')
if record_id == 1:
if file_state.started:
raise InvalidRecordError('Duplicate Start record')
@ -201,7 +208,7 @@ class OasisLayout:
elif record_id in (13, 14):
file_state.within_cell = True
else:
raise InvalidRecordError('Unknown record id: {}'.format(record_id))
raise InvalidRecordError(f'Unknown record id: {record_id}')
if record_id == 0:
''' Pad '''
@ -335,10 +342,10 @@ class OasisLayout:
self.cells[-1].geometry.append(record)
file_state.property_target = record.properties
else:
raise InvalidRecordError('Unknown record id: {}'.format(record_id))
raise InvalidRecordError(f'Unknown record id: {record_id}')
return False
def write(self, stream: io.BufferedIOBase) -> int:
def write(self, stream: IO[bytes]) -> int:
"""
Write this object in OASIS fromat to a stream.
@ -399,32 +406,28 @@ class OasisLayout:
class Cell:
"""
Representation of an OASIS cell.
Attributes:
name (Union[NString, int]): name or "CellName reference" number
properties (List[records.Property]): Properties of this cell
placements (List[records.Placement]): Placement record objects
geometry: (List[records.geometry_t]): Geometry record objectes
"""
name: Union[NString, int]
properties: List[records.Property]
placements: List[records.Placement]
geometry: List[records.geometry_t]
name: NString | int
"""name or "CellName reference" number"""
def __init__(self,
name: Union[NString, str, int],
properties: list[records.Property]
placements: list[records.Placement]
geometry: list[records.geometry_t]
def __init__(
self,
name: NString | str | int,
*,
properties: Optional[List[records.Property]] = None,
placements: Optional[List[records.Placement]] = None,
geometry: Optional[List[records.geometry_t]] = None,
):
properties: list[records.Property] | None = None,
placements: list[records.Placement] | None = None,
geometry: list[records.geometry_t] | None = None,
) -> None:
self.name = name if isinstance(name, (NString, int)) else NString(name)
self.properties = [] if properties is None else properties
self.placements = [] if placements is None else placements
self.geometry = [] if geometry is None else geometry
def dedup_write(self, stream: io.BufferedIOBase, modals: Modals) -> int:
def dedup_write(self, stream: IO[bytes], modals: Modals) -> int:
"""
Write this cell to a stream, using the provided modal variables to
deduplicate any repeated data.
@ -458,11 +461,13 @@ class CellName:
with the reference data stripped out.
"""
nstring: NString
properties: List[records.Property]
properties: list[records.Property]
def __init__(self,
nstring: Union[NString, str],
properties: Optional[List[records.Property]] = None):
def __init__(
self,
nstring: NString | str,
properties: list[records.Property] | None = None,
) -> None:
"""
Args:
nstring: The contained string.
@ -499,7 +504,7 @@ class XName:
attribute: int
bstring: bytes
def __init__(self, attribute: int, bstring: bytes):
def __init__(self, attribute: int, bstring: bytes) -> None:
"""
Args:
attribute: Attribute number.
@ -523,7 +528,7 @@ class XName:
# Mapping from record id to record class.
_GEOMETRY: Dict[int, Type[records.geometry_t]] = {
_GEOMETRY: dict[int, Type[records.geometry_t]] = {
19: records.Text,
20: records.Rectangle,
21: records.Polygon,

File diff suppressed because it is too large Load Diff

@ -1,10 +1,8 @@
'''
Build files equivalent to the test cases used by KLayout.
'''
# type: ignore
from typing import Callable
from io import BufferedIOBase
from typing import Callable, IO
from . import (
@ -12,10 +10,11 @@ from . import (
test_files_circles, test_files_ctrapezoids, test_files_trapezoids,
test_files_placements, test_files_paths, test_files_modals,
test_files_polygons, test_files_rectangles, test_files_empty,
test_files_texts, test_files_cells)
test_files_texts, test_files_cells,
)
def build_file(num: str, func: Callable[[BufferedIOBase], BufferedIOBase]) -> None:
def build_file(num: str, func: Callable[[IO[bytes]], IO[bytes]]) -> None:
with open('t' + num + '.oas', 'wb') as f:
func(f)

@ -1,17 +1,11 @@
# type: ignore
from typing import IO
from io import BytesIO
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
import struct
import pytest # type: ignore
import numpy
from numpy.testing import assert_equal
from .utils import HEADER, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring, write_byte, PathExtensionScheme
from ..basic import InvalidRecordError, InvalidDataError
from ..basic import write_uint, write_bstring, write_byte
from ..main import OasisLayout
@ -32,7 +26,7 @@ def base_tests(layout: OasisLayout) -> None:
assert not layout.cells[0].properties
def write_file_1(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_1(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)
@ -98,11 +92,15 @@ def test_file_1() -> None:
assert geometry[1].height == 610
assert geometry[1].width == 680
assert_equal(geometry[2].point_list,
[[-30, -360], [480, -50], [180, 430], [-630, -20]])
assert_equal(geometry[2].point_list, [
[-30, -360],
[480, -50],
[180, 430],
[-630, -20],
])
assert_equal(geometry[3].point_list,
[[-30, -400],
assert_equal(geometry[3].point_list, [
[-30, -400],
[450, 40],
[70, -220],
[10, 210],
@ -123,23 +121,29 @@ def test_file_1() -> None:
[210, 10],
[40, 820],
[-1340, 60],
[30, -1370]])
[30, -1370],
])
assert_equal(geometry[4].point_list,
[[40, -760], [490, -50], [110, 800], [-640, 10]])
assert_equal(geometry[4].point_list, [
[40, -760],
[490, -50],
[110, 800],
[-640, 10],
])
assert_equal(geometry[5].point_list,
[[140, -380],
assert_equal(geometry[5].point_list, [
[140, -380],
[340, -10],
[30, -100],
[-320, 20],
[130, -460],
[-480, -20],
[-210, 910],
[370, 40]])
[370, 40],
])
assert_equal(geometry[6].point_list,
[[720, -20],
assert_equal(geometry[6].point_list, [
[720, -20],
[20, 20],
[690, 0],
[-10, 650],
@ -153,10 +157,11 @@ def test_file_1() -> None:
[-90, -20],
[-60, 140],
[-1390, 50],
[10, 30]])
[10, 30],
])
assert_equal(geometry[7].point_list,
[[150, -830],
assert_equal(geometry[7].point_list, [
[150, -830],
[-1320, 40],
[-70, 370],
[310, -30],
@ -167,17 +172,25 @@ def test_file_1() -> None:
[-20, 290],
[-1070, 20],
[0, 230],
[1380, -60]])
[1380, -60],
])
assert_equal(geometry[8].point_list,
[[330, 0], [-10, 480], [620, -20], [-10, 330], [-930, 60], [0, -850]])
assert_equal(geometry[8].point_list, [
[330, 0],
[-10, 480],
[620, -20],
[-10, 330],
[-930, 60],
[0, -850],
])
assert_equal(geometry[9].point_list,
[[-140, -410],
assert_equal(geometry[9].point_list, [
[-140, -410],
[10, -140],
[270, 0],
[130, 1030],
[-500, 50],
[10, -330],
[210, -10],
[10, -190]])
[10, -190],
])

@ -1,14 +1,11 @@
# type: ignore
from typing import IO
from io import BytesIO
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
import struct
import pytest # type: ignore
import pytest
from .utils import HEADER, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring
from ..basic import write_uint, write_bstring
from ..basic import InvalidRecordError, InvalidDataError
from ..main import OasisLayout
@ -26,7 +23,7 @@ def base_tests(layout: OasisLayout) -> None:
assert not layout.layers
def write_file_1(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_1(buf: IO[bytes]) -> IO[bytes]:
'''
Single cell with explicit name 'XYZ'
'''
@ -51,7 +48,7 @@ def test_file_1() -> None:
assert not layout.cellnames
def write_file_2(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_2(buf: IO[bytes]) -> IO[bytes]:
'''
Two cellnames ('XYZ', 'ABC') and two cells with name references.
'''
@ -88,7 +85,7 @@ def test_file_2() -> None:
assert layout.cells[1].name == 1
def write_file_3(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_3(buf: IO[bytes]) -> IO[bytes]:
'''
Invalid file, contains a mix of explicit and implicit cellnames
'''
@ -119,7 +116,7 @@ def test_file_3() -> None:
layout = OasisLayout.read(buf)
def write_file_4(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_4(buf: IO[bytes]) -> IO[bytes]:
'''
Two cells referencing two names with explicit ids (unsorted)
'''
@ -158,7 +155,7 @@ def test_file_4() -> None:
assert layout.cells[1].name == 1
def write_file_5(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_5(buf: IO[bytes]) -> IO[bytes]:
'''
Reference to non-existent cell name.
'''
@ -199,7 +196,7 @@ def test_file_5() -> None:
#TODO add optional error checking for this case
def write_file_6(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_6(buf: IO[bytes]) -> IO[bytes]:
'''
Cellname with invalid n-string.
'''
@ -240,7 +237,7 @@ def test_file_6() -> None:
#assert layout.cells[1].name == 1
def write_file_7(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_7(buf: IO[bytes]) -> IO[bytes]:
'''
Unused cellname.
'''

@ -1,17 +1,9 @@
# type: ignore
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
import struct
import pytest # type: ignore
import numpy
from numpy.testing import assert_equal
from typing import IO
from io import BytesIO
from .utils import HEADER, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring, write_byte, PathExtensionScheme
from ..basic import InvalidRecordError, InvalidDataError
from ..basic import write_uint, write_sint, write_bstring, write_byte
from ..main import OasisLayout
@ -32,7 +24,7 @@ def base_tests(layout: OasisLayout) -> None:
assert not layout.cells[0].properties
def write_file_1(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_1(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)

@ -1,17 +1,9 @@
# type: ignore
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
import struct
import pytest # type: ignore
import numpy
from numpy.testing import assert_equal
from typing import IO
from io import BytesIO
from .utils import HEADER, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring, write_byte, PathExtensionScheme
from ..basic import InvalidRecordError, InvalidDataError
from ..basic import write_uint, write_sint, write_bstring, write_byte
from ..main import OasisLayout
@ -28,7 +20,7 @@ def base_tests(layout: OasisLayout) -> None:
assert not layout.layers
def write_file_1(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_1(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)
@ -66,7 +58,8 @@ def write_file_1(buf: BufferedIOBase) -> BufferedIOBase:
+ [0b10] * 4
+ [0b01] * 2
+ [0b10] * 2
+ [0b11, 0b10])
+ [0b11, 0b10]
)
for t, (x, x_en) in enumerate(zip(wh, wh_en)):
write_uint(buf, 26) # CTRAPEZOID record
@ -160,7 +153,7 @@ def test_file_1() -> None:
assert geometry[55].repetition.b_vector == [0, 300]
def write_file_2(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_2(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)

@ -1,14 +1,10 @@
# type: ignore
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
from typing import IO
from io import BytesIO
import struct
import pytest # type: ignore
from .utils import MAGIC_BYTES, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring
from ..basic import write_uint, write_bstring
from ..main import OasisLayout
@ -26,7 +22,7 @@ def base_tests(layout: OasisLayout) -> None:
assert not layout.layers
def write_file_1(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_1(buf: IO[bytes]) -> IO[bytes]:
'''
File contains one PAD record.
1000 units/micron
@ -59,8 +55,7 @@ def test_file_1() -> None:
assert layout.unit == 1000
def write_file_2(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_2(buf: IO[bytes]) -> IO[bytes]:
'''
File contains no records.
1/2 unit/micron
@ -91,7 +86,7 @@ def test_file_2() -> None:
assert layout.unit == 0.5
def write_file_3(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_3(buf: IO[bytes]) -> IO[bytes]:
'''
File contains no records.
10/4 unit/micron
@ -123,7 +118,7 @@ def test_file_3() -> None:
assert layout.unit == 10 / 4
def write_file_4(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_4(buf: IO[bytes]) -> IO[bytes]:
'''
File contains no records.
12.5 unit/micron (float32)
@ -154,7 +149,7 @@ def test_file_4() -> None:
assert layout.unit == 12.5
def write_file_5(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_5(buf: IO[bytes]) -> IO[bytes]:
'''
File contains no records.
12.5 unit/micron (float64)

@ -1,20 +1,15 @@
# type: ignore
from typing import Sequence, IO
from typing import List, Tuple, Iterable, Sequence
from itertools import chain
from io import BytesIO, BufferedIOBase
import pytest # type: ignore
import numpy
from numpy.testing import assert_equal
from io import BytesIO
from .utils import HEADER, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring, write_byte, PathExtensionScheme
from ..basic import InvalidRecordError, InvalidDataError
from ..basic import write_uint, write_sint, write_bstring, write_byte
from ..main import OasisLayout
LAYERS = [(1, 2), (1, 5), (1, 6), (1, 8),
LAYERS = [
(1, 2), (1, 5), (1, 6), (1, 8),
(5, 2), (5, 5), (5, 6), (5, 8),
(6, 2), (6, 5), (6, 6), (6, 8),
(7, 2), (7, 5), (7, 6), (7, 8),
@ -36,7 +31,7 @@ def base_tests(layout: OasisLayout) -> None:
assert not layout.cells[0].properties
def write_names_geom(buf: BufferedIOBase, short: bool = False) -> BufferedIOBase:
def write_names_geom(buf: IO[bytes], short: bool = False) -> IO[bytes]:
write_uint(buf, 11) # LAYERNAME record (geometry)
write_bstring(buf, b'AA') # name
write_uint(buf, 0) # all layers
@ -102,7 +97,7 @@ def write_names_geom(buf: BufferedIOBase, short: bool = False) -> BufferedIOBase
return buf
def write_names_text(buf: BufferedIOBase, prefix: bytes = b'') -> BufferedIOBase:
def write_names_text(buf: IO[bytes], prefix: bytes = b'') -> IO[bytes]:
write_uint(buf, 12) # LAYERNAME record (geometry)
write_bstring(buf, prefix + b'AA') # name
write_uint(buf, 0) # all layers
@ -134,7 +129,7 @@ def write_names_text(buf: BufferedIOBase, prefix: bytes = b'') -> BufferedIOBase
write_uint(buf, 0) # all datatypes
return buf
def write_geom(buf: BufferedIOBase) -> BufferedIOBase:
def write_geom(buf: IO[bytes]) -> IO[bytes]:
for ll, dt in LAYERS:
write_uint(buf, 27) # CIRCLE record
write_byte(buf, 0b0011_1011) # 00rX_YRDL
@ -146,7 +141,7 @@ def write_geom(buf: BufferedIOBase) -> BufferedIOBase:
return buf
def write_text(buf: BufferedIOBase) -> BufferedIOBase:
def write_text(buf: IO[bytes]) -> IO[bytes]:
for ll, dt in LAYERS:
write_uint(buf, 19) # TEXT record
write_byte(buf, 0b0101_1011) # 0CNX_YRTL
@ -160,7 +155,8 @@ def write_text(buf: BufferedIOBase) -> BufferedIOBase:
def name_test(layers: Sequence, is_textlayer: bool) -> None:
for ii, nn in enumerate(layers):
assert is_textlayer == nn.is_textlayer, f'Fail on layername {ii}'
msg = f'Fail on layername {ii}'
assert is_textlayer == nn.is_textlayer, msg
assert nn.nstring.string == ['AA', 'L5A', 'H5A', 'E5A', 'I56A',
'E5L4', 'E5H4', 'E5E4', 'E5I47'][ii], msg
@ -172,7 +168,8 @@ def name_test(layers: Sequence, is_textlayer: bool) -> None:
def name_test_text(layers: Sequence) -> None:
for ii, nn in enumerate(layers):
assert nn.is_textlayer, f'Fail on layername {ii}'
msg = f'Fail on layername {ii}'
assert nn.is_textlayer, msg
assert nn.nstring.string == ['TAA', 'TL5A', 'TH5A', 'TE5A', 'TI56A'][ii], msg
assert nn.layer_interval[0] == [None, None, 5, 5, 5][ii], msg
@ -209,7 +206,7 @@ def elem_test_text(geometry: Sequence) -> None:
assert not gg.properties, msg
def write_file_1(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_1(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)
@ -239,7 +236,7 @@ def test_file_1() -> None:
name_test(layout.layers, is_textlayer=False)
def write_file_2(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_2(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)
@ -269,7 +266,7 @@ def test_file_2() -> None:
name_test(layout.layers, is_textlayer=True)
def write_file_3(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_3(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)
@ -285,7 +282,7 @@ def write_file_3(buf: BufferedIOBase) -> BufferedIOBase:
return buf
def write_file_4(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_4(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)

@ -1,17 +1,9 @@
# type: ignore
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
import struct
import pytest # type: ignore
import numpy
from numpy.testing import assert_equal
from typing import IO
from io import BytesIO
from .utils import HEADER, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring, write_byte, PathExtensionScheme
from ..basic import InvalidRecordError, InvalidDataError
from ..basic import write_uint, write_sint, write_bstring, write_byte
from ..main import OasisLayout
@ -28,7 +20,7 @@ def base_tests(layout: OasisLayout) -> None:
assert not layout.layers
def write_file_1(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_1(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)

@ -1,17 +1,11 @@
# type: ignore
from typing import IO
from io import BytesIO
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
import struct
import pytest # type: ignore
import numpy
from numpy.testing import assert_equal
from .utils import HEADER, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring, write_byte, PathExtensionScheme
from ..basic import InvalidRecordError, InvalidDataError
from ..basic import write_uint, write_sint, write_bstring, write_byte, PathExtensionScheme
from ..main import OasisLayout
@ -32,7 +26,7 @@ def base_tests(layout: OasisLayout) -> None:
assert not layout.cells[0].properties
def write_file_1(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_1(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)

@ -1,17 +1,12 @@
# type: ignore
from typing import Tuple, IO, cast, List
from io import BytesIO
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
import struct
import pytest # type: ignore
import numpy
from numpy.testing import assert_equal
from .utils import HEADER, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring, write_byte, PathExtensionScheme
from ..basic import InvalidRecordError, InvalidDataError, write_float32, write_float64
from ..basic import write_uint, write_sint, write_bstring, write_byte, write_float32, write_float64
from ..records import Rectangle
from ..main import OasisLayout
@ -27,7 +22,7 @@ def base_tests(layout: OasisLayout) -> None:
assert not layout.layers
def write_rectangle(buf: BufferedIOBase, pos: Tuple[int, int] = (300, -400)) -> None:
def write_rectangle(buf: IO[bytes], pos: Tuple[int, int] = (300, -400)) -> None:
write_uint(buf, 20) # RECTANGLE record
write_byte(buf, 0b0111_1011) # SWHX_YRDL
write_uint(buf, 1) # layer
@ -38,7 +33,7 @@ def write_rectangle(buf: BufferedIOBase, pos: Tuple[int, int] = (300, -400)) ->
write_sint(buf, pos[1]) # geometry-y (absolute)
def write_file_1(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_1(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)
@ -179,7 +174,7 @@ def test_file_1() -> None:
assert not layout.cells[1].properties
assert not layout.cells[1].geometry
geometry = layout.cells[0].geometry
geometry = cast(List[Rectangle], layout.cells[0].geometry)
assert len(geometry) == 1
assert geometry[0].layer == 1
assert geometry[0].datatype == 2
@ -211,9 +206,9 @@ def test_file_1() -> None:
assert pp.y == 0, msg
if ii < 4 or ii == 5:
assert pp.flip == False, msg
assert not bool(pp.flip), msg
else:
assert pp.flip == True, msg
assert bool(pp.flip), msg
if ii < 5:
assert pp.angle == 0, msg
@ -254,7 +249,7 @@ def test_file_1() -> None:
assert placements[12].repetition.b_vector == [-330, 330]
def write_file_common(buf: BufferedIOBase, variant: int) -> BufferedIOBase:
def write_file_common(buf: IO[bytes], variant: int) -> IO[bytes]:
'''
'''
assert variant in (2, 3, 5, 7), 'Error in test definition!'
@ -502,9 +497,9 @@ def common_tests(layout: OasisLayout, variant: int) -> None:
assert pp.y == 400 * (ii + 1), msg
if ii in (4, 6):
assert pp.flip == True, msg
assert bool(pp.flip), msg
else:
assert pp.flip == False, msg
assert not bool(pp.flip), msg
if ii in (5, 6):
assert pp.angle == 90, msg
@ -520,7 +515,7 @@ def common_tests(layout: OasisLayout, variant: int) -> None:
assert placements[6].y == 2400
def write_file_4(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_4(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)
@ -599,7 +594,7 @@ def write_file_4(buf: BufferedIOBase) -> BufferedIOBase:
return buf
def write_file_6(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_6(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)
@ -752,7 +747,7 @@ def test_file_6() -> None:
assert pp.y == [0, 1000][ii], msg
def write_file_8(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_8(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)
@ -848,7 +843,7 @@ def test_file_8() -> None:
assert not layout.cells[2].properties
assert not layout.cells[2].placements
geometry = layout.cells[2].geometry
geometry = cast(List[Rectangle], layout.cells[2].geometry)
assert len(geometry) == 1
assert geometry[0].layer == 1
assert geometry[0].datatype == 2

@ -1,17 +1,12 @@
# type: ignore
from typing import IO
from io import BytesIO
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
import struct
import pytest # type: ignore
import numpy
from numpy.testing import assert_equal
from .utils import HEADER, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring, write_byte
from ..basic import InvalidRecordError, InvalidDataError
from ..basic import write_uint, write_sint, write_bstring, write_byte
from ..main import OasisLayout
@ -85,8 +80,11 @@ def common_tests(layout: OasisLayout) -> None:
for ii in range(4):
msg = f'Fail on poly {ii}'
assert len(geometry[0].point_list) == 6, msg
assert_equal(geometry[0].point_list, [[150, 0], [0, 50], [-50, 0], [0, 50],
[-100, 0], [0, -100]], err_msg=msg)
assert_equal(
geometry[0].point_list,
[[150, 0], [0, 50], [-50, 0], [0, 50], [-100, 0], [0, -100]],
err_msg=msg,
)
assert len(geometry[4].point_list) == 6
assert_equal(geometry[4].point_list, [[0, 150], [50, 0], [0, -50], [50, 0], [0, -100], [-100, 0]])
@ -97,8 +95,10 @@ def common_tests(layout: OasisLayout) -> None:
assert len(geometry[7].point_list) == 9
assert_equal(geometry[7].point_list, [[25, 0], [50, 50], [0, 50], [-50, 50], [-50, 0], [-50, -50], [10, -75], [25, -25], [40, 0]])
assert len(geometry[8].point_list) == 9
assert_equal(geometry[8].point_list,
numpy.cumsum([[25, 0], [50, 50], [0, 50], [-50, 50], [-50, 0], [-50, -50], [10, -75], [25, -25], [45, -575]], axis=0))
assert_equal(
geometry[8].point_list,
numpy.cumsum([[25, 0], [50, 50], [0, 50], [-50, 50], [-50, 0], [-50, -50], [10, -75], [25, -25], [45, -575]], axis=0),
)
for ii in range(9, 12):
msg = f'Fail on poly {ii}'
@ -106,7 +106,7 @@ def common_tests(layout: OasisLayout) -> None:
assert_equal(geometry[ii].point_list, [[0, 150], [50, 0], [0, -50], [50, 0], [0, -100], [-100, 0]], err_msg=msg)
def write_file_common(buf: BufferedIOBase, variant: int) -> BufferedIOBase:
def write_file_common(buf: IO[bytes], variant: int) -> IO[bytes]:
'''
'''
assert variant in (1, 3), 'Error in test!!'
@ -375,7 +375,7 @@ def test_file_1() -> None:
assert not gg.properties, f'Fail on polygon {ii}'
def write_file_2(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_2(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)
@ -425,7 +425,8 @@ def test_file_2() -> None:
assert_equal(poly.point_list,
([[-1000, 0]]
+ [[(-1) ** nn * 10, 20] for nn in range(8000)]
+ [[1000, 0], [0, -20 * 8000]]))
+ [[1000, 0], [0, -20 * 8000]]),
)
def test_file_3() -> None:

@ -1,17 +1,13 @@
# type: ignore
from typing import IO
from io import BytesIO
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
import struct
import pytest # type: ignore
import numpy
import pytest
from numpy.testing import assert_equal
from .utils import HEADER, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring, write_byte, PathExtensionScheme
from ..basic import InvalidRecordError, InvalidDataError
from ..basic import write_uint, write_sint, write_bstring, write_byte
from ..basic import InvalidDataError
from ..main import OasisLayout
@ -27,7 +23,7 @@ def base_tests(layout: OasisLayout) -> None:
assert not layout.layers
def write_file_common(buf: BufferedIOBase, variant: int) -> BufferedIOBase:
def write_file_common(buf: IO[bytes], variant: int) -> IO[bytes]:
'''
'''
include_repetitions = variant in (2, 5)
@ -54,7 +50,6 @@ def write_file_common(buf: BufferedIOBase, variant: int) -> BufferedIOBase:
write_uint(buf, 7) # PROPNAME record (implicit id 1)
write_bstring(buf, b'PROP1')
write_uint(buf, 14) # CELL record (explicit)
write_bstring(buf, b'A') # Cell name
@ -359,7 +354,7 @@ def test_file_5() -> None:
assert gg.repetition.b_vector == [0, 320], msg
def write_file_3(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_3(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)
@ -375,7 +370,7 @@ def write_file_3(buf: BufferedIOBase) -> BufferedIOBase:
write_uint(buf, 7) # PROPNAME record (implicit id 0)
write_bstring(buf, b'S_GDS_PROPERTY')
# ** CELL **
write_uint(buf, 14) # CELL record (explicit)
write_bstring(buf, b'A') # Cell name
@ -584,7 +579,7 @@ def test_file_3() -> None:
assert geometry[ii].properties[0].values[1].string == 'PROP_VALUE2', msg
def write_file_4_6(buf: BufferedIOBase, variant: int) -> BufferedIOBase:
def write_file_4_6(buf: IO[bytes], variant: int) -> IO[bytes]:
'''
'''
buf.write(HEADER)
@ -614,7 +609,7 @@ def write_file_4_6(buf: BufferedIOBase, variant: int) -> BufferedIOBase:
write_sint(buf, 300) # geometry-x (relative)
write_sint(buf, -400) # geometry-y (relative)
# ** CELL **
write_uint(buf, 14) # CELL record (explicit)
write_bstring(buf, b'TOP') # Cell name
@ -932,7 +927,7 @@ def test_file_6() -> None:
assert placements[ii].properties[0].values[1].string == 'PROP_VALUE2', msg
def write_file_7_8_9(buf: BufferedIOBase, variant: int) -> BufferedIOBase:
def write_file_7_8_9(buf: IO[bytes], variant: int) -> IO[bytes]:
'''
'''
buf.write(HEADER)
@ -991,7 +986,7 @@ def write_file_7_8_9(buf: BufferedIOBase, variant: int) -> BufferedIOBase:
write_uint(buf, 10) # prop-value 0 (a-string)
write_bstring(buf, b'CPValue0')
# ** CELL **
write_uint(buf, 13) # CELL record (name ref.)
write_uint(buf, 0) # Cell name 0 (XYZ)
@ -1020,7 +1015,6 @@ def write_file_7_8_9(buf: BufferedIOBase, variant: int) -> BufferedIOBase:
return buf
def test_file_7() -> None:
buf = write_file_7_8_9(BytesIO(), 7)

@ -1,15 +1,9 @@
# type: ignore
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
import struct
import pytest # type: ignore
from typing import IO
from io import BytesIO
from .utils import HEADER, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring, write_byte
from ..basic import InvalidRecordError, InvalidDataError
from ..basic import write_uint, write_sint, write_bstring, write_byte
from ..main import OasisLayout
@ -80,7 +74,7 @@ def base_tests(layout: OasisLayout) -> None:
assert geometry[10].repetition.x_displacements == [200, 300]
def write_file_common(buf: BufferedIOBase, variant: int) -> BufferedIOBase:
def write_file_common(buf: IO[bytes], variant: int) -> IO[bytes]:
'''
'''
assert variant in (1, 2), 'Error in test!!'

@ -1,14 +1,11 @@
# type: ignore
from typing import IO
from io import BytesIO
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
import struct
import pytest # type: ignore
import pytest
from .utils import HEADER, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring, write_byte
from ..basic import write_uint, write_sint, write_bstring, write_byte
from ..basic import InvalidRecordError, InvalidDataError
from ..basic import GridRepetition, ArbitraryRepetition
from ..main import OasisLayout
@ -86,12 +83,12 @@ def common_tests(layout: OasisLayout) -> None:
assert geometry[13].repetition.b_vector == [-10, 10]
assert geometry[14].repetition.a_count == 3
assert geometry[14].repetition.b_count == None
assert geometry[14].repetition.b_count is None
assert geometry[14].repetition.a_vector == [11, 12]
assert geometry[14].repetition.b_vector is None
assert geometry[15].repetition.a_count == 4
assert geometry[15].repetition.b_count == None
assert geometry[15].repetition.b_count is None
assert geometry[15].repetition.a_vector == [-10, 10]
assert geometry[15].repetition.b_vector is None
@ -102,7 +99,7 @@ def common_tests(layout: OasisLayout) -> None:
assert geometry[19].repetition.y_displacements == [12, -9]
def write_file_common(buf: BufferedIOBase, variant: int) -> BufferedIOBase:
def write_file_common(buf: IO[bytes], variant: int) -> IO[bytes]:
'''
Single cell with explicit name 'XYZ'
'''
@ -463,7 +460,7 @@ def test_file_12() -> None:
assert layout.textstrings[2].string == 'B'
def write_file_3(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_3(buf: IO[bytes]) -> IO[bytes]:
'''
File with one textstring with explicit id, and one with an implicit id.
Should fail.
@ -500,7 +497,7 @@ def test_file_3() -> None:
layout = OasisLayout.read(buf)
def write_file_4(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_4(buf: IO[bytes]) -> IO[bytes]:
'''
File with a TEXT record that references a non-existent TEXTSTRING
@ -540,7 +537,7 @@ def test_file_4() -> None:
base_tests(layout)
def write_file_6(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_6(buf: IO[bytes]) -> IO[bytes]:
'''
File with TEXT record that uses an un-filled modal for the repetition
'''
@ -573,7 +570,7 @@ def test_file_6() -> None:
layout = OasisLayout.read(buf)
def write_file_7(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_7(buf: IO[bytes]) -> IO[bytes]:
'''
File with TEXT record that uses an un-filled modal for the layer
'''
@ -604,7 +601,7 @@ def test_file_7() -> None:
layout = OasisLayout.read(buf)
def write_file_8(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_8(buf: IO[bytes]) -> IO[bytes]:
'''
File with TEXT record that uses an un-filled modal for the datatype
'''
@ -635,7 +632,7 @@ def test_file_8() -> None:
layout = OasisLayout.read(buf)
def write_file_9(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_9(buf: IO[bytes]) -> IO[bytes]:
'''
File with TEXT record that uses a default modal for the x coordinate
'''
@ -671,7 +668,7 @@ def test_file_9() -> None:
assert text.y == -200
def write_file_10(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_10(buf: IO[bytes]) -> IO[bytes]:
'''
File with TEXT record that uses a default modal for the y coordinate
'''
@ -707,7 +704,7 @@ def test_file_10() -> None:
assert text.x == 100
def write_file_11(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_11(buf: IO[bytes]) -> IO[bytes]:
'''
File with TEXT record that uses an un-filled modal for the text string
'''

@ -1,17 +1,9 @@
# type: ignore
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
import struct
import pytest # type: ignore
import numpy
from numpy.testing import assert_equal
from typing import IO
from io import BytesIO
from .utils import HEADER, FOOTER
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring, write_byte, PathExtensionScheme
from ..basic import InvalidRecordError, InvalidDataError
from ..basic import write_uint, write_sint, write_bstring, write_byte
from ..main import OasisLayout
@ -32,7 +24,7 @@ def base_tests(layout: OasisLayout) -> None:
assert not layout.cells[0].properties
def write_file_1(buf: BufferedIOBase) -> BufferedIOBase:
def write_file_1(buf: IO[bytes]) -> IO[bytes]:
'''
'''
buf.write(HEADER)

@ -1,9 +1,6 @@
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO
import pytest # type: ignore
from ..basic import read_uint, read_sint, write_uint, write_sint

@ -1,12 +1,6 @@
from typing import List, Tuple, Iterable
from itertools import chain
from io import BytesIO, BufferedIOBase
import struct
from io import BytesIO
import pytest # type: ignore
from ..basic import write_uint, write_sint, read_uint, read_sint, write_bstring, write_byte
from ..main import OasisLayout
from ..basic import write_uint, write_bstring, write_byte
MAGIC_BYTES = b'%SEMI-OASIS\r\n'

@ -44,7 +44,7 @@ classifiers = [
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)",
]
requires-python = ">=3.8"
requires-python = ">=3.10"
dynamic = ["version"]
dependencies = [
]

Loading…
Cancel
Save