Skip to content

Commit

Permalink
Merge pull request #27 from zph/zh-move-to-ruff
Browse files Browse the repository at this point in the history
zh move to ruff
  • Loading branch information
zph authored Feb 7, 2025
2 parents d7d5ca2 + d4b48f9 commit aa9f82b
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 48 deletions.
12 changes: 4 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ jobs:
- name: initialize folders
# Runbook command comes from .hermit/bin/runbook
run: runbook init --skip-confirmation=true
- name: Black formatting
run: pre-commit run black
- name: jupytext hook
run: pre-commit run jupytext
- name: isort hook
run: pre-commit run isort
- name: autoflake hook
run: pre-commit run autoflake
- name: Ruff formatting
run: pre-commit run ruff-format
- name: Ruff linting
run: pre-commit run ruff
- run: just test
- run: echo "🍏 This job's status is ${{ job.status }}."
34 changes: 7 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,12 @@
repos:
- repo: https://github.com/mwouts/jupytext
rev: v1.14.7 # CURRENT_TAG/COMMIT_HASH
hooks:
- id: jupytext
args: [--pipe, black]
exclude: runbook/data/_template-deno.ipynb|.*\.md|tests/.*
additional_dependencies:
- black==23.3.0 # Matches hook

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
language_version: python3
exclude: runbooks/binder/_template-deno.ipynb

- repo: https://github.com/pycqa/isort
rev: 5.13.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "d7f0995" # 2025-02-07
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
hooks:
- id: autoflake
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variables', '--ignore-init-module-imports']
- id: ruff
args: [--fix]
exclude: runbooks/binder/_template-deno.ipynb
- id: ruff-format
exclude: runbooks/binder/_template-deno.ipynb

- repo: local
hooks:
Expand Down
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ build-backend = "poetry.core.masonry.api"
[dependency-groups]
dev = [
"pytest>=8.3.4",
"ruff>=0.9.5",
]

[tool.poetry.scripts]
Expand All @@ -60,3 +61,14 @@ source = "init"
# https://github.com/python-poetry/poetry/issues/927
# [tool.poetry.plugins."papermill.translators"]
# "typescript" = "translators:runbook.translators.TypescriptTranslator"

[tool.ruff]
line-length = 88 # Same default as Black (adjust if needed)

[tool.ruff.format]
quote-style = "double" # Choose "single" or "double"
indent-style = "space"
line-ending = "lf"

[tool.ruff.lint]
select = ["I"]
1 change: 1 addition & 0 deletions runbook/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import click

from runbook.cli.commands import (
check,
convert,
Expand Down
1 change: 1 addition & 0 deletions runbook/cli/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from os import path

import click

from runbook.cli.completions import EditableNotebook
from runbook.cli.validators import validate_runbook_file_path

Expand Down
1 change: 1 addition & 0 deletions runbook/cli/commands/convert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from os import path

import click

from runbook.cli.completions import EditableNotebook
from runbook.cli.validators import validate_runbook_file_path

Expand Down
2 changes: 1 addition & 1 deletion runbook/cli/commands/create.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from os import path

import click

from runbook.cli.lib import nbconvert_launch_instance
from runbook.cli.validators import validate_create_language, validate_template

Expand All @@ -16,7 +17,6 @@
callback=validate_template,
help="Path to the template file to use",
)

# TODO: switch to language and template defaulting to Deno
# based on operational experience at work
@click.option(
Expand Down
1 change: 1 addition & 0 deletions runbook/cli/commands/diff.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from os import path

import click

from runbook.cli.completions import EditableNotebook
from runbook.cli.validators import validate_runbook_file_path

Expand Down
1 change: 1 addition & 0 deletions runbook/cli/commands/edit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from os import path

import click

from runbook.cli.completions import EditableNotebook
from runbook.cli.validators import validate_runbook_file_path

Expand Down
2 changes: 1 addition & 1 deletion runbook/cli/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from pathlib import Path

import click
from runbook.template import TEMPLATES

from runbook import __version__ as VERSION
from runbook.template import TEMPLATES

RUNBOOK_CONFIG = {"version": 1, "library_version": VERSION, "directory": None}

Expand Down
1 change: 1 addition & 0 deletions runbook/cli/commands/list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click

from runbook.cli.commands.show import get_notebook_header


Expand Down
4 changes: 2 additions & 2 deletions runbook/cli/commands/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

import click
import nbformat
import papermill as pm

from runbook.cli.lib import nbconvert_launch_instance
from runbook.cli.validators import validate_plan_params, validate_runbook_file_path
from runbook.constants import RUNBOOK_METADATA

import papermill as pm


def get_notebook_language(notebook_path: str) -> str:
"""
Expand Down
1 change: 1 addition & 0 deletions runbook/cli/commands/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click

from runbook.cli.validators import validate_planned_runbook_file_path


Expand Down
4 changes: 2 additions & 2 deletions runbook/cli/commands/show.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import click
import nbformat
import papermill as pm
from rich.console import Console
from rich.table import Table

from runbook.cli.commands.plan import get_notebook_language
from runbook.cli.validators import validate_runbook_file_path
from runbook.constants import RUNBOOK_METADATA

import papermill as pm


def get_notebook_header(notebook_path):
"""Get the title (H1) and description (H2) from the notebook's markdown cells.
Expand Down
4 changes: 2 additions & 2 deletions runbook/cli/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def runnable_shell_complete(self, ctx, param, incomplete):
pattern = f"**/{incomplete}*.ipynb"
if incomplete == "":
pattern = f"**/*.ipynb"
pattern = "**/*.ipynb"

return [
CompletionItem(name) for name in glob(pattern, recursive=True) if "runs" in name
Expand All @@ -21,7 +21,7 @@ def runnable_shell_complete(self, ctx, param, incomplete):
def editable_shell_complete(self, ctx, param, incomplete):
pattern = f"**/{incomplete}*.ipynb"
if incomplete == "":
pattern = f"**/*.ipynb"
pattern = "**/*.ipynb"

return [CompletionItem(name) for name in glob(pattern, recursive=True)]

Expand Down
2 changes: 1 addition & 1 deletion runbook/data/_template-python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"outputs": [],
"source": [
"# SHELL HELPERS\n",
"from runbook.shell import shell_builder, gather, confirm, style, quote\n",
"from runbook.shell import confirm, gather, shell_builder, style\n",
"\n",
"sh = shell_builder(\n",
" dry_run, tags_default={\"environment\": \"testing\"}, confirm_default=True\n",
Expand Down
8 changes: 5 additions & 3 deletions runbook/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def read_embedded_file(package: str, filename: str) -> str:
"""
if sys.version_info >= (3, 7):
# Use importlib.resources (Python 3.7+)
with importlib_resources.files(package).joinpath(filename).open(
"r", encoding="utf-8"
) as f:
with (
importlib_resources.files(package)
.joinpath(filename)
.open("r", encoding="utf-8") as f
):
return f.read()
else:
# Use pkgutil.get_data() for older versions
Expand Down
31 changes: 30 additions & 1 deletion uv.lock

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

0 comments on commit aa9f82b

Please sign in to comment.