diff --git a/dandi/cli/cmd_upload.py b/dandi/cli/cmd_upload.py index ada1f850c..087b19c94 100644 --- a/dandi/cli/cmd_upload.py +++ b/dandi/cli/cmd_upload.py @@ -10,11 +10,6 @@ @click.command() -# @dandiset_path_option( -# help="Top directory (local) of the dandiset. Files will be uploaded with " -# "paths relative to that directory. If not specified, current or a parent " -# "directory containing dandiset.yaml file will be assumed " -# ) @click.option( "-e", "--existing", @@ -69,7 +64,6 @@ def upload( dandi_instance, existing="refresh", validation="require", - dandiset_path=None, # Development options should come as kwargs allow_any_path=False, upload_dandiset_metadata=False, @@ -79,7 +73,9 @@ def upload( Upload Dandiset files to DANDI Archive. The target Dandiset to upload to must already be registered in the archive, - and a `dandiset.yaml` file must exist in the local `--dandiset-path`. + and a `dandiset.yaml` file must exist in the common ancestor of the given + paths (or the current directory, if no paths are specified) or a parent + directory thereof. Local Dandiset should pass validation. For that, the assets should first be organized using the `dandi organize` command. @@ -100,7 +96,6 @@ def upload( paths, existing=existing, validation=validation, - dandiset_path=dandiset_path, dandi_instance=dandi_instance, allow_any_path=allow_any_path, upload_dandiset_metadata=upload_dandiset_metadata, diff --git a/dandi/tests/fixtures.py b/dandi/tests/fixtures.py index 64cd642f0..b8210e08b 100644 --- a/dandi/tests/fixtures.py +++ b/dandi/tests/fixtures.py @@ -330,8 +330,7 @@ def upload( with pytest.MonkeyPatch().context() as m: m.setenv("DANDI_API_KEY", self.api.api_key) upload( - paths=paths, - dandiset_path=self.dspath, + paths=paths or [self.dspath], dandi_instance=self.api.instance_id, devel_debug=True, **{**self.upload_kwargs, **kwargs}, diff --git a/dandi/upload.py b/dandi/upload.py index 00f041843..e40c8a947 100644 --- a/dandi/upload.py +++ b/dandi/upload.py @@ -30,7 +30,6 @@ def upload( paths: Optional[List[Union[str, Path]]] = None, existing: str = "refresh", validation: str = "require", - dandiset_path: Union[str, Path, None] = None, dandi_instance: str = "dandi", allow_any_path: bool = False, upload_dandiset_metadata: bool = False, @@ -42,11 +41,15 @@ def upload( from .dandiapi import DandiAPIClient from .dandiset import APIDandiset, Dandiset - dandiset_ = Dandiset.find(dandiset_path) + if paths: + paths = [Path(p).absolute() for p in paths] + dandiset_ = Dandiset.find(os.path.commonpath(paths)) + else: + dandiset_ = Dandiset.find(None) if not dandiset_: raise RuntimeError( - f"Found no {dandiset_metadata_file} anywhere. " - "Use 'dandi download' or 'organize' first" + f"Found no {dandiset_metadata_file} anywhere in common ancestor of" + " paths. Use 'dandi download' or 'organize' first." ) instance = get_instance(dandi_instance) @@ -74,15 +77,9 @@ def upload( ignore_benign_pynwb_warnings() # so validate doesn't whine - # - # Treat paths - # if not paths: paths = [dandiset.path] - original_paths = paths - # Expand and validate all paths -- they should reside within dandiset - paths = [Path(p).absolute() for p in paths] dandi_files = list( find_dandi_files( *paths, @@ -335,7 +332,7 @@ def upload_agg(*ignored: Any) -> str: if sync: relpaths: List[str] = [] - for p in original_paths: + for p in paths: rp = os.path.relpath(p, dandiset.path) relpaths.append("" if rp == "." else rp) path_prefix = reduce(os.path.commonprefix, relpaths) # type: ignore[arg-type] diff --git a/docs/source/cmdline/upload.rst b/docs/source/cmdline/upload.rst index 5367aa2c2..330f3470c 100644 --- a/docs/source/cmdline/upload.rst +++ b/docs/source/cmdline/upload.rst @@ -8,7 +8,9 @@ Upload Dandiset files to DANDI Archive. The target Dandiset to upload to must already be registered in the archive, and -a :file:`dandiset.yaml` file must exist in the local :option:`--dandiset-path`. +a :file:`dandiset.yaml` file must exist in the common ancestor of the given +paths (or the current directory, if no paths are specified) or a parent +directory thereof. Local Dandisets should pass validation. For that, the assets should first be organized using the :ref:`dandi_organize` command.