Skip to content

Commit

Permalink
update template (#144)
Browse files Browse the repository at this point in the history
* update template

* fix pyproject.toml

* fix linting

* update deps and drop setup.cfg

* fix mypy import error

* fix tests

* drop tmp_dir fixture from dvc

---------

Co-authored-by: daavoo <[email protected]>
Co-authored-by: dberenbaum <[email protected]>
Co-authored-by: Dave Berenbaum <[email protected]>
  • Loading branch information
4 people authored Dec 16, 2023
1 parent f3c3f66 commit 61ee409
Show file tree
Hide file tree
Showing 20 changed files with 261 additions and 331 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/iterative/py-template",
"commit": "0aac03d10cbc7b2f7e144e728de5043b7a3458cb",
"commit": "15ee26df315020399731c6291d61bef81a3fc5d3",
"context": {
"cookiecutter": {
"project_name": "dvc-render",
Expand Down
38 changes: 8 additions & 30 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
default_language_version:
python: python3
repos:
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -23,32 +19,14 @@ repos:
args: ['--fix=lf']
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.7'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies: ["tomli"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear==23.7.10
- flake8-comprehensions==3.14.0
- flake8-debugger==4.1.2
- flake8-string-format==0.3.0
- repo: https://github.com/pycqa/bandit
rev: 1.7.5
hooks:
- id: bandit
args: [-c, pyproject.toml]
additional_dependencies: [".[toml]"]
1 change: 0 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def lint(session: nox.Session) -> None:
args = *(session.posargs or ("--show-diff-on-failure",)), "--all-files"
session.run("pre-commit", "run", *args)
session.run("python", "-m", "mypy")
session.run("python", "-m", "pylint", *locations)


@nox.session
Expand Down
128 changes: 87 additions & 41 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,63 @@ build-backend = "setuptools.build_meta"

[tool.setuptools_scm]

[tool.black]
line-length = 88
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
)/
'''

[tool.isort]
profile = "black"
known_first_party = ["dvc_render"]
line_length = 88
[project]
name = "dvc-render"
description = "Dvc Render"
readme = "README.rst"
license = {text = "Apache-2.0"}
authors = [{ name = "Iterative", email = "[email protected]" }]
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Development Status :: 4 - Beta",
]
requires-python = ">=3.8"
dynamic = ["version"]
dependencies = []

[project.urls]
Issues = "https://github.com/iterative/dvc-render/issues"
Source = "https://github.com/iterative/dvc-render"

[project.optional-dependencies]
table = [
"tabulate>=0.8.7",
"flatten_dict<1,>=0.4.1",
]
markdown = [
"dvc-render[table]",
"matplotlib",
]
docs = [
"mkdocs==1.5.2",
"mkdocs-gen-files==0.5.0",
"mkdocs-material==9.3.1",
"mkdocs-section-index==0.3.6",
"mkdocstrings-python==1.6.3",
]
tests = [
"dvc-render[table]",
"dvc-render[markdown]",
"pytest==7.2.0",
"pytest-sugar==0.9.5",
"pytest-cov==3.0.0",
"pytest-mock==3.8.2",
"mypy==1.2.0",
]
dev = [
"dvc-render[table]",
"dvc-render[markdown]",
"dvc-render[tests]",
"dvc-render[docs]",
]

[tool.setuptools.packages.find]
where = ["src"]
namespaces = false

[tool.pytest.ini_options]
addopts = "-ra"
Expand Down Expand Up @@ -70,27 +105,38 @@ module = [
]
ignore_missing_imports = true

[tool.codespell]
ignore-words-list = " "

[tool.pylint.format]
max-line-length = 88

[tool.pylint.message_control]
enable = ["c-extension-no-member", "no-else-return"]
disable = [
"missing-module-docstring",
"missing-class-docstring",
"invalid-name",
"R0801",
"C0415"
[tool.ruff]
ignore = [
"S101", # assert
"PLR2004", # magic-value-comparison
"PLW2901", # redefined-loop-name
"ISC001", # single-line-implicit-string-concatenation
"SIM105", # suppressible-exception
"SIM108", # if-else-block-instead-of-if-exp
"D203", # one blank line before class
"D213", # multi-line-summary-second-line
"RUF012", # mutable class attributes
"PT007", # value types in pytest.mark.parametrize
]
select = [
"F", "E", "W", "C90", "I", "N", "UP", "YTT", "ASYNC", "S", "BLE", "B", "A", "C4", "T10",
"EXE", "ISC", "ICN", "G", "INP", "PIE", "T20", "PYI", "PT", "Q", "RSE", "RET",
"SLOT", "SIM", "TID", "TCH", "ARG", "PGH", "PLC", "PLE", "PLR", "PLW", "TRY",
"FLY", "PERF101", "RUF",
]
show-source = true
show-fixes = true

[tool.pylint.variables]
dummy-variables-rgx = "_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_"
ignored-argument-names = "_.*|^ignored_|^unused_|args|kwargs"
[tool.ruff.per-file-ignores]
"noxfile.py" = ["D", "PTH"]
"tests/**" = ["S", "ARG001", "ARG002", "ANN"]
"docs/**" = ["INP"]

[tool.codespell]
ignore-words-list = " "
[tool.ruff.lint.flake8-type-checking]
strict = true

[tool.bandit]
exclude_dirs = ["tests"]
skips = ["B101"]
[tool.ruff.lint.isort]
known-first-party = ["{{ cookiecutter.package_name }}"]
78 changes: 0 additions & 78 deletions setup.cfg

This file was deleted.

17 changes: 10 additions & 7 deletions src/dvc_render/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ class Renderer(abc.ABC):

EXTENSIONS: Iterable[str] = {}

def __init__(self, datapoints: List = None, name: str = None, **properties):
def __init__(
self,
datapoints: Optional[List] = None,
name: Optional[str] = None,
**properties,
):
self.datapoints = datapoints or []
self.name = name or ""
self.properties = properties
Expand All @@ -34,12 +39,12 @@ def partial_html(self, **kwargs) -> str:

@property
@abc.abstractmethod
def TYPE(self): # pylint: disable=missing-function-docstring
def TYPE(self): # noqa: N802
raise NotImplementedError

@property
@abc.abstractmethod
def SCRIPTS(self): # pylint: disable=missing-function-docstring
def SCRIPTS(self): # noqa: N802
raise NotImplementedError

@staticmethod
Expand All @@ -58,13 +63,11 @@ def generate_html(self, html_path=None) -> str:
return self.DIV.format(id=div_id, partial=partial)
return ""

def generate_markdown(
self, report_path: Optional[StrPath] = None
) -> str: # pylint: disable=missing-function-docstring
def generate_markdown(self, report_path: Optional[StrPath] = None) -> str: # pylint: disable=missing-function-docstring
"Generate a markdown element"
raise NotImplementedError

@classmethod
def matches(cls, filename, properties) -> bool: # pylint: disable=unused-argument
def matches(cls, filename) -> bool: # pylint: disable=unused-argument
"Check if the Renderer is suitable."
return Path(filename).suffix in cls.EXTENSIONS
4 changes: 2 additions & 2 deletions src/dvc_render/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class DvcRenderException(Exception):
class DvcRenderError(Exception):
pass


class MissingPlaceholderError(DvcRenderException):
class MissingPlaceholderError(DvcRenderError):
def __init__(self, placeholder, template_type):
super().__init__(f"{template_type} template has to contain '{placeholder}'.")
4 changes: 2 additions & 2 deletions src/dvc_render/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from dvc_render.image import ImageRenderer

from .exceptions import DvcRenderException
from .exceptions import DvcRenderError

if TYPE_CHECKING:
from .base import Renderer, StrPath
Expand All @@ -28,7 +28,7 @@
</html>"""


class MissingPlaceholderError(DvcRenderException):
class MissingPlaceholderError(DvcRenderError):
def __init__(self, placeholder):
super().__init__(f"HTML template has to contain '{placeholder}'.")

Expand Down
4 changes: 2 additions & 2 deletions src/dvc_render/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ImageRenderer(Renderer):

EXTENSIONS = {".jpg", ".jpeg", ".gif", ".png", ".svg"}

def partial_html(self, html_path=None, **kwargs) -> str:
def partial_html(self, html_path=None, **kwargs) -> str: # noqa: ARG002
div_content = []
for datapoint in self.datapoints:
src = datapoint[self.SRC_FIELD]
Expand Down Expand Up @@ -50,7 +50,7 @@ def partial_html(self, html_path=None, **kwargs) -> str:
return "\n".join(div_content)
return ""

def generate_markdown(self, report_path=None) -> str:
def generate_markdown(self) -> str: # type: ignore[override]
content = []
for datapoint in self.datapoints:
src = datapoint[self.SRC_FIELD]
Expand Down
2 changes: 1 addition & 1 deletion src/dvc_render/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(
self.name = name
self.fill_value = fill_value

def partial_html(self, **kwargs) -> str:
def partial_html(self, **kwargs) -> str: # noqa: ARG002
return json.dumps(self._get_plotly_data())

def _get_plotly_data(self):
Expand Down
Loading

0 comments on commit 61ee409

Please sign in to comment.