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.
  • Loading branch information
keith committed Dec 2, 2024
1 parent 5d3d450 commit 0f3327f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 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: '\.(🔥|py)$'
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
6 changes: 3 additions & 3 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 Expand Up @@ -48,9 +50,7 @@ def has_not():
config.test_source_root = os.path.dirname(__file__)

# test_exec_root: The root path where tests should be run.
config.test_exec_root = os.path.join(
config.modular_obj_root, "mojo-stdlib", "test"
)
config.test_exec_root = os.path.join(config.modular_obj_root, "mojo-stdlib", "test")
# External, public Mojo testing configuration
else:
# test_source_root: The root path where tests are located.
Expand Down

0 comments on commit 0f3327f

Please sign in to comment.