From c50cfe88d670d6365b5cf749c40742830edb6dfd Mon Sep 17 00:00:00 2001 From: Daniil Fajnberg Date: Fri, 27 Oct 2023 12:20:41 +0200 Subject: [PATCH] Add `pytest` to dev dependencies; upgrade dev dependencies; remove unnecessary main test script entrypoint; remove unnecessary line from `.gitignore`; put repo description variable into top-level `__init__.py`; introduce syntax-error as a reminder to fix copyright; add CSS fix for broken inline-code segments; update `index.md` layout; reorder linting script calls and add a bit more output; support Python 3.8+ by default; fix wrong dependency file reference in `pyproject.toml`; add `pytest` config to `pyproject.toml`; call `pytest` in `coverage` config; add a few sensible rule-ignores to `ruff` config --- .gitignore | 3 --- docs/css/extra.css | 3 +++ docs/index.md | 16 +++++++++------- pyproject.toml | 33 ++++++++++++++++++++++++++------- requirements/dev.txt | 5 +++-- scripts/lint.sh | 10 +++++----- src/package_name/__init__.py | 4 ++-- tests/__main__.py | 13 ------------- 8 files changed, 48 insertions(+), 39 deletions(-) delete mode 100644 tests/__main__.py diff --git a/.gitignore b/.gitignore index 9f4c7ab..51c3ea6 100644 --- a/.gitignore +++ b/.gitignore @@ -18,8 +18,5 @@ __pycache__/ *.py[cod] -# Testing: -/.coverage - # Miscellaneous cache: .cache/ diff --git a/docs/css/extra.css b/docs/css/extra.css index e69de29..8337c63 100644 --- a/docs/css/extra.css +++ b/docs/css/extra.css @@ -0,0 +1,3 @@ +.md-typeset code { + word-break: keep-all; /* Prevent inline-code from being broken up. */ +} diff --git a/docs/index.md b/docs/index.md index fc317c8..69ae2df 100644 --- a/docs/index.md +++ b/docs/index.md @@ -4,23 +4,25 @@ --- -| [📑 Documentation][1] | [🧑‍💻 Source Code][2] | [🐛 Bug Tracker][3] | -|-----------------------|------------------------|---------------------| +[📑 Documentation][1]   |   [🧑‍💻 Source Code][2]   |   [🐛 Bug Tracker][3] --- -## Usage - -... - ## Installation `pip install ${REPO_NAME}` +## Usage + +... + ## Dependencies -Python Version ..., OS ... +Python `>=3.8`, OS agnostic +--- + +© 2023 ... [1]: https://${REPO_OWNER_LOWER}.github.io/${REPO_NAME_LOWER} [2]: https://github.com/${REPO_OWNER_LOWER}/${REPO_NAME_LOWER} diff --git a/pyproject.toml b/pyproject.toml index ed9b1d2..8a0ab47 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,10 @@ # Python packaging: # [build-system] -requires = ["setuptools", "setuptools-scm"] +requires = [ + "setuptools", + "setuptools-scm", +] build-backend = "setuptools.build_meta" [project] @@ -14,7 +17,7 @@ authors = [ maintainers = [ { name = ..., email = ... }, ] -requires-python = ">=3.9, <4.0" +requires-python = ">=3.8, <4.0" keywords = [ ... ] @@ -41,14 +44,15 @@ dynamic = [ [project.optional-dependencies] full = [] dev = [ - "black==23.9.1", + "black==23.10.1", "build==1.0.3", "coverage[toml]==7.3.2", "isort==5.12.0", "mkdocs-material==9.4.6", "mkdocstrings[python]==0.23.0", "mypy==1.5.1", - "ruff==0.0.292", + "pytest==7.4.3", + "ruff==0.1.3", ] [project.urls] @@ -57,9 +61,9 @@ dev = [ "Documentation" = "http://${REPO_OWNER_LOWER}.github.io/${REPO_NAME_LOWER}" [tool.setuptools.dynamic] -dependencies = { file = "requirements/common.txt" } +dependencies = { file = "requirements/base.txt" } readme = { file = ["README.md"], content-type = "text/markdown" } -version = {attr = ..."${REPO_NAME}.__version__"} +version = { attr = ..."${REPO_NAME}.__version__" } ######################### # Static type checking: # @@ -75,6 +79,16 @@ strict = true show_error_codes = true plugins = [] +############ +# Testing: # + +[tool.pytest.ini_options] +cache_dir = ".cache/pytest" +addopts = "-ra -v" +testpaths = [ + "tests", +] + ####################### # Unit test coverage: # @@ -84,7 +98,7 @@ source = [ "src/", ] branch = true -command_line = "-m tests" +command_line = "-m pytest -qq" omit = [ ".venv*/*", ] @@ -140,6 +154,7 @@ ignore = [ "ANN101", # Missing type annotation for self in method -> unnecessary "ANN102", # Missing type annotation for cls in classmethod -> unnecessary "ANN401", # Dynamically typed expressions (typing.Any) are disallowed -> we'll use it sparingly + "N818", # Exception name should be named with an Error suffix -> absolutely not ] [tool.ruff.per-file-ignores] @@ -152,7 +167,11 @@ ignore = [ "D100", # Missing docstring in public module "D101", # Missing docstring in public class "D102", # Missing docstring in public method + "D103", # Missing docstring in public function "D104", # Missing docstring in public package + "S101", # Use of `assert` detected + "FBT", # flake8-boolean-trap + "TRY", # tryceratops ] #################### diff --git a/requirements/dev.txt b/requirements/dev.txt index 503774c..4e3752e 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,9 +1,10 @@ -r full.txt -black==23.9.1 +black==23.10.1 build==1.0.3 coverage[toml]==7.3.2 isort==5.12.0 mkdocs-material==9.4.6 mkdocstrings[python]==0.23.0 mypy==1.5.1 -ruff==0.0.292 +pytest==7.4.3 +ruff==0.1.3 diff --git a/scripts/lint.sh b/scripts/lint.sh index 38855d1..0c1e95e 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -5,13 +5,13 @@ source "$(dirname $(realpath $0))/util.sh" echo 'Linting source and test files...' -echo ' isort - consistent imports' -isort src/ tests/ --check-only - -echo ' ruff - extensive linting' +echo ' ruff - Doing extensive linting' ruff src/ tests/ -echo ' black - consistent style' +echo ' black - Ensuring consistent code style' run_and_capture black src/ tests/ --check +echo ' isort - Ensuring consistent import structure' +isort src/ tests/ --check-only + echo -e "${bold_green}No issues found${color_reset}\n" diff --git a/src/package_name/__init__.py b/src/package_name/__init__.py index 38a8f4f..74e0738 100644 --- a/src/package_name/__init__.py +++ b/src/package_name/__init__.py @@ -1,4 +1,4 @@ -__copyright__ = "© 2023 ${REPO_OWNER_TITLE}" +... __copyright__ = "© 2023 ..." __license__ = """Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,5 +16,5 @@ limitations under the License.""" __version__ = "0.0.1" __doc__ = """ -PLACEHOLDER +${REPO_DESCRIPTION} """ diff --git a/tests/__main__.py b/tests/__main__.py deleted file mode 100644 index fa3bae6..0000000 --- a/tests/__main__.py +++ /dev/null @@ -1,13 +0,0 @@ -import sys -import unittest - - -if __name__ == "__main__": - try: - pattern = sys.argv[1] - except IndexError: - pattern = "test*.py" - test_suite = unittest.defaultTestLoader.discover(".", pattern=pattern) - test_runner = unittest.TextTestRunner(resultclass=unittest.TextTestResult) - result = test_runner.run(test_suite) - sys.exit(not result.wasSuccessful())