Skip to content

Commit

Permalink
Merge pull request #76 from timvink/73_filter_tables
Browse files Browse the repository at this point in the history
Use `pyproject.toml`  syntax
  • Loading branch information
timvink authored Sep 2, 2024
2 parents 6fdf150 + cc8cab7 commit a253d99
Show file tree
Hide file tree
Showing 14 changed files with 681 additions and 62 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ jobs:
- name: Make sure unit tests succeed
run: |
pip install -r tests/test_requirements.txt
pip install .
pip install ".[dev]"
pytest
- name: Build
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Static code checking with pyflakes
run: |
pip install pyflakes
pyflakes mkdocs_table_reader_plugin
- name: Run unit tests
run: |
pip install -r tests/test_requirements.txt
pip install -e .
pip install ".[dev]"
pytest --cov=mkdocs_table_reader_plugin --cov-report=xml
- name: Upload coverage to Codecov
Expand Down
Empty file.
117 changes: 117 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
[build-system]
requires = ["setuptools>=70.0", "setuptools-scm>=8.0"]
build-backend = "setuptools.build_meta"

[project.entry-points."mkdocs.plugins"]
"table-reader" = "mkdocs_table_reader_plugin.plugin:TableReaderPlugin"

[project]
name="mkdocs_table_reader_plugin"
keywords = ["mkdocs", "plugin"]
authors = [
{ name = "Tim Vink", email = "[email protected]" }
]
license = { text = "MIT" }

description="MkDocs plugin to directly insert tables from files into markdown."
readme = { file = "README.md", content-type = "text/markdown" }

requires-python=">=3.8"

classifiers=[
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"License :: OSI Approved :: MIT License",
]

dynamic = ["version","dependencies","optional-dependencies"]

[project.urls]
"Homepage" = "https://github.com/timvink/mkdocs-table-reader-plugin"

[tool.setuptools.dynamic]
version = {attr = "mkdocs_table_reader_plugin.__version__"}

dependencies={file = ["requirements.txt"]}

optional-dependencies.dev={file = ["requirements_dev.txt"]}
optional-dependencies.base={file = ["requirements.txt"]}
optional-dependencies.all={file = ["requirements.txt", "requirements_dev.txt"]}

[tool.pytest.ini_options]
markers = [
"integration: marks tests as integration, meaning they use databases (deselect with '-m \"not integration\"')",
"serial",
"no_temp_caching",
]

# https://github.com/charliermarsh/ruff
[tool.ruff]

# Rules to apply
lint.select= ["E", "F", "I", "UP"]

# Exclude rules
lint.ignore = ['D104'
,'D212'
,'D200'
,'D412'
,'E731'
,'E501'
,'E722'
,'D104'
,'E402'
,"UP038" # UP038 Use `X | Y` in `isinstance` call instead of `(X, Y)`
]

# Exclude files in tests dir
lint.exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]

# Set line length, keep same as black
line-length = 120

extend-exclude = [
"*.yml",
"*.toml",
"*.md",
".json",
"Makefile",
"*.txt",
]

#supported for python 3.10
target-version = "py310"

# Always autofix
fix = true

[tool.uv]
dev-dependencies = [
"ruff",
]
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mkdocs>=1.0
pandas>=1.1
tabulate>=0.8.7
PyYAML>=5.4.1
2 changes: 1 addition & 1 deletion tests/test_requirements.txt → requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ xlrd>=1.0.0
openpyxl
pyarrow
# linting
pyflakes
ruff
# documentation
mkdocs-macros-plugin
mkdocs-material
Expand Down
35 changes: 0 additions & 35 deletions setup.py

This file was deleted.

1 change: 1 addition & 0 deletions src/mkdocs_table_reader_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "3.1.0"
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
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
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
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
File renamed without changes.
Loading

0 comments on commit a253d99

Please sign in to comment.