Skip to content

Commit

Permalink
Change the way the auto generated relative paths are done for single …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
stuartmcalpine committed Oct 22, 2024
1 parent 10cd9e1 commit 3ea78a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/dataregistry/registrar/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def register(
# If `relative_path` not passed, automatically generate it
if kwargs_dict["relative_path"] is None:
kwargs_dict["relative_path"] = _relpath_from_name(
name, kwargs_dict["version_string"]
name, kwargs_dict["version_string"], kwargs_dict["old_location"]
)

# Make sure the relative_path in the `root_dir` is avaliable
Expand Down
17 changes: 15 additions & 2 deletions src/dataregistry/registrar/registrar_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def _compute_checksum(file_path):

raise Exception(e)

def _relpath_from_name(name, version):
def _relpath_from_name(name, version, old_location):
"""
Construct a relative path from the name and version of a dataset.
We use this when the `relative_path` is not explicitly defined.
Expand All @@ -337,17 +337,30 @@ def _relpath_from_name(name, version):
into this top level folder. This is to prevent clashes with user specified
`relative_path`'s.
The auto-generated `relative_path` will be a directory that contains the
name and version, which is where the ingested data (from `old_location`)
will eventually reside. If the data being ingested is a single file, the
`relative_path` will be the full path to the file within the registry, not
just the directory that contains the file.
Parameters
----------
name : str
Dataset name
version : str
Dataset version
old_location : str
Path the data is coming from (needed to parse filename)
Returns
-------
relative_path : str
Automatically generated `relative_path`
"""

return os.path.join(".gen_paths", f"{name}_{version}")
# For single files, scrape the filename and add it to the `relative_path`
if (old_location is not None) and os.path.isfile(old_location):
return os.path.join(".gen_paths", f"{name}_{version}", os.path.basename(old_location))
else:
# For directories, only need the autogenerated directory name
return os.path.join(".gen_paths", f"{name}_{version}")

0 comments on commit 3ea78a2

Please sign in to comment.