-
Notifications
You must be signed in to change notification settings - Fork 187
/
asserts.py
56 lines (44 loc) · 1.81 KB
/
asserts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from __future__ import annotations
import warnings
from gdsfactory.component import Component
from gdsfactory.config import __version__
def grating_coupler(gc: Component) -> None:
if not gc.info.get("polarization"):
raise ValueError(f"{gc.name} does not have polarization")
if gc.info.get("polarization") not in ["te", "tm", "dual"]:
raise ValueError(f"{gc.name} polarization not 'te' or 'tm' or 'dual")
if not gc.info.get("wavelength"):
raise ValueError(f"{gc.name} wavelength does not have wavelength")
if not (0.5 < gc.info["wavelength"] < 5.0):
raise ValueError(f"{gc.name} wavelength {gc.wavelength} should be in um")
if "o1" not in gc.ports:
warnings.warn(
f"grating_coupler {gc.name} should have a o1 port. It has {gc.ports}",
stacklevel=3,
)
if "o1" in gc.ports and gc.ports["o1"].orientation != 180:
warnings.warn(
f"grating_coupler {gc.name} orientation = {gc.ports['o1'].orientation}"
" should be 180 degrees",
stacklevel=3,
)
def version(
requirement: str, current: str = __version__, package_name="gdsfactory"
) -> None:
"""Raises error if current version does not match requirement."""
try:
import semantic_version
except ModuleNotFoundError as e:
print("You need to 'pip install semantic-version'")
raise e
s = semantic_version.SimpleSpec(requirement)
if not s.match(semantic_version.Version(current)):
raise ValueError(
f"{package_name} requirement {requirement}\n"
f"not compatible your current installed version {current}\n"
"you can run:\n"
f"pip install {package_name} {requirement}\n"
)
if __name__ == "__main__":
# version(">=3.8.10")
version("<=3.8.7")