From a9d427c4f8944baa423209a52967a8b865c7a7ae Mon Sep 17 00:00:00 2001 From: Ethan Harris Date: Fri, 10 Nov 2023 09:12:54 +0000 Subject: [PATCH] App: Enable bundling addtional files into app source (#18980) --- src/lightning/app/plugin/plugin.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lightning/app/plugin/plugin.py b/src/lightning/app/plugin/plugin.py index 56a9a9fe19..6f5d7fce72 100644 --- a/src/lightning/app/plugin/plugin.py +++ b/src/lightning/app/plugin/plugin.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import os +import shutil import tarfile import tempfile from pathlib import Path @@ -33,6 +34,7 @@ from lightning.app.utilities.load_app import _load_plugin_from_file logger = Logger(__name__) _PLUGIN_MAX_CLIENT_TRIES: int = 3 +_PLUGIN_INTERNAL_DIR_PATH: str = f"{os.environ.get('HOME', '')}/internal" class LightningPlugin: @@ -169,6 +171,10 @@ def _run_plugin(run: _Run) -> Dict[str, Any]: status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Error loading plugin: {str(ex)}." ) + # Allow devs to add files to the app source + if os.path.isdir(_PLUGIN_INTERNAL_DIR_PATH): + shutil.copytree(_PLUGIN_INTERNAL_DIR_PATH, source_path, dirs_exist_ok=True) + # Ensure that apps are dispatched from the temp directory cwd = os.getcwd() os.chdir(source_path)