From fd6af64d49d4784e14763c9c884937a340bdd977 Mon Sep 17 00:00:00 2001 From: SaitejaBandari756 Date: Wed, 10 Dec 2025 23:49:12 +0530 Subject: [PATCH] Fixed the good first issue --- docs/source/conf.py | 7 ++-- mypy.ini | 3 ++ pyproject.toml | 3 +- up.py | 99 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 mypy.ini create mode 100644 up.py diff --git a/docs/source/conf.py b/docs/source/conf.py index 04c6a2a..549ee0d 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -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 @@ -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 ------------------------------------------------- diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..6ee2785 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,3 @@ +[mypy] +exclude = venv/|.venv/|build/|dist/ +ignore_missing_imports = True diff --git a/pyproject.toml b/pyproject.toml index cde7907..6eca980 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -40,7 +41,7 @@ norecursedirs = [ "tests/*/data" ] -python_files = "*.py" +#python_files = "*.py" python_classes = "Test" python_functions = "test" diff --git a/up.py b/up.py new file mode 100644 index 0000000..175e01b --- /dev/null +++ b/up.py @@ -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()