Skip to content

Commit

Permalink
Ruff fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
timvink authored Sep 2, 2024
1 parent 4bfe2d2 commit cc8cab7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ extend-exclude = [
#supported for python 3.10
target-version = "py310"

# Always autofix
fix = true

[tool.uv]
dev-dependencies = [
"ruff",
Expand Down
6 changes: 3 additions & 3 deletions src/mkdocs_table_reader_plugin/markdown.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import re
from typing import Dict
import pandas as pd
import textwrap

import pandas as pd


def replace_unescaped_pipes(text: str) -> str:
"""
Expand All @@ -19,7 +19,7 @@ def replace_unescaped_pipes(text: str) -> str:
return re.sub(r"(?<!\\)\|", "\\|", text)


def convert_to_md_table(df: pd.DataFrame, **markdown_kwargs: Dict) -> str:
def convert_to_md_table(df: pd.DataFrame, **markdown_kwargs: dict) -> str:
"""
Convert dataframe to markdown table using tabulate.
"""
Expand Down
8 changes: 4 additions & 4 deletions src/mkdocs_table_reader_plugin/plugin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import re

from mkdocs.plugins import BasePlugin, get_plugin_logger
from mkdocs.config import config_options
from mkdocs.exceptions import ConfigurationError
from mkdocs.plugins import BasePlugin, get_plugin_logger

from mkdocs_table_reader_plugin.markdown import add_indentation, convert_to_md_table, fix_indentation
from mkdocs_table_reader_plugin.readers import MACROS, READERS
from mkdocs_table_reader_plugin.safe_eval import parse_argkwarg
from mkdocs_table_reader_plugin.readers import READERS, MACROS
from mkdocs_table_reader_plugin.markdown import fix_indentation, add_indentation, convert_to_md_table

logger = get_plugin_logger("table-reader")

Expand Down Expand Up @@ -138,7 +138,7 @@ def on_page_markdown(self, markdown, page, config, files, **kwargs):
# match group 0: to extract any leading whitespace
# match group 1: to extract the arguments (positional and keywords)
tag_pattern = re.compile(
r"( *)\{\{\s+%s\((.+)\)\s+\}\}" % reader, flags=re.IGNORECASE
r"( *)\{\{\s+%s\((.+)\)\s+\}\}" % reader, flags=re.IGNORECASE # noqa: UP031
)
matches = re.findall(tag_pattern, markdown)

Expand Down
16 changes: 8 additions & 8 deletions src/mkdocs_table_reader_plugin/readers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pandas as pd
import yaml
import functools
import logging
import os
from pathlib import Path
import logging

import functools
import pandas as pd
import yaml

from mkdocs_table_reader_plugin.utils import kwargs_in_func, kwargs_not_in_func
from mkdocs_table_reader_plugin.markdown import convert_to_md_table
from mkdocs_table_reader_plugin.utils import kwargs_in_func, kwargs_not_in_func

logger = logging.getLogger("mkdocs.plugins")

Expand Down Expand Up @@ -134,14 +134,14 @@ def read_excel(*args, **kwargs) -> str:
@ParseArgs
def pd_read_yaml(*args, **kwargs) -> str:
json_kwargs = kwargs_in_func(kwargs, pd.json_normalize)
with open(args[0], "r") as f:
with open(args[0]) as f:
df = pd.json_normalize(yaml.safe_load(f), **json_kwargs)
return df

@ParseArgs
def read_yaml(*args, **kwargs) -> str:
json_kwargs = kwargs_in_func(kwargs, pd.json_normalize)
with open(args[0], "r") as f:
with open(args[0]) as f:
df = pd.json_normalize(yaml.safe_load(f), **json_kwargs)

markdown_kwargs = kwargs_not_in_func(kwargs, pd.json_normalize)
Expand Down Expand Up @@ -170,7 +170,7 @@ def read_raw(*args, **kwargs) -> str:
Returns:
str: file contents
"""
with open(args[0], "r") as f:
with open(args[0]) as f:
return f.read()


Expand Down
3 changes: 1 addition & 2 deletions src/mkdocs_table_reader_plugin/safe_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ def parse_argkwarg(input_str: str):
else:
if len(kwargs) != 0:
raise AssertionError(
"[table-reader-plugin] Make sure the python in your reader tag is correct: Positional arguments follow keyword arguments in '%s'"
% input_str
f"[table-reader-plugin] Make sure the python in your reader tag is correct: Positional arguments follow keyword arguments in '{input_str}'"
)
args.append(literal_eval(i))

Expand Down

0 comments on commit cc8cab7

Please sign in to comment.