From 27d840d67ae17eeeccd30c82c780448028690014 Mon Sep 17 00:00:00 2001 From: psalaberria002 Date: Thu, 20 Jun 2024 15:10:05 +0200 Subject: [PATCH] example --- .gitignore | 2 ++ examples/typical/BUILD.bazel | 4 +++- .../site_packages_extra/lib/python/hello/hello.py | 2 ++ .../typical/site_packages_extra/sitecustomize.py | 12 ++++++++++++ examples/typical/sitecustomize.py | 1 - 5 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 examples/typical/site_packages_extra/lib/python/hello/hello.py create mode 100644 examples/typical/site_packages_extra/sitecustomize.py delete mode 100644 examples/typical/sitecustomize.py diff --git a/.gitignore b/.gitignore index 85f9442..3f932b0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ bazel-* venv/ .venv/ + +__pycache__ diff --git a/examples/typical/BUILD.bazel b/examples/typical/BUILD.bazel index a8d5423..ae3c046 100644 --- a/examples/typical/BUILD.bazel +++ b/examples/typical/BUILD.bazel @@ -14,5 +14,7 @@ create_venv(name = "create-venv") create_venv( name = "create-venv-custom-destination", destination_folder = ".venv", - site_packages_extra_files = ["sitecustomize.py"], + site_packages_extra_files = [ + "site_packages_extra/sitecustomize.py", + ], ) diff --git a/examples/typical/site_packages_extra/lib/python/hello/hello.py b/examples/typical/site_packages_extra/lib/python/hello/hello.py new file mode 100644 index 0000000..40f915d --- /dev/null +++ b/examples/typical/site_packages_extra/lib/python/hello/hello.py @@ -0,0 +1,2 @@ +def hello() -> None: + print("Hello") diff --git a/examples/typical/site_packages_extra/sitecustomize.py b/examples/typical/site_packages_extra/sitecustomize.py new file mode 100644 index 0000000..d1ee6f1 --- /dev/null +++ b/examples/typical/site_packages_extra/sitecustomize.py @@ -0,0 +1,12 @@ +# This file is loaded by the Python interpreter and can alter the Python module loading process. +# We use it to inject lib/python into our PYTHON_PATH so that we can import modules relative to this directory. +import os +import sys + +dirname = os.path.dirname(__file__) +# Add site_packages_extra/lib/python to path so we can import `hello`` without the site_packages_extra.lib.python prefix +sys.path.append( + os.path.abspath(os.path.join(dirname, "../../../../site_packages_extra/lib/python")) +) +# Add repo root to the path +sys.path.append(os.path.abspath(os.path.join(dirname, "../../../.."))) diff --git a/examples/typical/sitecustomize.py b/examples/typical/sitecustomize.py deleted file mode 100644 index 144ad42..0000000 --- a/examples/typical/sitecustomize.py +++ /dev/null @@ -1 +0,0 @@ -# Hola