Skip to content

Commit dd45830

Browse files
committed
fix pre-commit
1 parent d9389d6 commit dd45830

File tree

9 files changed

+208
-34
lines changed

9 files changed

+208
-34
lines changed

.devcontainer/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM joamatab/gdsfactory:latest
2+
3+
EXPOSE 8082
4+
EXPOSE 8083
5+
EXPOSE 8888
6+
7+
USER root
8+
USER jovyan
9+
RUN conda init bash
10+
RUN pip install kweb
11+
WORKDIR /home/jovyan

.devcontainer/devcontainer.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"image": "mcr.microsoft.com/devcontainers/universal:2",
3+
"hostRequirements": {
4+
"cpus": 2
5+
},
6+
"waitFor": "onCreateCommand",
7+
"updateContentCommand": "make install",
8+
"postCreateCommand": "",
9+
"customizations": {
10+
"codespaces": {
11+
"openFiles": []
12+
},
13+
"vscode": {
14+
"extensions": [
15+
"ms-toolsai.jupyter",
16+
"ms-python.python"
17+
]
18+
}
19+
}
20+
}

.pre-commit-config.yaml

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: "5191f112dfd133e97acba8c2162c37d8613cf54b"
4+
hooks:
5+
- id: check-added-large-files
6+
- id: check-case-conflict
7+
- id: check-merge-conflict
8+
- id: check-symlinks
9+
- id: check-yaml
10+
- id: debug-statements
11+
- id: end-of-file-fixer
12+
- id: mixed-line-ending
13+
- id: name-tests-test
14+
args: ["--pytest-test-first"]
15+
- id: requirements-txt-fixer
16+
- id: trailing-whitespace
17+
18+
- repo: https://github.com/hakancelik96/unimport
19+
rev: 33ead41ee30f1d323a9c2fcfd0114297efbbc4d5
20+
hooks:
21+
- id: unimport
22+
args: [--remove, --include-star-import]
23+
- repo: https://github.com/pycqa/isort
24+
rev: "06d8ef58a15751eda085547cc2095a6dea098f3b"
25+
hooks:
26+
- id: isort
27+
files: "kweb/.*"
28+
args: ["--profile", "black", "--filter-files"]
29+
30+
- repo: https://github.com/psf/black
31+
rev: "196b1f349eb2baa9bbbc483226874cc01fb7567d"
32+
hooks:
33+
- id: black
34+
35+
# - repo: https://github.com/pycqa/flake8
36+
# rev: "647996c743f9e77368ce46cc74abe98549dd4c3a"
37+
# hooks:
38+
# - id: flake8
39+
40+
- repo: https://github.com/kynan/nbstripout
41+
rev: 1185a8d25bb45ada13f64d9591c14d81d69206bc
42+
hooks:
43+
- id: nbstripout
44+
files: ".ipynb"
45+
46+
- repo: https://github.com/asottile/pyupgrade
47+
rev: 97ed6fb3cf2e650d4f762ba231c3f04c41797710
48+
hooks:
49+
- id: pyupgrade
50+
args: [--py310-plus, --keep-runtime-typing]
51+
52+
# - repo: https://github.com/codespell-project/codespell
53+
# rev: 3841ffe24aba604a5d16439c8216b018a7ec649a
54+
# hooks:
55+
# - id: codespell
56+
# args: ["-L TE,TE/TM,te,ba,FPR,fpr_spacing,ro,donot"]
57+
58+
- repo: https://github.com/shellcheck-py/shellcheck-py
59+
rev: 953faa6870f6663ac0121ab4a800f1ce76bca31f
60+
hooks:
61+
- id: shellcheck
62+
63+
# - repo: https://github.com/pre-commit/pygrep-hooks
64+
# rev: 7b4409161486c6956bb3206ce96db5d56731b1b9 # Use the ref you want to point at
65+
# hooks:
66+
# - id: python-use-type-annotations
67+
68+
- repo: https://github.com/PyCQA/bandit
69+
rev: 91c4d979550888c8d190898279bfdb0af732791e
70+
hooks:
71+
- id: bandit
72+
args: [--exit-zero]
73+
# ignore all tests, not just tests data
74+
exclude: ^tests/
75+
# - repo: https://github.com/pre-commit/mirrors-mypy
76+
# rev: "v0.991"
77+
# hooks:
78+
# - id: mypy
79+
# exclude: ^(docs/|example-plugin/|tests/fixtures)
80+
# additional_dependencies:
81+
# - "pydantic"
82+
# - repo: https://github.com/terrencepreilly/darglint
83+
# rev: master
84+
# hooks:
85+
# - id: darglint
86+
# - repo: https://github.com/pycqa/pydocstyle
87+
# rev: "a6fe4222012e990042c86cdaaa904a8d059752ee"
88+
# hooks:
89+
# - id: pydocstyle
90+
# additional_dependencies: ["pydocstyle[toml]"]
91+
# - repo: https://github.com/asottile/reorder_python_imports
92+
# rev: 2b2f0c74acdb3de316e23ceb7dd0d7945c354050
93+
# hooks:
94+
# - id: reorder-python-imports
95+
# - repo: https://github.com/PyCQA/pylint
96+
# rev: v2.14.1
97+
# hooks:
98+
# - id: pylint
99+
# args: [--exit-zero]
100+
# - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
101+
# rev: 6565d773ca281682d7062d4c0be74538cc474cc9
102+
# hooks:
103+
# - id: pretty-format-java
104+
# args: [--autofix]
105+
# - id: pretty-format-kotlin
106+
# args: [--autofix]
107+
# - id: pretty-format-yaml
108+
# args: [--autofix, --indent, "2"]
109+
# - repo: https://github.com/adrienverge/yamllint.git
110+
# rev: v1.21.0 # or higher tag
111+
# hooks:
112+
# - id: yamllint
113+
# args: [--format, parsable, --strict]
114+
# - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
115+
# rev: 0.1.0 # or specific tag
116+
# hooks:
117+
# - id: yamlfmt
118+
- repo: https://github.com/pre-commit/pygrep-hooks
119+
rev: "v1.10.0"
120+
hooks:
121+
- id: python-check-blanket-noqa
122+
- id: python-check-blanket-type-ignore
123+
- id: python-no-log-warn
124+
- id: python-no-eval
125+
- id: python-use-type-annotations
126+
- id: rst-backticks
127+
- id: rst-directive-colons
128+
- id: rst-inline-touching-normal
129+
# - repo: https://github.com/nbQA-dev/nbQA
130+
# rev: 3e5186603806260939b5f1b0372c058203c65553
131+
# hooks:
132+
# - id: nbqa-black
133+
# additional_dependencies: [jupytext, black] # optional, only if you're using Jupytext
134+
# - id: nbqa-pyupgrade
135+
# args: ["--py37-plus"]
136+
# # - id: nbqa-flake8
137+
# # - id: nbqa-isort
138+
# # args: ["--float-to-top"]
139+
- repo: https://github.com/charliermarsh/ruff-pre-commit
140+
rev: "v0.0.231"
141+
hooks:
142+
- id: ruff

src/kweb/main.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
from fastapi import FastAPI, WebSocket, Request
1+
from pathlib import Path
2+
3+
from fastapi import FastAPI, Request, WebSocket
24
from fastapi.responses import HTMLResponse
35
from fastapi.staticfiles import StaticFiles
46
from fastapi.templating import Jinja2Templates
5-
from kweb.server import LayoutViewServer
6-
from pathlib import Path
77

8+
from kweb.server import LayoutViewServer
89

910
module_path = Path(__file__).parent.absolute()
10-
home_path = Path.home() / ".gdsfactory"
11+
home_path = Path.home() / ".gdsfactory" / "extra"
1112

1213
app = FastAPI()
1314
app.mount("/static", StaticFiles(directory=module_path / "static"), name="static")
1415

1516
gdsfiles = StaticFiles(directory=home_path)
1617
app.mount("/gds_files", gdsfiles, name="gds_files")
17-
templates = Jinja2Templates(directory=module_path/"templates")
18+
templates = Jinja2Templates(directory=module_path / "templates")
1819

1920

2021
@app.get("/")
2122
async def root():
22-
return {"message": "Welcome to kweb visualizer: \n go to http://127.0.0.1:8000/gds/wg"}
23+
return {
24+
"message": "Welcome to kweb visualizer: \n go to http://127.0.0.1:8000/gds/wg"
25+
}
2326

2427

2528
@app.get("/gds/{id}", response_class=HTMLResponse)

src/kweb/server.py

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/usr/bin/env python3
22

33
import asyncio
4-
from fastapi import WebSocket
5-
import time
64
import json
75

86
# NOTE: import db to enable stream format readers
97
import klayout.db as db
108
import klayout.lay as lay
9+
from fastapi import WebSocket
1110

1211
host = "localhost"
1312
port = 8765
@@ -17,7 +16,7 @@
1716
)
1817

1918

20-
class LayoutViewServer(object):
19+
class LayoutViewServer:
2120
def __init__(self, url):
2221
self.layout_view = None
2322
self.url = url
@@ -42,22 +41,22 @@ def annotation_dump(self):
4241

4342
def layer_dump(self):
4443
js = []
45-
for l in self.layout_view.each_layer():
44+
for layer in self.layout_view.each_layer():
4645
js.append(
4746
{
48-
"dp": l.eff_dither_pattern(),
49-
"ls": l.eff_line_style(),
50-
"c": l.eff_fill_color(),
51-
"fc": l.eff_frame_color(),
52-
"m": l.marked,
53-
"s": l.source,
54-
"t": l.transparent,
55-
"va": l.valid,
56-
"v": l.visible,
57-
"w": l.width,
58-
"x": l.xfill,
59-
"name": l.name,
60-
"id": l.id(),
47+
"dp": layer.eff_dither_pattern(),
48+
"ls": layer.eff_line_style(),
49+
"c": layer.eff_fill_color(),
50+
"fc": layer.eff_frame_color(),
51+
"m": layer.marked,
52+
"s": layer.source,
53+
"t": layer.transparent,
54+
"va": layer.valid,
55+
"v": layer.visible,
56+
"w": layer.width,
57+
"x": layer.xfill,
58+
"name": layer.name,
59+
"id": layer.id(),
6160
}
6261
)
6362
return js
@@ -78,7 +77,7 @@ async def connection(self, websocket: WebSocket, path: str = None) -> None:
7877
)
7978
)
8079

81-
writer_task = asyncio.create_task(self.timer(websocket))
80+
asyncio.create_task(self.timer(websocket))
8281
reader_task = asyncio.create_task(self.reader(websocket))
8382
await reader_task
8483

src/kweb/server_jupyter.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
2+
23
import uvicorn
4+
35
from kweb.main import app
46

57
jupyter_server = None

src/kweb/static/client.css

-1
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,3 @@ div .menu-right-frame {
8686
.layer-visible-cell {
8787
padding-right: 0.5rem;
8888
}
89-

src/kweb/static/client.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function showMenu(modes, annotations) {
172172
inner.className = "checked";
173173
socket.send(JSON.stringify({ msg: "select-mode", value: m }));
174174
};
175-
175+
176176
cell.appendChild(inner);
177177
modeRow.appendChild(cell);
178178

@@ -209,7 +209,7 @@ function showMenu(modes, annotations) {
209209
socket.send(JSON.stringify({ msg: "clear-annotations" }));
210210
};
211211
cell.appendChild(clearRulers);
212-
212+
213213
var index = 0;
214214

215215
annotations.forEach(function(a) {
@@ -254,15 +254,15 @@ function showLayers(layers) {
254254
inner.onclick = function() {
255255
var checked = this.checked;
256256
visibilityCheckboxes.forEach(function(cb) {
257-
cb.checked = checked;
257+
cb.checked = checked;
258258
});
259259
socket.send(JSON.stringify({ msg: "layer-v-all", value: checked }));
260260
};
261261
cell.appendChild(inner);
262262

263263
layerRow.appendChild(cell);
264264
layerTable.appendChild(layerRow);
265-
265+
266266
// create table rows for each layer
267267

268268
layers.forEach(function(l) {
@@ -272,7 +272,7 @@ function showLayers(layers) {
272272

273273
cell = document.createElement("td");
274274
cell.className = "layer-visible-cell";
275-
275+
276276
inner = document.createElement("input");
277277
visibilityCheckboxes.push(inner);
278278
inner.type = "checkbox";
@@ -296,12 +296,12 @@ function showLayers(layers) {
296296
s += "background: #" + (l.c & 0xffffff).toString(16) + ";";
297297
inner.style = s;
298298
cell.appendChild(inner);
299-
299+
300300
cell = document.createElement("td");
301301
cell.className = "layer-name-cell";
302302
cell.textContent = (l.name != 0 ? l.name : l.s);
303303
layerRow.appendChild(cell);
304-
304+
305305
layerTable.appendChild(layerRow);
306306

307307
});
@@ -352,4 +352,3 @@ canvas.addEventListener('wheel', function (evt) {
352352
sendWheelEvent(canvas, "wheel", evt);
353353
evt.preventDefault();
354354
}, false);
355-

src/kweb/templates/client.html

-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,3 @@
3030

3131
</body>
3232
</html>
33-

0 commit comments

Comments
 (0)