-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ds add: use --dvc/--dvcx/--url flags to accept url (#10326)
* ds add: use --dvc/--dvcx/--url flags to accept url .. instead of relying on `scheme://` I think this is more simpler from user's perspective, easier to teach and easier to maintain as we won't have to do url parsing. I am taking inspiration from `cargo install` has `--git`/`--rev`, etc. to install from alternate sources. ```console Options: --version <VERSION> Specify a version to install --index <INDEX> Registry index to install from --registry <REGISTRY> Registry to use --git <URL> Git URL to install the specified crate from --branch <BRANCH> Branch to use when installing from git --tag <TAG> Tag to use when installing from git --rev <SHA> Specific commit to use when installing from git --path <PATH> Filesystem path to local crate to install --root <DIR> Directory to install packages into``` ``` The `name` is also changed from an option to an argument. ### Examples ```console dvc ds add example-get-started --dvc [email protected]:iterative/example-get-started.git dvc ds add dogs --dvcx dogs dvc ds add dogs --url s3://bucket/key/path ``` * add --version alias
- Loading branch information
Showing
5 changed files
with
58 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,17 @@ def display(cls, name: str, dataset: "Dataset", action: str = "Adding"): | |
ui.write(action, ui.rich_text(name, "cyan"), text, styled=True) | ||
|
||
def run(self): | ||
if not self.args.dvc and self.args.rev: | ||
raise DvcException("--rev can't be used without --dvc") | ||
if not self.args.dvc and self.args.path: | ||
raise DvcException("--path can't be used without --dvc") | ||
|
||
d = vars(self.args) | ||
for key in ["dvc", "dvcx", "url"]: | ||
if url := d.pop(key, None): | ||
d.update({"type": key, "url": url}) | ||
break | ||
|
||
existing = self.repo.datasets.get(self.args.name) | ||
with self.repo.scm_context: | ||
if not self.args.force and existing: | ||
|
@@ -57,7 +68,7 @@ def run(self): | |
f"{self.args.name} already exists in {path}, " | ||
"use the --force to overwrite" | ||
) | ||
dataset = self.repo.datasets.add(**vars(self.args)) | ||
dataset = self.repo.datasets.add(**d) | ||
self.display(self.args.name, dataset) | ||
return 0 | ||
|
||
|
@@ -154,33 +165,37 @@ def add_parser(subparsers, parent_parser): | |
formatter_class=formatter.RawTextHelpFormatter, | ||
help=dataset_add_help, | ||
) | ||
ds_add_parser.add_argument( | ||
|
||
url_exclusive_group = ds_add_parser.add_mutually_exclusive_group(required=True) | ||
url_exclusive_group.add_argument( | ||
"--dvcx", metavar="name", help="Name of the dvcx dataset to track" | ||
) | ||
url_exclusive_group.add_argument( | ||
"--dvc", | ||
help="Path or URL to a Git/DVC repository to track", | ||
metavar="url", | ||
) | ||
url_exclusive_group.add_argument( | ||
"--url", | ||
required=True, | ||
help="""\ | ||
Location of the data to download. Supported URLs: | ||
URL of a cloud-versioned remote to track. Supported URLs: | ||
s3://bucket/key/path | ||
gs://bucket/path/to/file/or/dir | ||
azure://mycontainer/path | ||
remote://remote_name/path/to/file/or/dir (see `dvc remote`) | ||
dvcx://dataset_name | ||
To import data from dvc/git repositories, \ | ||
add dvc:// schema to the repo url, e.g: | ||
dvc://[email protected]:iterative/example-get-started.git | ||
dvc+https://github.com/iterative/example-get-started.git""", | ||
) | ||
ds_add_parser.add_argument( | ||
"--name", help="Name of the dataset to add", required=True | ||
""", | ||
) | ||
ds_add_parser.add_argument("name", help="Name of the dataset to add") | ||
ds_add_parser.add_argument( | ||
"--rev", | ||
help="Git revision, e.g. SHA, branch, tag " | ||
"(only applicable for dvc/git repository)", | ||
help="Git revision, e.g. SHA, branch, tag (only applicable with --dvc)", | ||
metavar="<commit>", | ||
) | ||
ds_add_parser.add_argument( | ||
"--path", help="Path to a file or directory within the git repository" | ||
"--path", | ||
help="Path to a file or a directory within a git repository " | ||
"(only applicable with --dvc)", | ||
) | ||
ds_add_parser.add_argument( | ||
"-f", | ||
|
@@ -202,6 +217,7 @@ def add_parser(subparsers, parent_parser): | |
ds_update_parser.add_argument("name", help="Name of the dataset to update") | ||
ds_update_parser.add_argument( | ||
"--rev", | ||
"--version", | ||
nargs="?", | ||
help="DVCX dataset version or Git revision (e.g. SHA, branch, tag)", | ||
metavar="<version>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.