From 42fc1e1cf82a81ddc523222b92f6e972de703b64 Mon Sep 17 00:00:00 2001 From: Tim Rid <6593626+timrid@users.noreply.github.com> Date: Mon, 17 Mar 2025 20:33:11 +0100 Subject: [PATCH] Add processing of .pth files from "app_packages". --- {{ cookiecutter.format }}/src/sitecustomize.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 {{ cookiecutter.format }}/src/sitecustomize.py diff --git a/{{ cookiecutter.format }}/src/sitecustomize.py b/{{ cookiecutter.format }}/src/sitecustomize.py new file mode 100644 index 0000000..a8e8e75 --- /dev/null +++ b/{{ cookiecutter.format }}/src/sitecustomize.py @@ -0,0 +1,18 @@ +# A site customization that processes .pth files from "app_packages". +import os +import sys +import site + +# Add the "app_packages" directory to the path and process its .pth files. +site.addsitedir(os.path.join(os.path.dirname(__file__), "app_packages")) + +# Call the next sitecustomize script if there is one +# (https://nedbatchelder.com/blog/201001/running_code_at_python_startup.html). +del sys.modules["sitecustomize"] +this_dir = os.path.dirname(__file__) +path_index = sys.path.index(this_dir) +del sys.path[path_index] +try: + import sitecustomize # noqa: F401 +finally: + sys.path.insert(path_index, this_dir) \ No newline at end of file