From 5cdafd580f52e5314f855f76e3c39a9bef7d19a3 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 28 Jul 2024 20:18:12 -0700 Subject: [PATCH 01/10] don't need ABCMeta here --- masque/traits/copyable.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/masque/traits/copyable.py b/masque/traits/copyable.py index 91af84b..c652aff 100644 --- a/masque/traits/copyable.py +++ b/masque/traits/copyable.py @@ -1,9 +1,8 @@ from typing import Self -from abc import ABCMeta import copy -class Copyable(metaclass=ABCMeta): +class Copyable: """ Trait class which adds .copy() and .deepcopy() """ From 48ffc9709ea8e5f7d1e2467f1f658170544bf849 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 28 Jul 2024 20:19:02 -0700 Subject: [PATCH 02/10] double quotes for docstrings --- masque/shapes/arc.py | 12 ++++++------ masque/shapes/path.py | 8 ++++---- masque/shapes/polygon.py | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/masque/shapes/arc.py b/masque/shapes/arc.py index da10d0d..4213229 100644 --- a/masque/shapes/arc.py +++ b/masque/shapes/arc.py @@ -308,7 +308,7 @@ class Arc(Shape): return [poly] def get_bounds_single(self) -> NDArray[numpy.float64]: - ''' + """ Equation for rotated ellipse is `x = x0 + a * cos(t) * cos(rot) - b * sin(t) * sin(phi)` `y = y0 + a * cos(t) * sin(rot) + b * sin(t) * cos(rot)` @@ -319,7 +319,7 @@ class Arc(Shape): where -+ is for x, y cases, so that's where the extrema are. If the extrema are innaccessible due to arc constraints, check the arc endpoints instead. - ''' + """ a_ranges = self._angles_to_parameters() mins = [] @@ -424,13 +424,13 @@ class Arc(Shape): )) def get_cap_edges(self) -> NDArray[numpy.float64]: - ''' + """ Returns: ``` [[[x0, y0], [x1, y1]], array of 4 points, specifying the two cuts which [[x2, y2], [x3, y3]]], would create this arc from its corresponding ellipse. ``` - ''' + """ a_ranges = self._angles_to_parameters() mins = [] @@ -454,11 +454,11 @@ class Arc(Shape): return numpy.array([mins, maxs]) + self.offset def _angles_to_parameters(self) -> NDArray[numpy.float64]: - ''' + """ Returns: "Eccentric anomaly" parameter ranges for the inner and outer edges, in the form `[[a_min_inner, a_max_inner], [a_min_outer, a_max_outer]]` - ''' + """ a = [] for sgn in (-1, +1): wh = sgn * self.width / 2 diff --git a/masque/shapes/path.py b/masque/shapes/path.py index bfaf14f..dfd89f1 100644 --- a/masque/shapes/path.py +++ b/masque/shapes/path.py @@ -431,22 +431,22 @@ class Path(Shape): return self def remove_duplicate_vertices(self) -> 'Path': - ''' + """ Removes all consecutive duplicate (repeated) vertices. Returns: self - ''' + """ self.vertices = remove_duplicate_vertices(self.vertices, closed_path=False) return self def remove_colinear_vertices(self) -> 'Path': - ''' + """ Removes consecutive co-linear vertices. Returns: self - ''' + """ self.vertices = remove_colinear_vertices(self.vertices, closed_path=False) return self diff --git a/masque/shapes/polygon.py b/masque/shapes/polygon.py index 1d52489..f6add4d 100644 --- a/masque/shapes/polygon.py +++ b/masque/shapes/polygon.py @@ -415,22 +415,22 @@ class Polygon(Shape): return self def remove_duplicate_vertices(self) -> 'Polygon': - ''' + """ Removes all consecutive duplicate (repeated) vertices. Returns: self - ''' + """ self.vertices = remove_duplicate_vertices(self.vertices, closed_path=True) return self def remove_colinear_vertices(self) -> 'Polygon': - ''' + """ Removes consecutive co-linear vertices. Returns: self - ''' + """ self.vertices = remove_colinear_vertices(self.vertices, closed_path=True) return self From aa3636ebc6837af164e9d7686d98bbe611188488 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 28 Jul 2024 20:19:22 -0700 Subject: [PATCH 03/10] flatten indent --- masque/pattern.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/masque/pattern.py b/masque/pattern.py index e500d1d..efa5fab 100644 --- a/masque/pattern.py +++ b/masque/pattern.py @@ -595,8 +595,7 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable): if (cbounds[1] < cbounds[0]).any(): return None - else: - return cbounds + return cbounds def get_bounds_nonempty( self, From 5f0a450ffad9c9c2a5721552b1554c39bee05070 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 28 Jul 2024 20:19:43 -0700 Subject: [PATCH 04/10] no need for string annotation --- masque/pattern.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/masque/pattern.py b/masque/pattern.py index efa5fab..6f4d89a 100644 --- a/masque/pattern.py +++ b/masque/pattern.py @@ -953,7 +953,7 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable): Returns: self """ - flattened: dict[str | None, 'Pattern | None'] = {} + flattened: dict[str | None, Pattern | None] = {} def flatten_single(name: str | None) -> None: if name is None: From b10803efe935ecffb7d96833e8c2331c5178328d Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 28 Jul 2024 20:19:59 -0700 Subject: [PATCH 05/10] pass along string arg --- masque/pattern.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/masque/pattern.py b/masque/pattern.py index 6f4d89a..0696552 100644 --- a/masque/pattern.py +++ b/masque/pattern.py @@ -616,7 +616,7 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable): Returns: `[[x_min, y_min], [x_max, y_max]]` """ - bounds = self.get_bounds(library) + bounds = self.get_bounds(library, recurse=recurse) assert bounds is not None return bounds From 7e1f617274a06756e5a0c1cf278e0a1d8a225969 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 28 Jul 2024 20:21:02 -0700 Subject: [PATCH 06/10] fix bug where use_mmap was ignored --- masque/file/gdsii.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/masque/file/gdsii.py b/masque/file/gdsii.py index a28979d..542fb86 100644 --- a/masque/file/gdsii.py +++ b/masque/file/gdsii.py @@ -597,7 +597,7 @@ def load_libraryfile( path = pathlib.Path(filename) stream: IO[bytes] if is_gzipped(path): - if mmap: + if use_mmap: logger.info('Asked to mmap a gzipped file, reading into memory instead...') gz_stream = gzip.open(path, mode='rb') stream = io.BytesIO(gz_stream.read()) # type: ignore @@ -605,7 +605,7 @@ def load_libraryfile( gz_stream = gzip.open(path, mode='rb') stream = io.BufferedReader(gz_stream) # type: ignore else: # noqa: PLR5501 - if mmap: + if use_mmap: base_stream = open(path, mode='rb', buffering=0) stream = mmap.mmap(base_stream.fileno(), 0, access=mmap.ACCESS_READ) # type: ignore else: From 445c5690e179cfe24528a872a0252f5e79c5b1ff Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 28 Jul 2024 20:30:15 -0700 Subject: [PATCH 07/10] use path.open --- masque/file/gdsii.py | 4 ++-- masque/file/utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/masque/file/gdsii.py b/masque/file/gdsii.py index 542fb86..b75c854 100644 --- a/masque/file/gdsii.py +++ b/masque/file/gdsii.py @@ -606,10 +606,10 @@ def load_libraryfile( stream = io.BufferedReader(gz_stream) # type: ignore else: # noqa: PLR5501 if use_mmap: - base_stream = open(path, mode='rb', buffering=0) + base_stream = path.open(mode='rb', buffering=0) # noqa: SIM115 stream = mmap.mmap(base_stream.fileno(), 0, access=mmap.ACCESS_READ) # type: ignore else: - stream = open(path, mode='rb') + stream = path.open(mode='rb') # noqa: SIM115 return load_library(stream, full_load=full_load, postprocess=postprocess) diff --git a/masque/file/utils.py b/masque/file/utils.py index 95248ae..33f68d4 100644 --- a/masque/file/utils.py +++ b/masque/file/utils.py @@ -129,7 +129,7 @@ def clean_pattern_vertices(pat: Pattern) -> Pattern: def is_gzipped(path: pathlib.Path) -> bool: - with open(path, 'rb') as stream: + with path.open('rb') as stream: magic_bytes = stream.read(2) return magic_bytes == b'\x1f\x8b' From 97688ffae13892bd52e307fe39e16f77a6c86c70 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 28 Jul 2024 20:30:28 -0700 Subject: [PATCH 08/10] don't want to use context manager here --- masque/file/gdsii.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/masque/file/gdsii.py b/masque/file/gdsii.py index b75c854..11e1574 100644 --- a/masque/file/gdsii.py +++ b/masque/file/gdsii.py @@ -599,10 +599,10 @@ def load_libraryfile( if is_gzipped(path): if use_mmap: logger.info('Asked to mmap a gzipped file, reading into memory instead...') - gz_stream = gzip.open(path, mode='rb') + gz_stream = gzip.open(path, mode='rb') # noqa: SIM115 stream = io.BytesIO(gz_stream.read()) # type: ignore else: - gz_stream = gzip.open(path, mode='rb') + gz_stream = gzip.open(path, mode='rb') # noqa: SIM115 stream = io.BufferedReader(gz_stream) # type: ignore else: # noqa: PLR5501 if use_mmap: From 810a09f18b28cbac17a376c5795bf8e3a42761bd Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 28 Jul 2024 20:34:25 -0700 Subject: [PATCH 09/10] simplify comparison --- masque/shapes/arc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/masque/shapes/arc.py b/masque/shapes/arc.py index 4213229..8d14f0f 100644 --- a/masque/shapes/arc.py +++ b/masque/shapes/arc.py @@ -286,7 +286,7 @@ class Arc(Shape): return thetas wh = self.width / 2.0 - if wh == r0 or wh == r1: + if wh in (r0, r1): thetas_inner = numpy.zeros(1) # Don't generate multiple vertices if we're at the origin else: thetas_inner = get_thetas(inner=True) From 1ae3ffb9a28ee4b35af72bce18c985328224c662 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Sun, 28 Jul 2024 20:35:37 -0700 Subject: [PATCH 10/10] linter cleanup --- masque/pattern.py | 2 +- masque/repetition.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/masque/pattern.py b/masque/pattern.py index 0696552..47f64c5 100644 --- a/masque/pattern.py +++ b/masque/pattern.py @@ -296,7 +296,7 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable): if not annotations_eq(self.annotations, other.annotations): return False - if not ports_eq(self.ports, other.ports): + if not ports_eq(self.ports, other.ports): # noqa: SIM103 return False return True diff --git a/masque/repetition.py b/masque/repetition.py index 972f3b7..68b6b19 100644 --- a/masque/repetition.py +++ b/masque/repetition.py @@ -289,7 +289,7 @@ class Grid(Repetition): return True if self.b_vector is None or other.b_vector is None: return False - if any(self.b_vector[ii] != other.b_vector[ii] for ii in range(2)): + if any(self.b_vector[ii] != other.b_vector[ii] for ii in range(2)): # noqa: SIM103 return False return True