Skip to content

Commit

Permalink
Format python with ruff
Browse files Browse the repository at this point in the history
Ruff is a faster and more modern python formatter. This swaps out using
`mojo format` for python with ruff.

Signed-off-by: Keith Smiley <[email protected]>
  • Loading branch information
keith committed Dec 2, 2024
1 parent 5d3d450 commit fba3175
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
8 changes: 7 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
name: mojo-format
entry: mojo format
language: system
files: '\.(mojo|🔥|py)$'
files: '\.(mojo|🔥)$'
stages: [commit]
- id: check-docstrings
name: check-docstrings
Expand All @@ -24,3 +24,9 @@ repos:
hooks:
- id: markdownlint
args: ['--config', 'stdlib/scripts/.markdownlint.yaml', '--fix']
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
2 changes: 1 addition & 1 deletion examples/check_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ def install_if_missing(name: str):
raise ImportError("python not on path" + FIX)
subprocess.check_call([python, "-m", "pip", "install", name])
return
except:
except subprocess.CalledProcessError:
raise ImportError(f"{name} not found" + FIX)
8 changes: 5 additions & 3 deletions examples/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# limitations under the License.
# ===----------------------------------------------------------------------=== #

# ruff: noqa

import os
from pathlib import Path

Expand Down Expand Up @@ -55,9 +57,9 @@
/ "mojo",
)

os.environ[
"MODULAR_MOJO_NIGHTLY_IMPORT_PATH"
] = f"{build_root},{pre_built_packages_path}"
os.environ["MODULAR_MOJO_NIGHTLY_IMPORT_PATH"] = (
f"{build_root},{pre_built_packages_path}"
)

# Pass through several environment variables
# to the underlying subprocesses that run the tests.
Expand Down
2 changes: 1 addition & 1 deletion examples/pymatmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import check_mod

check_mod.install_if_missing("numpy")
import numpy as np
import numpy as np # noqa


class PyMatrix:
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import check_mod

check_mod.install_if_missing("numpy")
import numpy as np
import numpy as np # noqa


def test_interop_func():
Expand Down
2 changes: 2 additions & 0 deletions stdlib/benchmarks/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# limitations under the License.
# ===----------------------------------------------------------------------=== #

# ruff: noqa

import os
from pathlib import Path

Expand Down
2 changes: 2 additions & 0 deletions stdlib/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# limitations under the License.
# ===----------------------------------------------------------------------=== #

# ruff: noqa

import os
import shutil
from pathlib import Path
Expand Down

0 comments on commit fba3175

Please sign in to comment.