Skip to content

Commit

Permalink
refc: Replace black with ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
yaugenst-flex committed May 31, 2024
1 parent aefb080 commit f55fc2c
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ jobs:
#----------------------------------------------
- name: Run tests
run: |
poetry run black . --check --diff
poetry run ruff format . --check --diff
poetry run ruff check tidy3d --fix --exit-non-zero-on-fix
poetry run pytest -rA tests
poetry run pytest -rA tests/_test_data/_test_datasets_no_vtk.py
2 changes: 1 addition & 1 deletion .github/workflows/update_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
- name: Run tests
run: |
source $VENV
black . --check --diff
ruff format . --check --diff
ruff check tidy3d --fix --exit-non-zero-on-fix
coverage run -m pytest -rA tests
coverage report -m
Expand Down
11 changes: 3 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
repos:
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
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. >>>

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.3.2"
rev: "v0.2.2"
hooks:
- id: ruff
args: [ --fix ]
args: [ --fix ]
- id: ruff-format
43 changes: 22 additions & 21 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 22 additions & 36 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ joblib = "*"
# development core
bump-my-version = {version="*", optional = true}
black = {version="23.12.1", optional = true}
ruff = {version="0.2.2", optional = true}
coverage = {version="*", optional = true}
dill = {version="*", optional = true}
ipython = {version="*", optional = true}
Expand All @@ -60,10 +61,8 @@ pre-commit = {version="*", optional = true}
pylint = {version="*", optional = true}
pytest = {version="*", optional = true}
pytest-timeout = {version="*", optional = true}
ruff = {version="0.3.2", optional = true}
tox = {version="*", optional = true}


# gdspy
gdspy = {version="*", optional = true}

Expand Down Expand Up @@ -111,8 +110,8 @@ devsim = {version="*", optional = true}
cma = {version="*", optional = true}

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

[tool.black]
target-version = ["py39"]
line-length = 100
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
'''

extend-exclude = "docs/faq/|docs/notebooks/"

[tool.ruff]
lint.ignore-init-module-imports = true
lint.typing-modules = ["tidy3d.components.types"] # without this Literal["something fails"]
target-version = "py39"
line-length = 100
fix = true
lint.ignore = [
"E501", # line too long, handled by black
extend-exclude = ["docs/faq/", "docs/notebooks/"]

[tool.ruff.lint]
ignore-init-module-imports = true
typing-modules = ["tidy3d.components.types"] # without this Literal["something fails"]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"C", # flake8-comprehensions
"B", # flake8-bugbear
"UP",
"NPY201", # numpy 2.* compatibility check
]
ignore = [
"E501",
"B008", # do not perform function calls in argument defaults
"C901", # too complex
"UP007", # use x | y instead of union[x,y] (does not work)
Expand All @@ -177,16 +175,6 @@ lint.ignore = [
"UP035", # TODO decide what to do here
]

lint.select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"C", # flake8-comprehensions
"B", # flake8-bugbear
"UP",
"NPY201", # numpy 2.* compatibility check
]

[tool.bumpversion]
current_version = "2.7.0rc2"
parse = """(?x)
Expand Down Expand Up @@ -228,5 +216,3 @@ replace = "\nversion = \"{new_version}\""
filename = "tidy3d/version.py"
search = "{current_version}"
replace = "{new_version}"

target-version = "py310"
4 changes: 2 additions & 2 deletions tidy3d/components/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2859,7 +2859,7 @@ def _get_numpy_array(data_array: Union[ArrayLike, DataArray, UnstructuredGridDat


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


def _ones_like(
data_array: Union[ArrayLike, xr.DataArray, UnstructuredGridDataset]
data_array: Union[ArrayLike, xr.DataArray, UnstructuredGridDataset],
) -> Union[ArrayLike, xr.DataArray, UnstructuredGridDataset]:
"""Get a unity replica of dataarray/dataset."""
if isinstance(data_array, UnstructuredGridDataset):
Expand Down
4 changes: 1 addition & 3 deletions tidy3d/components/grid/mesher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,9 +1129,7 @@ def fun_scale(new_scale):
if isclose(new_scale, 1.0):
return len_interval - small_dl * (1 + num_step)
return (
len_interval
- small_dl * (1 - new_scale**num_step) / (1 - new_scale)
- small_dl
len_interval - small_dl * (1 - new_scale**num_step) / (1 - new_scale) - small_dl
)

# solve for new scaling factor
Expand Down
2 changes: 1 addition & 1 deletion tidy3d/components/medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ def _validate_isreal_dataarray(dataarray: CustomSpatialDataType) -> bool:

@staticmethod
def _validate_isreal_dataarray_tuple(
dataarray_tuple: Tuple[CustomSpatialDataType, ...]
dataarray_tuple: Tuple[CustomSpatialDataType, ...],
) -> bool:
"""Validate that the dataarray is real"""
return np.all([AbstractCustomMedium._validate_isreal_dataarray(f) for f in dataarray_tuple])
Expand Down
4 changes: 2 additions & 2 deletions tidy3d/components/parameter_perturbation.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def ensure_temp_in_range(
sample: Callable[
Union[ArrayLike[float], CustomSpatialDataType],
Union[ArrayLike[float], ArrayLike[Complex], CustomSpatialDataType],
]
],
) -> Callable[
Union[ArrayLike[float], CustomSpatialDataType],
Union[ArrayLike[float], ArrayLike[Complex], CustomSpatialDataType],
Expand Down Expand Up @@ -418,7 +418,7 @@ def ensure_charge_in_range(
Union[ArrayLike[float], CustomSpatialDataType],
],
Union[ArrayLike[float], ArrayLike[Complex], CustomSpatialDataType],
]
],
) -> Callable[
[
Union[ArrayLike[float], CustomSpatialDataType],
Expand Down
6 changes: 1 addition & 5 deletions tidy3d/plugins/microwave/models/coupled_microstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ def _z0_even_odd(
Q3 = 0.1975 + (16.6 + (8.4 / g) ** 6) ** -0.387 + np.log(g**10 / (1 + (g / 3.4) ** 10)) / 241
Q4 = (2 * Q1 / Q2) * (np.exp(-g) * u**Q3 + (2 - np.exp(-g)) * u**-Q3) ** -1
Q5 = 1.794 + 1.14 * np.log(1 + 0.638 / (g + 0.517 * g**2.43))
Q6 = (
0.2305
+ np.log(g**10 / (1 + (g / 5.8) ** 10)) / 281.3
+ np.log(1 + 0.598 * g**1.154) / 5.1
)
Q6 = 0.2305 + np.log(g**10 / (1 + (g / 5.8) ** 10)) / 281.3 + np.log(1 + 0.598 * g**1.154) / 5.1
Q7 = (10 + 190 * g**2) / (1 + 82.3 * g**3)
Q8 = np.exp(-6.5 - 0.95 * np.log(g) - (g / 0.15) ** 5)
Q9 = np.log(Q7) * (Q8 + 1 / 16.5)
Expand Down

0 comments on commit f55fc2c

Please sign in to comment.