1818from dstack ._internal .cli .services .profile import apply_profile_args , register_profile_args
1919from dstack ._internal .cli .services .repos import (
2020 get_repo_from_dir ,
21+ get_repo_from_url ,
2122 init_default_virtual_repo ,
2223 is_git_repo_url ,
2324 register_init_repo_args ,
2425)
25- from dstack ._internal .cli .utils .common import confirm_ask , console , warn
26+ from dstack ._internal .cli .utils .common import confirm_ask , console
2627from dstack ._internal .cli .utils .rich import MultiItemStatus
2728from dstack ._internal .cli .utils .run import get_runs_table , print_run_plan
2829from dstack ._internal .core .errors import (
4445 TaskConfiguration ,
4546)
4647from dstack ._internal .core .models .repos import RepoHeadWithCreds
47- from dstack ._internal .core .models .repos .base import Repo
48- from dstack ._internal .core .models .repos .local import LocalRepo
4948from dstack ._internal .core .models .repos .remote import RemoteRepo , RemoteRepoCreds
5049from dstack ._internal .core .models .resources import CPUSpec
5150from dstack ._internal .core .models .runs import JobStatus , JobSubmission , RunSpec , RunStatus
52- from dstack ._internal .core .services .configs import ConfigManager
5351from dstack ._internal .core .services .diff import diff_models
5452from dstack ._internal .core .services .repos import (
5553 InvalidRepoCredentialsError ,
5654 get_repo_creds_and_default_branch ,
57- load_repo ,
5855)
5956from dstack ._internal .utils .common import local_time
6057from dstack ._internal .utils .interpolator import InterpolatorError , VariablesInterpolator
@@ -96,8 +93,9 @@ def apply_configuration(
9693 if conf .working_dir is not None and not is_absolute_posix_path (conf .working_dir ):
9794 raise ConfigurationError ("working_dir must be absolute" )
9895
99- config_manager = ConfigManager ()
100- repo = self .get_repo (conf , configuration_path , configurator_args , config_manager )
96+ repo = self .get_repo (conf , configuration_path , configurator_args )
97+ if repo is None :
98+ repo = init_default_virtual_repo (api = self .api )
10199 profile = load_profile (Path .cwd (), configurator_args .profile )
102100 with console .status ("Getting apply plan..." ):
103101 run_plan = self .api .runs .get_run_plan (
@@ -475,12 +473,11 @@ def get_repo(
475473 conf : RunConfigurationT ,
476474 configuration_path : str ,
477475 configurator_args : argparse .Namespace ,
478- config_manager : ConfigManager ,
479- ) -> Repo :
476+ ) -> Optional [RemoteRepo ]:
480477 if configurator_args .no_repo :
481- return init_default_virtual_repo ( api = self . api )
478+ return None
482479
483- repo : Optional [Repo ] = None
480+ repo : Optional [RemoteRepo ] = None
484481 repo_head : Optional [RepoHeadWithCreds ] = None
485482 repo_branch : Optional [str ] = configurator_args .repo_branch
486483 repo_hash : Optional [str ] = configurator_args .repo_hash
@@ -497,8 +494,6 @@ def get_repo(
497494 local_path : Optional [Path ] = None
498495 # dummy value, safe to join with any path
499496 root_dir = Path ("." )
500- # True if no repo specified, but we found one in `config.yml`
501- legacy_local_path = False
502497 if repo_arg := configurator_args .repo :
503498 if is_git_repo_url (repo_arg ):
504499 url = repo_arg
@@ -521,84 +516,49 @@ def get_repo(
521516 if repo_hash is None :
522517 repo_hash = repo_spec .hash
523518 else :
524- local_path = Path . cwd ()
525- legacy_local_path = True
519+ return None
520+
526521 if url :
527- repo = RemoteRepo . from_url ( repo_url = url )
522+ repo = get_repo_from_url ( url )
528523 repo_head = self .api .repos .get (repo_id = repo .repo_id , with_creds = True )
529524 elif local_path :
530- if legacy_local_path :
531- if repo_config := config_manager .get_repo_config (local_path ):
532- repo = load_repo (repo_config )
533- repo_head = self .api .repos .get (repo_id = repo .repo_id , with_creds = True )
534- if repo_head is not None :
535- warn (
536- "The repo is not specified but found and will be used in the run\n "
537- "Future versions will not load repos automatically\n "
538- "To prepare for future versions and get rid of this warning:\n "
539- "- If you need the repo in the run, either specify [code]repos[/code]"
540- " in the configuration or use [code]--repo .[/code]\n "
541- "- If you don't need the repo in the run, either run"
542- " [code]dstack init --remove[/code] once (it removes only the record"
543- " about the repo, the repo files will remain intact)"
544- " or use [code]--no-repo[/code]"
545- )
546- else :
547- # ignore stale entries in `config.yml`
548- repo = None
549- init = False
550- else :
551- original_local_path = local_path
552- local_path = local_path .expanduser ()
553- if not local_path .is_absolute ():
554- local_path = (root_dir / local_path ).resolve ()
555- if not local_path .exists ():
556- raise ConfigurationError (
557- f"Invalid repo path: { original_local_path } -> { local_path } "
558- )
559- local : bool = configurator_args .local
560- repo = get_repo_from_dir (local_path , local = local )
561- repo_head = self .api .repos .get (repo_id = repo .repo_id , with_creds = True )
562- if isinstance (repo , RemoteRepo ):
563- repo_branch = repo .run_repo_data .repo_branch
564- repo_hash = repo .run_repo_data .repo_hash
525+ original_local_path = local_path
526+ local_path = local_path .expanduser ()
527+ if not local_path .is_absolute ():
528+ local_path = (root_dir / local_path ).resolve ()
529+ if not local_path .exists ():
530+ raise ConfigurationError (
531+ f"Invalid repo path: { original_local_path } -> { local_path } "
532+ )
533+ repo = get_repo_from_dir (local_path )
534+ repo_head = self .api .repos .get (repo_id = repo .repo_id , with_creds = True )
535+ repo_branch = repo .run_repo_data .repo_branch
536+ repo_hash = repo .run_repo_data .repo_hash
565537 else :
566538 assert False , "should not reach here"
567539
568- if repo is None :
569- return init_default_virtual_repo (api = self .api )
540+ assert repo .repo_url is not None
570541
571- if isinstance (repo , RemoteRepo ):
572- assert repo .repo_url is not None
542+ if repo_head is not None and repo_head .repo_creds is not None :
543+ if git_identity_file is None and oauth_token is None :
544+ git_private_key = repo_head .repo_creds .private_key
545+ oauth_token = repo_head .repo_creds .oauth_token
546+ else :
547+ init = True
573548
574- if repo_head is not None and repo_head .repo_creds is not None :
575- if git_identity_file is None and oauth_token is None :
576- git_private_key = repo_head .repo_creds .private_key
577- oauth_token = repo_head .repo_creds .oauth_token
578- else :
579- init = True
549+ try :
550+ repo_creds , _ = get_repo_creds_and_default_branch (
551+ repo_url = repo .repo_url ,
552+ identity_file = git_identity_file ,
553+ private_key = git_private_key ,
554+ oauth_token = oauth_token ,
555+ )
556+ except InvalidRepoCredentialsError as e :
557+ raise CLIError (* e .args ) from e
580558
581- try :
582- repo_creds , default_repo_branch = get_repo_creds_and_default_branch (
583- repo_url = repo .repo_url ,
584- identity_file = git_identity_file ,
585- private_key = git_private_key ,
586- oauth_token = oauth_token ,
587- )
588- except InvalidRepoCredentialsError as e :
589- raise CLIError (* e .args ) from e
590-
591- if repo_branch is None and repo_hash is None :
592- if default_repo_branch is None :
593- raise CLIError (
594- "Failed to automatically detect remote repo branch."
595- " Specify branch or hash."
596- )
597- # TODO: remove in 0.20. Currently `default_repo_branch` is sent only for backward compatibility of `dstack-runner`.
598- repo_branch = default_repo_branch
599- repo .run_repo_data .repo_branch = repo_branch
600- if repo_hash is not None :
601- repo .run_repo_data .repo_hash = repo_hash
559+ repo .run_repo_data .repo_branch = repo_branch
560+ if repo_hash is not None :
561+ repo .run_repo_data .repo_hash = repo_hash
602562
603563 if init :
604564 self .api .repos .init (
@@ -608,15 +568,6 @@ def get_repo(
608568 creds = repo_creds ,
609569 )
610570
611- if isinstance (repo , LocalRepo ):
612- warn (
613- f"{ repo .repo_dir } is a local repo\n "
614- "Local repos are deprecated since 0.19.25 and will be removed soon\n "
615- "There are two options:\n "
616- "- Migrate to [code]files[/code]: https://dstack.ai/docs/concepts/tasks/#files\n "
617- "- Specify [code]--no-repo[/code] if you don't need the repo at all"
618- )
619-
620571 return repo
621572
622573
0 commit comments