Skip to content

Commit f55fc2c

Browse files
committed
refc: Replace black with ruff format
1 parent aefb080 commit f55fc2c

File tree

10 files changed

+56
-80
lines changed

10 files changed

+56
-80
lines changed

.github/workflows/run_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ jobs:
148148
#----------------------------------------------
149149
- name: Run tests
150150
run: |
151-
poetry run black . --check --diff
151+
poetry run ruff format . --check --diff
152152
poetry run ruff check tidy3d --fix --exit-non-zero-on-fix
153153
poetry run pytest -rA tests
154154
poetry run pytest -rA tests/_test_data/_test_datasets_no_vtk.py

.github/workflows/update_coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
- name: Run tests
8383
run: |
8484
source $VENV
85-
black . --check --diff
85+
ruff format . --check --diff
8686
ruff check tidy3d --fix --exit-non-zero-on-fix
8787
coverage run -m pytest -rA tests
8888
coverage report -m

.pre-commit-config.yaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 23.12.1
4-
hooks:
5-
- id: black
6-
name: black <<< NOTE:, if you get a message stating that "All done! n file(s) reformatted", you must git add and commit the changes again to complete the commit. >>>
7-
82
- repo: https://github.com/astral-sh/ruff-pre-commit
9-
rev: "v0.3.2"
3+
rev: "v0.2.2"
104
hooks:
115
- id: ruff
12-
args: [ --fix ]
6+
args: [ --fix ]
7+
- id: ruff-format

poetry.lock

Lines changed: 22 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ joblib = "*"
5252
# development core
5353
bump-my-version = {version="*", optional = true}
5454
black = {version="23.12.1", optional = true}
55+
ruff = {version="0.2.2", optional = true}
5556
coverage = {version="*", optional = true}
5657
dill = {version="*", optional = true}
5758
ipython = {version="*", optional = true}
@@ -60,10 +61,8 @@ pre-commit = {version="*", optional = true}
6061
pylint = {version="*", optional = true}
6162
pytest = {version="*", optional = true}
6263
pytest-timeout = {version="*", optional = true}
63-
ruff = {version="0.3.2", optional = true}
6464
tox = {version="*", optional = true}
6565

66-
6766
# gdspy
6867
gdspy = {version="*", optional = true}
6968

@@ -111,8 +110,8 @@ devsim = {version="*", optional = true}
111110
cma = {version="*", optional = true}
112111

113112
[tool.poetry.extras]
114-
dev = ['bump-my-version', 'black', "coverage", 'dill', 'divparams', 'gdspy', 'gdstk', 'gdstk', 'grcwa', 'ipython', 'ipython', 'jax', 'jaxlib', 'jinja2',
115-
'jupyter', 'jupyterblack', 'myst-parser', 'memory_profiler', 'nbconvert', 'nbdime', 'nbsphinx', 'networkx', 'optax', 'pre-commit',
113+
dev = ['bump-my-version', "coverage", 'dill', 'divparams', 'gdspy', 'gdstk', 'gdstk', 'grcwa', 'ipython', 'ipython', 'jax', 'jaxlib', 'jinja2',
114+
'jupyter', 'myst-parser', 'memory_profiler', 'nbconvert', 'nbdime', 'nbsphinx', 'networkx', 'optax', 'pre-commit',
116115
'pydata-sphinx-theme', 'pylint', 'pyswarms', 'pytest', 'pytest-timeout', 'rtree', 'ruff', 'sax', 'signac', 'sphinx',
117116
'sphinx-book-theme', 'sphinx-copybutton', 'sphinx-favicon', 'sphinx-notfound-page', 'sphinx-sitemap', 'sphinx-tabs', 'sphinxemoji', 'tmm', 'tox', 'trimesh',
118117
'scikit-rf', 'vtk', 'devsim', 'cma']
@@ -141,30 +140,29 @@ requires = ["poetry-core>=1.0.0"]
141140
build-backend = "poetry.core.masonry.api"
142141

143142
[tool.black]
143+
target-version = ["py39"]
144144
line-length = 100
145-
include = '\.pyi?$'
146-
exclude = '''
147-
/(
148-
\.git
149-
| \.hg
150-
| \.mypy_cache
151-
| \.tox
152-
| \.venv
153-
| _build
154-
| buck-out
155-
| build
156-
| dist
157-
)/
158-
'''
159-
145+
extend-exclude = "docs/faq/|docs/notebooks/"
160146

161147
[tool.ruff]
162-
lint.ignore-init-module-imports = true
163-
lint.typing-modules = ["tidy3d.components.types"] # without this Literal["something fails"]
148+
target-version = "py39"
164149
line-length = 100
165-
fix = true
166-
lint.ignore = [
167-
"E501", # line too long, handled by black
150+
extend-exclude = ["docs/faq/", "docs/notebooks/"]
151+
152+
[tool.ruff.lint]
153+
ignore-init-module-imports = true
154+
typing-modules = ["tidy3d.components.types"] # without this Literal["something fails"]
155+
select = [
156+
"E", # pycodestyle errors
157+
"W", # pycodestyle warnings
158+
"F", # pyflakes
159+
"C", # flake8-comprehensions
160+
"B", # flake8-bugbear
161+
"UP",
162+
"NPY201", # numpy 2.* compatibility check
163+
]
164+
ignore = [
165+
"E501",
168166
"B008", # do not perform function calls in argument defaults
169167
"C901", # too complex
170168
"UP007", # use x | y instead of union[x,y] (does not work)
@@ -177,16 +175,6 @@ lint.ignore = [
177175
"UP035", # TODO decide what to do here
178176
]
179177

180-
lint.select = [
181-
"E", # pycodestyle errors
182-
"W", # pycodestyle warnings
183-
"F", # pyflakes
184-
"C", # flake8-comprehensions
185-
"B", # flake8-bugbear
186-
"UP",
187-
"NPY201", # numpy 2.* compatibility check
188-
]
189-
190178
[tool.bumpversion]
191179
current_version = "2.7.0rc2"
192180
parse = """(?x)
@@ -228,5 +216,3 @@ replace = "\nversion = \"{new_version}\""
228216
filename = "tidy3d/version.py"
229217
search = "{current_version}"
230218
replace = "{new_version}"
231-
232-
target-version = "py310"

tidy3d/components/data/dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,7 +2859,7 @@ def _get_numpy_array(data_array: Union[ArrayLike, DataArray, UnstructuredGridDat
28592859

28602860

28612861
def _zeros_like(
2862-
data_array: Union[ArrayLike, xr.DataArray, UnstructuredGridDataset]
2862+
data_array: Union[ArrayLike, xr.DataArray, UnstructuredGridDataset],
28632863
) -> Union[ArrayLike, xr.DataArray, UnstructuredGridDataset]:
28642864
"""Get a zeroed replica of dataarray/dataset."""
28652865
if isinstance(data_array, UnstructuredGridDataset):
@@ -2870,7 +2870,7 @@ def _zeros_like(
28702870

28712871

28722872
def _ones_like(
2873-
data_array: Union[ArrayLike, xr.DataArray, UnstructuredGridDataset]
2873+
data_array: Union[ArrayLike, xr.DataArray, UnstructuredGridDataset],
28742874
) -> Union[ArrayLike, xr.DataArray, UnstructuredGridDataset]:
28752875
"""Get a unity replica of dataarray/dataset."""
28762876
if isinstance(data_array, UnstructuredGridDataset):

tidy3d/components/grid/mesher.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,7 @@ def fun_scale(new_scale):
11291129
if isclose(new_scale, 1.0):
11301130
return len_interval - small_dl * (1 + num_step)
11311131
return (
1132-
len_interval
1133-
- small_dl * (1 - new_scale**num_step) / (1 - new_scale)
1134-
- small_dl
1132+
len_interval - small_dl * (1 - new_scale**num_step) / (1 - new_scale) - small_dl
11351133
)
11361134

11371135
# solve for new scaling factor

tidy3d/components/medium.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ def _validate_isreal_dataarray(dataarray: CustomSpatialDataType) -> bool:
12491249

12501250
@staticmethod
12511251
def _validate_isreal_dataarray_tuple(
1252-
dataarray_tuple: Tuple[CustomSpatialDataType, ...]
1252+
dataarray_tuple: Tuple[CustomSpatialDataType, ...],
12531253
) -> bool:
12541254
"""Validate that the dataarray is real"""
12551255
return np.all([AbstractCustomMedium._validate_isreal_dataarray(f) for f in dataarray_tuple])

tidy3d/components/parameter_perturbation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def ensure_temp_in_range(
7777
sample: Callable[
7878
Union[ArrayLike[float], CustomSpatialDataType],
7979
Union[ArrayLike[float], ArrayLike[Complex], CustomSpatialDataType],
80-
]
80+
],
8181
) -> Callable[
8282
Union[ArrayLike[float], CustomSpatialDataType],
8383
Union[ArrayLike[float], ArrayLike[Complex], CustomSpatialDataType],
@@ -418,7 +418,7 @@ def ensure_charge_in_range(
418418
Union[ArrayLike[float], CustomSpatialDataType],
419419
],
420420
Union[ArrayLike[float], ArrayLike[Complex], CustomSpatialDataType],
421-
]
421+
],
422422
) -> Callable[
423423
[
424424
Union[ArrayLike[float], CustomSpatialDataType],

tidy3d/plugins/microwave/models/coupled_microstrip.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ def _z0_even_odd(
6262
Q3 = 0.1975 + (16.6 + (8.4 / g) ** 6) ** -0.387 + np.log(g**10 / (1 + (g / 3.4) ** 10)) / 241
6363
Q4 = (2 * Q1 / Q2) * (np.exp(-g) * u**Q3 + (2 - np.exp(-g)) * u**-Q3) ** -1
6464
Q5 = 1.794 + 1.14 * np.log(1 + 0.638 / (g + 0.517 * g**2.43))
65-
Q6 = (
66-
0.2305
67-
+ np.log(g**10 / (1 + (g / 5.8) ** 10)) / 281.3
68-
+ np.log(1 + 0.598 * g**1.154) / 5.1
69-
)
65+
Q6 = 0.2305 + np.log(g**10 / (1 + (g / 5.8) ** 10)) / 281.3 + np.log(1 + 0.598 * g**1.154) / 5.1
7066
Q7 = (10 + 190 * g**2) / (1 + 82.3 * g**3)
7167
Q8 = np.exp(-6.5 - 0.95 * np.log(g) - (g / 0.15) ** 5)
7268
Q9 = np.log(Q7) * (Q8 + 1 / 16.5)

0 commit comments

Comments
 (0)