Compare commits

..

No commits in common. "v0.6" and "master" have entirely different histories.

8 changed files with 1180 additions and 1579 deletions

View file

@ -1,3 +1,2 @@
include README.md
include LICENSE.md
include fatamorgana/VERSION

View file

@ -26,12 +26,12 @@
Install with pip from PyPi (preferred):
```bash
pip3 install fatamorgana
pip install fatamorgana
```
Install directly from git repository:
```bash
pip3 install git+https://mpxd.net/code/jan/fatamorgana.git@release
pip install git+https://mpxd.net/code/jan/fatamorgana.git@release
```
## Documentation

View file

@ -1 +0,0 @@
0.6

View file

@ -16,16 +16,8 @@
Dependencies:
- Python 3.5 or later
- numpy (optional, faster but no additional functionality)
To get started, try:
```python3
import fatamorgana
help(fatamorgana.OasisLayout)
```
- numpy (optional, no additional functionality)
"""
import pathlib
from .main import OasisLayout, Cell, XName
from .basic import NString, AString, Validation, OffsetTable, OffsetEntry, \
EOFError, SignedError, InvalidDataError, InvalidRecordError
@ -33,7 +25,4 @@ from .basic import NString, AString, Validation, OffsetTable, OffsetEntry, \
__author__ = 'Jan Petykiewicz'
with open(pathlib.Path(__file__).parent / 'VERSION', 'r') as f:
__version__ = f.read().strip()
version = __version__
version = '0.4'

File diff suppressed because it is too large Load diff

View file

@ -3,12 +3,11 @@ 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
import io
import logging
from . import records
from .records import Modals, Record
from .records import Modals
from .basic import OffsetEntry, OffsetTable, NString, AString, real_t, Validation, \
read_magic_bytes, write_magic_bytes, read_uint, EOFError, \
InvalidDataError, InvalidRecordError
@ -24,16 +23,17 @@ 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 = None # type: bool or None
propname_implicit = None # type: bool or None
xname_implicit = None # type: bool or None
textstring_implicit = None # type: bool or None
propstring_implicit = None # type: bool or None
cellname_implicit = None # type: bool or None
within_cell: bool = False
within_cblock: bool = False
end_has_offset_table: bool
started: bool = False
within_cell = False # type: bool
within_cblock = False # type: bool
end_has_offset_table = None # type: bool
started = False # type: bool
class OasisLayout:
@ -43,51 +43,49 @@ class OasisLayout:
Names and strings are stored in dicts, indexed by reference number.
Layer names and properties are stored directly using their associated
record objects.
Cells are stored using `Cell` objects (different from `records.Cell`
record objects).
Cells are stored using Cell objects (different from Cell record objects).
Attributes:
(File properties)
version (AString): Version string ('1.0')
unit (real_t): grid steps per micron
validation (Validation): checksum data
Properties:
File properties:
.version AString: Version string ('1.0')
.unit real number: grid steps per micron
.validation Validation: checksum data
(Names)
cellnames (Dict[int, NString]): Cell names
propnames (Dict[int, NString]): Property names
xnames (Dict[int, XName]): Custom names
Names:
.cellnames Dict[int, NString]
.propnames Dict[int, NString]
.xnames Dict[int, XName]
(Strings)
textstrings (Dict[int, AString]): Text strings
propstrings (Dict[int, AString]): Property strings
Strings:
.textstrings Dict[int, AString]
.propstrings Dict[int, AString]
(Data)
layers (List[records.LayerName]): Layer definitions
properties (List[records.Property]): Property values
cells (List[Cell]): Layout cells
Data:
.layers List[records.LayerName]
.properties List[records.Property]
.cells List[Cell]
"""
version: AString
unit: real_t
validation: Validation
version = None # type: AString
unit = None # type: real_t
validation = None # type: Validation
properties: List[records.Property]
cells: List['Cell']
properties = None # type: List[records.Property]
cells = None # type: List[Cell]
cellnames: Dict[int, NString]
propnames: Dict[int, NString]
xnames: Dict[int, 'XName']
cellnames = None # type: Dict[int, NString]
propnames = None # type: Dict[int, NString]
xnames = None # type: Dict[int, XName]
textstrings: Dict[int, AString]
propstrings: Dict[int, AString]
layers: List[records.LayerName]
textstrings = None # type: Dict[int, AString]
propstrings = None # type: Dict[int, AString]
layers = None # type: List[records.LayerName]
def __init__(self, unit: real_t, validation: Validation = None):
"""
Args:
unit: Real number (i.e. int, float, or `Fraction`), grid steps per micron.
validation: `Validation` object containing checksum data.
Default creates a `Validation` object of the "no checksum" type.
:param unit: Real number (i.e. int, float, or Fraction), grid steps per micron.
:param validation: Validation object containing checksum data.
Default creates a Validation object of the "no checksum" type.
"""
if validation is None:
validation = Validation(0)
@ -107,17 +105,14 @@ class OasisLayout:
@staticmethod
def read(stream: io.BufferedIOBase) -> 'OasisLayout':
"""
Read an entire .oas file into an `OasisLayout` object.
Read an entire .oas file into an OasisLayout object.
Args:
stream: Stream to read from.
Returns:
New `OasisLayout` object.
:param stream: Stream to read from.
:return: New OasisLayout object.
"""
file_state = FileModals()
modals = Modals()
layout = OasisLayout(unit=-1) # dummy unit
layout = OasisLayout(unit=None)
read_magic_bytes(stream)
@ -132,20 +127,15 @@ class OasisLayout:
) -> bool:
"""
Read a single record of unspecified type from a stream, adding its
contents into this `OasisLayout` object.
contents into this OasisLayout object.
Args:
stream: Stream to read from.
modals: Modal variable data, used to fill unfilled record
:param stream: Stream to read from.
:param modals: Modal variable data, used to fill unfilled record
fields and updated using filled record fields.
file_state: File status data.
Returns:
`True` if EOF was reached without error, `False` otherwise.
Raises:
InvalidRecordError: from unexpected records
InvalidDataError: from within record parsers
:param file_state: File status data.
:return: True if EOF was reached without error, False otherwise.
:raises: InvalidRecordError from unexpected records;
InvalidDataError from within record parsers.
"""
try:
record_id = read_uint(stream)
@ -157,8 +147,6 @@ class OasisLayout:
logger.info('read_record of type {} at position 0x{:x}'.format(record_id, stream.tell()))
record: Record
# CBlock
if record_id == 34:
if file_state.within_cblock:
@ -316,14 +304,9 @@ class OasisLayout:
"""
Write this object in OASIS fromat to a stream.
Args:
stream: Stream to write to.
Returns:
Number of bytes written.
Raises:
InvalidDataError: if contained records are invalid.
:param stream: Stream to write to.
:return: Number of bytes written.
:raises: InvalidDataError if contained records are invalid.
"""
modals = Modals()
@ -340,7 +323,7 @@ class OasisLayout:
for refnum, name in self.propnames.items())
xnames_offset = OffsetEntry(False, size)
size += sum(records.XName(x.attribute, x.bstring, refnum).dedup_write(stream, modals)
size += sum(records.XName(x.attribute, x.string, refnum).dedup_write(stream, modals)
for refnum, x in self.xnames.items())
textstrings_offset = OffsetEntry(False, size)
@ -374,22 +357,21 @@ class Cell:
"""
Representation of an OASIS cell.
Attributes:
name (Union[NString, int]): name or "CellName reference" number
Properties:
.name NString or int (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
.properties List of records.Property
.placements List of records.Placement
.geometry List of geometry record objectes
"""
name: Union[NString, int]
properties: List[records.Property]
placements: List[records.Placement]
geometry: List[records.geometry_t]
name = None # type: NString or int
properties = None # type: List[records.Property]
placements = None # type: List[records.Placement]
geometry = None # type: List[records.geometry_t]
def __init__(self, name: Union[NString, int]):
def __init__(self, name: NString or int):
"""
Args:
name: `NString` or "CellName reference" number
:param name: NString or int (CellName reference number)
"""
self.name = name
self.properties = []
@ -401,15 +383,10 @@ class Cell:
Write this cell to a stream, using the provided modal variables to
deduplicate any repeated data.
Args:
stream: Stream to write to.
modals: Modal variables to use for deduplication.
Returns:
Number of bytes written.
Raises:
InvalidDataError: if contained records are invalid.
:param stream: Stream to write to.
:param modals: Modal variables to use for deduplication.
:return: Number of bytes written.
:raises: InvalidDataError if contained records are invalid.
"""
size = records.Cell(self.name).dedup_write(stream, modals)
size += sum(p.dedup_write(stream, modals) for p in self.properties)
@ -422,17 +399,16 @@ class XName:
"""
Representation of an XName.
This class is effectively a simplified form of a `records.XName`,
This class is effectively a simplified form of a records.XName,
with the reference data stripped out.
"""
attribute: int
bstring: bytes
attribute = None # type: int
bstring = None # type: bytes
def __init__(self, attribute: int, bstring: bytes):
"""
Args:
attribute: Attribute number.
bstring: Binary data.
:param attribute: Attribute number.
:param bstring: Binary data.
"""
self.attribute = attribute
self.bstring = bstring
@ -440,19 +416,16 @@ class XName:
@staticmethod
def from_record(record: records.XName) -> 'XName':
"""
Create an `XName` object from a `records.XName` record.
Create an XName object from a records.XName record.
Args:
record: XName record to use.
Returns:
`XName` object.
:param record: XName record to use.
:return: XName object.
"""
return XName(record.attribute, record.bstring)
# Mapping from record id to record class.
_GEOMETRY: Dict[int, Type] = {
_GEOMETRY = {
19: records.Text,
20: records.Rectangle,
21: records.Polygon,

File diff suppressed because it is too large Load diff

View file

@ -1,15 +1,13 @@
#!/usr/bin/env python3
from setuptools import setup, find_packages
import fatamorgana
with open('README.md', 'r') as f:
long_description = f.read()
with open('fatamorgana/VERSION', 'r') as f:
version = f.read().strip()
setup(name='fatamorgana',
version=version,
version=fatamorgana.version,
description='OASIS layout format parser and writer',
long_description=long_description,
long_description_content_type='text/markdown',
@ -37,6 +35,7 @@ setup(name='fatamorgana',
'gds',
],
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Development Status :: 3 - Alpha',
'Environment :: Other Environment',
@ -49,11 +48,9 @@ setup(name='fatamorgana',
'Operating System :: Microsoft :: Windows',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)',
'Topic :: Software Development :: Libraries :: Python Modules',
],
packages=find_packages(),
package_data={
'fatamorgana': ['VERSION']
},
install_requires=[
'typing',
],