Skip to content

Commit

Permalink
ref: ruff linting (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxb2 authored Jul 19, 2023
1 parent f945284 commit a79245a
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 130 deletions.
9 changes: 6 additions & 3 deletions docs_gen_files.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Generate files for mkdocs."""

from pathlib import Path

import mkdocs_gen_files
Expand All @@ -10,12 +12,13 @@ def copy_file(source: Path, out: Path):
source (Path): source file
out (Path): output file (relative to the mkdocs docs/ folder)
"""
with open(source, "rb") as f_source:
with mkdocs_gen_files.open(out, "wb") as f_out:
f_out.write(f_source.read())
with open(source, "rb") as f_source, mkdocs_gen_files.open(out, "wb") as f_out:
f_out.write(f_source.read())


def main():
"""Copy files to docs folder."""

# Copy changelog to docs
copy_file("CHANGELOG.md", "changelog.md")

Expand Down
65 changes: 44 additions & 21 deletions duties.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Project Duties."""

import os
from typing import Tuple
from typing import Optional, Tuple

from duty import duty
from duty.callables import blacken_docs, mkdocs, mypy
Expand Down Expand Up @@ -40,7 +42,7 @@ def fmt_docs(ctx: Context):
ctx.run(
blacken_docs.run("docs/", exts=[".md"]),
nofail=True,
title="Formatting docs",
title="Formatting docs (blacken-docs)",
)


Expand All @@ -51,8 +53,8 @@ def fmt(ctx: Context):
Args:
ctx (Context): the context instance (passed automatically).
"""
ctx.run("isort --ca --profile=black .", title="Sorting imports")
ctx.run("black .", title="Formatting code")
ctx.run("isort --ca --profile=black .", title="Sorting imports (isort)")
ctx.run("black .", title="Formatting code (black)")


@duty(aliases=["check_deps"])
Expand All @@ -63,7 +65,8 @@ def check_dependencies(ctx: Context):
ctx (Context): the context instance (passed automatically).
"""
ctx.run(
"poetry export --only main | safety check --stdin", title="Dependency checking"
"poetry export --only main | safety check --stdin",
title="Dependency checking (safety)",
)


Expand All @@ -74,17 +77,38 @@ def check_types(ctx: Context):
Args:
ctx (Context): the context instance (passed automatically).
"""
ctx.run(mypy.run("typer_config"), title="Type checking", pty=PTY)
ctx.run(mypy.run("typer_config"), title="Type checking (mypy)", pty=PTY)


@duty
def pylint(ctx: Context):
"""Run pylint code linting.
Deprecated: use ruff instead of pylint.
Args:
ctx (Context): the context instance (passed automatically).
"""
ctx.run("pylint typer_config", title="Code linting (pylint)")


@duty
def ruff(ctx: Context):
"""Run ruff code linting.
Args:
ctx (Context): the context instance (passed automatically).
"""
ctx.run("ruff .", title="Code linting (ruff)")


@duty(pre=["ruff"])
def check_quality(ctx: Context):
"""Check the code quality.
Args:
ctx (Context): the context instance (passed automatically).
"""
ctx.run("pylint typer_config", title="Code Linting")


@duty
Expand All @@ -98,7 +122,7 @@ def check_api(ctx: Context) -> None:

ctx.run(
lambda: g_check("typer_config"),
title="Checking for API breaking changes",
title="Checking for API breaking changes (griffe)",
nofail=True,
)

Expand All @@ -119,7 +143,7 @@ def test(ctx: Context):
Args:
ctx (Context): the context instance (passed automatically).
"""
ctx.run("pytest --cov=typer_config --cov-report=xml", title="Testing")
ctx.run("pytest --cov=typer_config --cov-report=xml", title="Testing (pytest)")


@duty
Expand All @@ -136,7 +160,7 @@ def docs(ctx: Context, host: str = "127.0.0.1", port: int = 8000) -> None:
dev_addr=f"{host}:{port}",
watch=["docs", "typer_config", "docs_gen_files.py"],
),
title="Serving documentation",
title="Serving documentation (mkdocs)",
capture=False,
)

Expand All @@ -148,33 +172,32 @@ def changelog(ctx: Context):
Args:
ctx (Context): the context instance (passed automatically).
"""
ctx.run(_changelog, title="Generating changelog")
ctx.run(_changelog, title="Generating changelog (git-changelog)")


@duty()
def release(ctx: Context, version: str = None):
def release(ctx: Context, version: Optional[str] = None):
"""Release a new Python package.
Args:
ctx (Context): The context instance (passed automatically).
version (str, optional): The new version number to use. Defaults to None.
"""
if version is None:
res: Tuple[Changelog, str] = _changelog()
version: str = res[0].versions_list[0].planned_tag
ctx.run(f"poetry version {version}", title="Bumping version")
ctx.run("git add pyproject.toml CHANGELOG.md", title="Staging files")
ctx.run(f"poetry version {version}", title="Bumping version (poetry)")
ctx.run("git add pyproject.toml CHANGELOG.md", title="Staging files (git)")
ctx.run(
["git", "commit", "-m", f"chore: Prepare release {version}"],
title="Committing changes",
title="Committing changes (git)",
pty=PTY,
)
ctx.run("poetry publish --build", title="Publish package")
ctx.run("poetry publish --build", title="Publish package (poetry)")
ctx.run(
f"mike deploy --push --update-aliases {version} latest",
title="Deploying documentation",
title="Deploying documentation (mike)",
)
ctx.run(f"git tag {version}", title="Tagging commit", pty=PTY)
ctx.run("git push", title="Pushing commits", pty=False)
ctx.run("git push --tags", title="Pushing tags", pty=False)
ctx.run(f"git tag {version}", title="Tagging commit (git)", pty=PTY)
ctx.run("git push", title="Pushing commits (git)", pty=False)
ctx.run("git push --tags", title="Pushing tags (git)", pty=False)
46 changes: 46 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,52 @@ profile = "black"
[tool.pylint.format]
max-line-length = "88"

[tool.ruff]
extend-select = [ # https://beta.ruff.rs/docs/rules/
"A",
"ANN",
"ARG",
"B",
"BLE",
"C4",
"D",
"E",
"EM",
"ERA",
"F",
"FA",
"FBT",
"FIX",
"I",
"ISC",
"ICN",
"INP",
"PERF",
"PIE",
"PL",
"PT",
"Q",
"RSE",
"RET",
"RUF",
"S",
"SIM",
"T10",
"T20",
"TCH",
"TD",
"TID",
"YTT"]
extend-ignore = ["D202", "D205", "D107"]

[tool.ruff.extend-per-file-ignores]
"tests/*.py" = ["ANN", "S", "ARG001", "B008"]
"docs_gen_files.py" = ["ANN201"]
"duties.py" = ["ANN201", "ARG001"]

[tool.ruff.pydocstyle]
convention = "google" # Accepts: "google", "numpy", or "pep257".

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Typer Config tests."""
Loading

0 comments on commit a79245a

Please sign in to comment.