From deeafeaed5b5f2ce960a2e599149e3bbddde1f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=87=BA=F0=9F=87=A6=20Sviatoslav=20Sydorenko=20=28?= =?UTF-8?q?=D0=A1=D0=B2=D1=8F=D1=82=D0=BE=D1=81=D0=BB=D0=B0=D0=B2=20=D0=A1?= =?UTF-8?q?=D0=B8=D0=B4=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE=29?= Date: Sat, 28 Dec 2024 16:08:42 +0100 Subject: [PATCH] chore(packaging): Convert project to src-layout (#736) * Drop top import package deprecation warning This patch puts it directly into the check script. In general, it's harmful to have such logic in `__init__.py` since it's executed at import time and would get triggered when interacting with other importables from the same namespace just as well. * Convert project to src-layout This is one of the most resilient Python project structures that offers isolation and prevents accidental local imports during testing [[1]]. [1]: https://blog.ganssle.io/articles/2019/08/test-as-installed.html --- hatch.toml | 7 ++----- hooks/__init__.py | 4 ---- pyproject.toml | 2 +- .../pre_commit_terraform}/terraform_docs_replace.py | 9 +++++++++ 4 files changed, 12 insertions(+), 10 deletions(-) delete mode 100644 hooks/__init__.py rename {hooks => src/pre_commit_terraform}/terraform_docs_replace.py (86%) diff --git a/hatch.toml b/hatch.toml index dca8f8565..053ff6bfb 100644 --- a/hatch.toml +++ b/hatch.toml @@ -1,14 +1,11 @@ [build.targets.sdist] include = [ - 'hooks/*.py', -] -exclude = [ - 'hooks/*.sh', + 'src/', ] [build.targets.wheel] packages = [ - 'hooks/', + 'src/pre_commit_terraform/', ] [metadata.hooks.vcs.urls] diff --git a/hooks/__init__.py b/hooks/__init__.py deleted file mode 100644 index aeb6f9b27..000000000 --- a/hooks/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -print( - '`terraform_docs_replace` hook is DEPRECATED.' - 'For migration instructions see https://github.com/antonbabenko/pre-commit-terraform/issues/248#issuecomment-1290829226' -) diff --git a/pyproject.toml b/pyproject.toml index 20c051ddc..e609e55a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,4 +33,4 @@ file = 'README.md' content-type = 'text/markdown' [project.scripts] -terraform_docs_replace = 'hooks.terraform_docs_replace:main' +terraform_docs_replace = 'pre_commit_terraform.terraform_docs_replace:main' diff --git a/hooks/terraform_docs_replace.py b/src/pre_commit_terraform/terraform_docs_replace.py similarity index 86% rename from hooks/terraform_docs_replace.py rename to src/pre_commit_terraform/terraform_docs_replace.py index a9cf6c9bc..3e10913df 100644 --- a/hooks/terraform_docs_replace.py +++ b/src/pre_commit_terraform/terraform_docs_replace.py @@ -2,6 +2,7 @@ import os import subprocess import sys +import warnings def main(argv=None): @@ -27,6 +28,14 @@ def main(argv=None): parser.add_argument('filenames', nargs='*', help='Filenames to check.') args = parser.parse_args(argv) + warnings.warn( + '`terraform_docs_replace` hook is DEPRECATED.' + 'For migration instructions see ' + 'https://github.com/antonbabenko/pre-commit-terraform/issues/248' + '#issuecomment-1290829226', + category=UserWarning, + ) + dirs = [] for filename in args.filenames: if (os.path.realpath(filename) not in dirs and