App: Enable bundling addtional files into app source (#18980)

This commit is contained in:
Ethan Harris 2023-11-10 09:12:54 +00:00 committed by GitHub
parent 1c86011dab
commit a9d427c4f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -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)