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 6, 2024
1 parent 0262c0d commit 43626a7
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 113 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
2 changes: 1 addition & 1 deletion docs/_ext/custom-robots.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def process_robots_txt(app, exception):
# Get the path to the source directory
srcdir = app.builder.srcdir
srcdir = app.builder.srcdir # noqa: F841

# Get the path to the robots.txt file
robots_file = os.path.join(app.outdir, "robots.txt")
Expand Down
60 changes: 31 additions & 29 deletions poetry.lock

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

60 changes: 23 additions & 37 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ responses = "*"
# 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 @@ -57,10 +58,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 @@ -105,12 +104,12 @@ 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',
'vtk', 'devsim', 'cma']
docs = ["jupyter", "jinja2", "nbconvert", "sphinx", "nbsphinx", "ipython", "divparams", "sphinx-copybutton", 'sphinx-favicon', "sphinx-book-theme", "pydata-sphinx-theme", "tmm", "gdstk", "grcwa", "sphinx-sitemap", 'sphinx-notfound-page', "nbdime", "optax", "signac", "sax", "pylint", "jupyterblack", "sphinx-tabs", "sphinxemoji", "myst-parser", "devsim", "cma"]
docs = ["jupyter", "jinja2", "nbconvert", "sphinx", "nbsphinx", "ipython", "divparams", "sphinx-copybutton", 'sphinx-favicon', "sphinx-book-theme", "pydata-sphinx-theme", "tmm", "gdstk", "grcwa", "sphinx-sitemap", 'sphinx-notfound-page', "nbdime", "optax", "signac", "sax", "pylint", "sphinx-tabs", "sphinxemoji", "myst-parser", "devsim", "cma"]
gdspy = ["gdspy"]
gdstk = ["gdstk"]
jax = ["jaxlib", "jax"]
Expand All @@ -134,30 +133,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 @@ -170,16 +168,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 @@ -221,5 +209,3 @@ replace = "\nversion = \"{new_version}\""
filename = "tidy3d/version.py"
search = "{current_version}"
replace = "{new_version}"

target-version = "py310"
2 changes: 1 addition & 1 deletion tests/test_components/test_eme.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ def _get_eme_mode_solver_data():
monitor=monitor,
grid_primal_correction=grid_primal_correction,
grid_dual_correction=grid_dual_correction,
**kwargs
**kwargs,
)


Expand Down
17 changes: 13 additions & 4 deletions tests/test_components/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import numpy as np
import tidy3d as td
from tidy3d.exceptions import SetupError, Tidy3dKeyError, ValidationError
from tidy3d.exceptions import SetupError, Tidy3dKeyError
from tidy3d.components import simulation
from tidy3d.components.simulation import MAX_NUM_SOURCES
from tidy3d.components.scene import MAX_NUM_MEDIUMS, MAX_GEOMETRY_COUNT
Expand Down Expand Up @@ -1278,7 +1278,10 @@ def test_sim_structure_extent(log_capture, box_size, log_level): # noqa F811
],
)
def test_sim_validate_structure_bounds_pml(
log_capture, box_length, absorb_type, log_level # noqa: F811
log_capture, # noqa: F811
box_length,
absorb_type,
log_level,
):
"""Make sure we warn if structure bounds are within the PML exactly to simulation edges."""

Expand Down Expand Up @@ -1594,10 +1597,16 @@ def test_tfsf_boundaries(log_capture): # noqa F811
sources=[source],
boundary_spec=td.BoundarySpec(
x=td.Boundary.bloch_from_source(
source=source, domain_size=0.5 * 1.1, axis=0, medium=None # wrong domain size
source=source,
domain_size=0.5 * 1.1,
axis=0,
medium=None, # wrong domain size
),
y=td.Boundary.bloch_from_source(
source=source, domain_size=0.5 * 1.1, axis=1, medium=None # wrong domain size
source=source,
domain_size=0.5 * 1.1,
axis=1,
medium=None, # wrong domain size
),
z=td.Boundary.pml(),
),
Expand Down
Loading

0 comments on commit 43626a7

Please sign in to comment.