Skip to content

Add ruff.toml, pre-commit #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions .github/workflows/ruff-format.yml

This file was deleted.

21 changes: 11 additions & 10 deletions .github/workflows/ruff-lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ruff lint
name: Ruff lint and format

on:
workflow_dispatch:
Expand All @@ -8,16 +8,17 @@ on:
pull_request:

jobs:
lint:
lint-check:
name: Lint check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install the latest version of uv
uses: astral-sh/setup-uv@v3
- name: Checkout repository
uses: actions/checkout@v4
with:
version: "latest"
submodules: 'recursive'

- name: Ruff lint
run: uv run --group lint -- ruff check
- name: Check lint
run: |
pip install pre-commit==3.6.0
pre-commit install
pre-commit run --all-files --show-diff-on-failure --color=always
41 changes: 34 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.6.1
hooks:
# Run the linter.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
# only include python files
files: \.py$
- id: trailing-whitespace
# only include python files
files: \.py$

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.9.9" # Use the appropriate version
hooks:
- id: ruff
args: [ --fix ]
# Run the formatter.
args: ["--fix"]
- id: ruff
args: ["check", "--select", "I", "--fix"]
- id: ruff-format

- repo: local
hooks:
- id: no-underscore-md
name: "Disallow '_' in Markdown filenames"
language: system
entry: |
bash -c '
# Report the offending files
echo "[pre-commit] ERROR: Found Markdown files with underscores:" >&2
for file in "$@"; do
echo " - $file (use hyphens instead)" >&2
done
exit 1
'
files: '.*\/[^\/]*_[^\/]*\.md$'
exclude: '^\.github/'
types: [file]
1 change: 1 addition & 0 deletions examples/docker/hello_docker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import nemo_run as run


if __name__ == "__main__":
inline_script = run.Script(
inline="""
Expand Down
4 changes: 1 addition & 3 deletions examples/entrypoint/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def train_models_experiment(

with run.Experiment("train_models_experiment") as exp:
for i, (model, optimizer) in enumerate(zip(models, optimizers)):
train = run.Partial(
train_model, model=model, optimizer=optimizer, epochs=epochs, batch_size=batch_size
)
train = run.Partial(train_model, model=model, optimizer=optimizer, epochs=epochs, batch_size=batch_size)

exp.add(train, name=f"train_model_{i}", executor=ctx.executor)

Expand Down
4 changes: 1 addition & 3 deletions examples/entrypoint/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def my_optimizer(
learning_rate: float = 0.001, weight_decay: float = 1e-5, betas: List[float] = [0.9, 0.999]
) -> run.Config[Optimizer]:
"""Create an optimizer configuration."""
return run.Config(
Optimizer, learning_rate=learning_rate, weight_decay=weight_decay, betas=betas
)
return run.Config(Optimizer, learning_rate=learning_rate, weight_decay=weight_decay, betas=betas)


def train_model(
Expand Down
4 changes: 1 addition & 3 deletions examples/entrypoint/task_with_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def my_optimizer(
learning_rate: float = 0.001, weight_decay: float = 1e-5, betas: List[float] = [0.9, 0.999]
) -> run.Config[Optimizer]:
"""Create an optimizer configuration."""
return run.Config(
Optimizer, learning_rate=learning_rate, weight_decay=weight_decay, betas=betas
)
return run.Config(Optimizer, learning_rate=learning_rate, weight_decay=weight_decay, betas=betas)


def train_model(
Expand Down
1 change: 1 addition & 0 deletions examples/hello-world/hello_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import nemo_run as run


# This script defines an experiment that invokes three tasks in parallel, two scripts and a run.Partial.
# The example demonstrates how you can use scripts and run.Partial.
if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion examples/hello-world/simple/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

1 change: 1 addition & 0 deletions nemo_run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from nemo_run.run.experiment import Experiment
from nemo_run.run.plugin import ExperimentPlugin as Plugin


__all__ = [
"autoconvert",
"cli",
Expand Down
2 changes: 2 additions & 0 deletions nemo_run/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import os
import warnings


if "NEMORUN_SHOW_WARNINGS" not in os.environ:
warnings.simplefilter(action="ignore", category=DeprecationWarning)
warnings.simplefilter(action="ignore", category=FutureWarning)

from nemo_run.cli.api import create_cli # noqa: E402


app = create_cli()
1 change: 1 addition & 0 deletions nemo_run/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from nemo_run.core.execution.base import Executor
from nemo_run.core.frontend.console.api import CONSOLE, CustomConfigRepr


F = TypeVar("F", bound=Callable[..., Any])
T = TypeVar("T")
P = ParamSpec("P")
Expand Down
1 change: 1 addition & 0 deletions nemo_run/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)
from nemo_run.cli.cli_parser import parse_cli_args, parse_config, parse_partial


__all__ = [
"create_cli",
"main",
Expand Down
Loading
Loading