@@ -218,16 +218,22 @@ def cloudspace_dispatch(
218218 # Dispatch in four phases: resolution, validation, spec creation, API transactions
219219 # Resolution
220220 root = self ._resolve_root ()
221- repo = self ._resolve_repo (root )
221+ # If the root will already be there, we don't need to upload and preserve the absolute entrypoint
222+ absolute_entrypoint = str (root ).startswith ("/project" )
223+ # If system customization files found, it will set their location path
224+ sys_customizations_root = self ._resolve_env_root ()
225+ repo = self ._resolve_repo (
226+ root ,
227+ default_ignore = False ,
228+ package_source = not absolute_entrypoint ,
229+ sys_customizations_root = sys_customizations_root ,
230+ )
222231 project = self ._resolve_project (project_id = project_id )
223232 existing_instances = self ._resolve_run_instances_by_name (project_id , name )
224233 name = self ._resolve_run_name (name , existing_instances )
225234 cloudspace = self ._resolve_cloudspace (project_id , cloudspace_id )
226235 queue_server_type = self ._resolve_queue_server_type ()
227236
228- # If system customization files found, it will set their location path
229- sys_customizations_sync_root = self ._resolve_env_root ()
230-
231237 self .app ._update_index_file ()
232238
233239 # Validation
@@ -241,17 +247,26 @@ def cloudspace_dispatch(
241247 flow_servers = self ._get_flow_servers ()
242248 network_configs = self ._get_network_configs (flow_servers )
243249 works = self ._get_works (cloudspace = cloudspace )
244- run_body = self ._get_run_body (cluster_id , flow_servers , network_configs , works , False , root , True )
250+ run_body = self ._get_run_body (
251+ cluster_id ,
252+ flow_servers ,
253+ network_configs ,
254+ works ,
255+ False ,
256+ root ,
257+ True ,
258+ True ,
259+ absolute_entrypoint ,
260+ )
245261 env_vars = self ._get_env_vars (self .env_vars , self .secrets , self .run_app_comment_commands )
246262
247- # If the system customization root is set, prepare files for environment synchronization
248- if sys_customizations_sync_root is not None :
249- repo .prepare_sys_customizations_sync (sys_customizations_sync_root )
250-
251263 # API transactions
264+ logger .info (f"Creating cloudspace run. run_body: { run_body } " )
252265 run = self ._api_create_run (project_id , cloudspace_id , run_body )
266+
253267 self ._api_package_and_upload_repo (repo , run )
254268
269+ logger .info (f"Creating cloudspace run instance. name: { name } " )
255270 run_instance = self ._api_create_run_instance (
256271 cluster_id ,
257272 project_id ,
@@ -454,6 +469,9 @@ def _resolve_repo(
454469 self ,
455470 root : Path ,
456471 ignore_functions : Optional [List [_IGNORE_FUNCTION ]] = None ,
472+ default_ignore : bool = True ,
473+ package_source : bool = True ,
474+ sys_customizations_root : Optional [Path ] = None ,
457475 ) -> LocalSourceCodeDir :
458476 """Gather and merge all lightningignores from the app children and create the ``LocalSourceCodeDir``
459477 object."""
@@ -470,7 +488,13 @@ def _resolve_repo(
470488 patterns = _parse_lightningignore (merged )
471489 ignore_functions = [* ignore_functions , partial (_filter_ignored , root , patterns )]
472490
473- return LocalSourceCodeDir (path = root , ignore_functions = ignore_functions )
491+ return LocalSourceCodeDir (
492+ path = root ,
493+ ignore_functions = ignore_functions ,
494+ default_ignore = default_ignore ,
495+ package_source = package_source ,
496+ sys_customizations_root = sys_customizations_root ,
497+ )
474498
475499 def _resolve_project (self , project_id : Optional [str ] = None ) -> V1Membership :
476500 """Determine the project to run on, choosing a default if multiple projects are found."""
@@ -785,7 +809,7 @@ def _get_works(self, cloudspace: Optional[V1CloudSpace] = None) -> List[V1Work]:
785809 network_config = [V1NetworkConfig (name = random_name , port = work .port )],
786810 data_connection_mounts = data_connection_mounts ,
787811 )
788- works .append (V1Work (name = work .name , spec = work_spec ))
812+ works .append (V1Work (name = work .name , display_name = work . display_name , spec = work_spec ))
789813
790814 return works
791815
@@ -798,12 +822,18 @@ def _get_run_body(
798822 no_cache : bool ,
799823 root : Path ,
800824 start_server : bool ,
825+ should_mount_cloudspace_content : bool = False ,
826+ absolute_entrypoint : bool = False ,
801827 ) -> CloudspaceIdRunsBody :
802828 """Get the specification of the run creation request."""
803- # The entry point file needs to be relative to the root of the uploaded source file directory,
804- # because the backend will invoke the lightning commands relative said source directory
805- # TODO: we shouldn't set this if the entrypoint isn't a file but the backend gives an error if we don't
806- app_entrypoint_file = Path (self .entrypoint ).absolute ().relative_to (root )
829+ if absolute_entrypoint :
830+ # If the entrypoint will already exist in the cloud then we can choose to keep it as an absolute path.
831+ app_entrypoint_file = Path (self .entrypoint ).absolute ()
832+ else :
833+ # The entry point file needs to be relative to the root of the uploaded source file directory,
834+ # because the backend will invoke the lightning commands relative said source directory
835+ # TODO: we shouldn't set this if the entrypoint isn't a file but the backend gives an error if we don't
836+ app_entrypoint_file = Path (self .entrypoint ).absolute ().relative_to (root )
807837
808838 run_body = CloudspaceIdRunsBody (
809839 cluster_id = cluster_id ,
@@ -813,6 +843,7 @@ def _get_run_body(
813843 network_config = network_configs ,
814844 works = works ,
815845 local_source = True ,
846+ should_mount_cloudspace_content = should_mount_cloudspace_content ,
816847 )
817848
818849 if self .app is not None :
@@ -827,9 +858,10 @@ def _get_run_body(
827858 # if requirements file at the root of the repository is present,
828859 # we pass just the file name to the backend, so backend can find it in the relative path
829860 requirements_file = root / "requirements.txt"
830- if requirements_file .is_file ():
861+ if requirements_file .is_file () and requirements_file .exists ():
862+ requirements_path = requirements_file if absolute_entrypoint else "requirements.txt"
831863 run_body .image_spec = Gridv1ImageSpec (
832- dependency_file_info = V1DependencyFileInfo (package_manager = V1PackageManager .PIP , path = "requirements.txt" )
864+ dependency_file_info = V1DependencyFileInfo (package_manager = V1PackageManager .PIP , path = requirements_path )
833865 )
834866 if not DISABLE_DEPENDENCY_CACHE and not no_cache :
835867 # hash used for caching the dependencies
@@ -997,7 +1029,10 @@ def _api_create_run_instance(
9971029 )
9981030
9991031 @staticmethod
1000- def _api_package_and_upload_repo (repo : LocalSourceCodeDir , run : V1LightningRun ) -> None :
1032+ def _api_package_and_upload_repo (
1033+ repo : LocalSourceCodeDir ,
1034+ run : V1LightningRun ,
1035+ ) -> None :
10011036 """Package and upload the provided local source code directory to the provided run."""
10021037 if run .source_upload_url == "" :
10031038 raise RuntimeError ("The source upload url is empty." )
0 commit comments