diff --git a/pyproject.toml b/pyproject.toml index 0b056d7..97a5c6a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,6 +108,9 @@ extend-exclude = [ #supported for python 3.10 target-version = "py310" +# Always autofix +fix = true + [tool.uv] dev-dependencies = [ "ruff", diff --git a/src/mkdocs_table_reader_plugin/markdown.py b/src/mkdocs_table_reader_plugin/markdown.py index bc66c6f..856a3c6 100644 --- a/src/mkdocs_table_reader_plugin/markdown.py +++ b/src/mkdocs_table_reader_plugin/markdown.py @@ -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: """ @@ -19,7 +19,7 @@ def replace_unescaped_pipes(text: str) -> str: return re.sub(r"(? str: +def convert_to_md_table(df: pd.DataFrame, **markdown_kwargs: dict) -> str: """ Convert dataframe to markdown table using tabulate. """ diff --git a/src/mkdocs_table_reader_plugin/plugin.py b/src/mkdocs_table_reader_plugin/plugin.py index 62ab21b..a195d36 100644 --- a/src/mkdocs_table_reader_plugin/plugin.py +++ b/src/mkdocs_table_reader_plugin/plugin.py @@ -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") @@ -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) diff --git a/src/mkdocs_table_reader_plugin/readers.py b/src/mkdocs_table_reader_plugin/readers.py index 2144d62..e60f25d 100644 --- a/src/mkdocs_table_reader_plugin/readers.py +++ b/src/mkdocs_table_reader_plugin/readers.py @@ -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") @@ -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) @@ -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() diff --git a/src/mkdocs_table_reader_plugin/safe_eval.py b/src/mkdocs_table_reader_plugin/safe_eval.py index 24db2f8..c41d541 100644 --- a/src/mkdocs_table_reader_plugin/safe_eval.py +++ b/src/mkdocs_table_reader_plugin/safe_eval.py @@ -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))