Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@

# Redirects for olds pages
# See https://documatt.gitlab.io/sphinx-reredirects/usage.html
redirects = {}
# redirects = {}
redirects: dict[str, str] = {}

# This points to aboutcode.readthedocs.io
# In case of "undefined label" ERRORS check docs on intersphinx to troubleshoot
Expand All @@ -60,8 +61,8 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []

# exclude_patterns = []
exclude_patterns: list[str] = []

# -- Options for HTML output -------------------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[mypy]
exclude = venv/|.venv/|build/|dist/
ignore_missing_imports = True
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ build-backend = "setuptools.build_meta"
fallback_version = "9999.$Format:%h-%cs$"

[tool.pytest.ini_options]
python_files = "test_*.py"
norecursedirs = [
".git",
"bin",
Expand Down Expand Up @@ -40,7 +41,7 @@ norecursedirs = [
"tests/*/data"
]

python_files = "*.py"
#python_files = "*.py"

python_classes = "Test"
python_functions = "test"
Expand Down
99 changes: 99 additions & 0 deletions up.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from __future__ import annotations
import argparse
import shutil
import subprocess
import sys
from pathlib import Path
from typing import List

PYTHON = sys.executable
ROOT = Path(__file__).resolve().parent


def run(cmd: List[str], dry: bool = False):
print("+", " ".join(cmd))
if dry:
return 0
return subprocess.call(cmd)


def ensure(tool: str):
return shutil.which(tool) is not None


def cmd_test(dry):
# pytest preferred
if ensure("pytest"):
return run([PYTHON, "-m", "pytest"], dry)
return run([PYTHON, "-m", "unittest", "discover", "-v"], dry)


def cmd_lint(dry):
if ensure("ruff"):
return run(["ruff", "check", "."], dry)
if ensure("flake8"):
return run(["flake8", "."], dry)
if ensure("pylint"):
# auto-detect python packages in repo
packages = [p.name for p in ROOT.iterdir() if (p / "__init__.py").exists()]
if packages:
return run(["pylint"] + packages, dry)
return run(["pylint", "."], dry)
print("No linter installed.")
return 1


def cmd_format(dry):
if ensure("black"):
return run(["black", "."], dry)
print("Black not installed.")
return 1


def cmd_mypy(dry):
if ensure("mypy"):
return run(["mypy", "."], dry)
print("mypy not installed.")
return 1


def cmd_docs(dry):
if ensure("sphinx-build"):
return run(["sphinx-build", "docs", "docs/_build"], dry)
print("Sphinx not installed.")
return 1


def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"command",
nargs="?",
default="help",
choices=["help", "test", "lint", "format", "mypy", "docs", "all"],
)
parser.add_argument("--dry-run", action="store_true")
args = parser.parse_args()

cmds = {
"test": [cmd_test],
"lint": [cmd_lint],
"format": [cmd_format],
"mypy": [cmd_mypy],
"docs": [cmd_docs],
"all": [cmd_format, cmd_lint, cmd_mypy, cmd_test, cmd_docs],
}

if args.command == "help":
parser.print_help()
return

for task in cmds[args.command]:
rc = task(args.dry_run)
if rc:
sys.exit(rc)

sys.exit(0)

if __name__ == "__main__":
main()