-
Notifications
You must be signed in to change notification settings - Fork 186
/
cli.py
140 lines (94 loc) · 3.52 KB
/
cli.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from __future__ import annotations
import pathlib
import typer
from gdsfactory import show as _show
from gdsfactory.config import print_version_pdks, print_version_plugins
from gdsfactory.difftest import diff
from gdsfactory.install import install_gdsdiff, install_klayout_package
from gdsfactory.read.from_updk import from_updk
from gdsfactory.watch import watch as _watch
app = typer.Typer()
@app.command()
def layermap_to_dataclass(
filepath: str,
force: bool = typer.Option(False, "--force", "-f", help="Force deletion"),
) -> None:
"""Converts KLayout LYP to a dataclass."""
from gdsfactory.technology import lyp_to_dataclass
filepath_lyp = pathlib.Path(filepath)
filepath_py = filepath_lyp.with_suffix(".py")
if not filepath_lyp.exists():
raise FileNotFoundError(f"{filepath_lyp} not found")
if not force and filepath_py.exists():
raise FileExistsError(f"found {filepath_py}")
lyp_to_dataclass(lyp_filepath=filepath_lyp)
@app.command()
def write_cells(gdspath: str, dirpath: str = None) -> None:
"""Write each all level cells into separate GDS files."""
from gdsfactory.write_cells import write_cells as write_cells_to_separate_gds
write_cells_to_separate_gds(gdspath=gdspath, dirpath=dirpath)
@app.command()
def merge_gds(dirpath: str = None, gdspath: str = None) -> None:
"""Merges GDS cells from a directory into a single GDS."""
from gdsfactory.read.from_gdspaths import from_gdsdir
dirpath = dirpath or pathlib.Path.cwd()
gdspath = gdspath or pathlib.Path.cwd() / "merged.gds"
dirpath = pathlib.Path(dirpath)
c = from_gdsdir(dirpath=dirpath)
c.write_gds(gdspath=gdspath)
c.show()
@app.command()
def watch(
path: str = str(pathlib.Path.cwd()),
pdk: str = typer.Option(None, "--pdk", "-pdk", help="PDK name"),
) -> None:
"""Filewatch a folder for changes in *.py or *.pic.yml files."""
path = pathlib.Path(path)
path = path.parent if path.is_dir() else path
_watch(str(path), pdk=pdk)
@app.command()
def show(filename: str) -> None:
"""Show a GDS file using klive."""
_show(filename)
@app.command()
def gds_diff(gdspath1: str, gdspath2: str, xor: bool = False) -> None:
"""Show boolean difference between two GDS files."""
diff(gdspath1, gdspath2, xor=xor)
@app.command()
def install_klayout_genericpdk() -> None:
"""Install Klayout generic PDK."""
install_klayout_package()
@app.command()
def install_git_diff() -> None:
"""Install git diff."""
install_gdsdiff()
@app.command()
def print_plugins() -> None:
"""Show installed plugin versions."""
print_version_plugins()
@app.command()
def print_pdks() -> None:
"""Show installed PDK versions."""
print_version_pdks()
@app.command(name="from_updk")
def from_updk_command(filepath: str, filepath_out: str = None) -> None:
"""Writes a PDK in python from uPDK YAML spec."""
filepath = pathlib.Path(filepath)
filepath_out = filepath_out or filepath.with_suffix(".py")
from_updk(filepath, filepath_out=filepath_out)
@app.command(name="text_from_pdf")
def text_from_pdf_command(filepath: str) -> None:
"""Converts a PDF to text."""
import pdftotext
with open(filepath, "rb") as f:
pdf = pdftotext.PDF(f)
# Read all the text into one string
text = "\n".join(pdf)
filepath = pathlib.Path(filepath)
f = filepath.with_suffix(".md")
f.write_text(text)
if __name__ == "__main__":
import sys
if len(sys.argv) == 1: # No arguments provided
sys.argv.append("--help")
app()