Skip to content

Commit

Permalink
Merge pull request #83 from LSSTDESC/u/stuart/add_schema_to_rootdir
Browse files Browse the repository at this point in the history
Add schema name to the shared space path
  • Loading branch information
stuartmcalpine authored Dec 7, 2023
2 parents 935d643 + abccf66 commit 0c535c9
Show file tree
Hide file tree
Showing 14 changed files with 1,004 additions and 799 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,11 @@ jobs:
run: |
cd tests/end_to_end_tests
# Register database entries using dataregistry package
python create_test_entries.py
# Register more database entries using the CLI
bash create_test_entries_cli.sh
# Run some test queries
pytest -v test_query.py
pytest -v test_*.py
sqlite-end-to-end-tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -196,11 +193,8 @@ jobs:
run: |
cd tests/end_to_end_tests
# Register database entries using dataregistry package
python create_test_entries.py
# Register more database entries using the CLI
bash create_test_entries_cli.sh
# Run some test queries
pytest -v test_query.py
pytest -v -m "not skip" test_*.py
5 changes: 5 additions & 0 deletions src/cli/register.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
import os
from dataregistry import DataRegistry

Expand All @@ -23,6 +24,10 @@ def register_dataset(args):
found in `src/cli/cli.py` or by running `dregs --help`.
"""

# Convert to a datetime object (needed for SQLite)
if args.creation_date is not None:
args.creation_date = datetime.strptime(args.creation_date, "%Y-%m-%d")

# Connect to database.
datareg = DataRegistry(
config_file=args.config_file,
Expand Down
2 changes: 1 addition & 1 deletion src/dataregistry/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.2"
__version__ = "0.3.0"
1 change: 1 addition & 0 deletions src/dataregistry/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ def get_dataset_absolute_path(self, dataset_id, schema=None):
results["dataset.owner_type"][0],
results["dataset.owner"][0],
results["dataset.relative_path"][0],
schema=schema,
root_dir=self._root_dir,
)
else:
Expand Down
6 changes: 5 additions & 1 deletion src/dataregistry/registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ def _handle_data(self, relative_path, old_location, owner, owner_type, verbose):

# Get destination directory in data registry.
dest = _form_dataset_path(
owner_type, owner, relative_path, root_dir=self._root_dir
owner_type,
owner,
relative_path,
schema=self._schema,
root_dir=self._root_dir,
)

# Is the data already on location, or coming from somewhere new?
Expand Down
20 changes: 14 additions & 6 deletions src/dataregistry/registrar_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ def _parse_version_string(version, with_suffix=False):
return d


def _form_dataset_path(owner_type, owner, relative_path, root_dir=None):
def _form_dataset_path(owner_type, owner, relative_path, schema=None, root_dir=None):
"""
Construct full (or relative) path to dataset in the data registry.
Path will have the format if `root_dir` is None:
When schema and root_dir are not None, the full path is returned:
<root_dir>/<schema>/<owner_type>/<owner>/<relative_path>
When schema and root_dir are ommited, the relative path is returned:
<owner_type>/<owner>/<relative_path>
or if `root_dir` is not None:
<root_dir>/<owner_type>/<owner>/<relative_path>
Parameters
----------
Expand All @@ -72,17 +73,24 @@ def _form_dataset_path(owner_type, owner, relative_path, root_dir=None):
Owner of dataset
relative_path : str
Relative path within the data registry
root_dir : str
schema : str, optional
Schema we are connected to
root_dir : str, optional
Root directory of data registry
dialect : str, optional
SQL dialect, e.g postgres or sqlite
Returns
-------
to_return : str
Full path of dataset in the data registry
Full (or relative) path of dataset in the data registry
"""

if owner_type == "production":
owner = "production"
to_return = os.path.join(owner_type, owner, relative_path)
if schema:
to_return = os.path.join(schema, to_return)
if root_dir:
to_return = os.path.join(root_dir, to_return)
return to_return
Expand Down
Loading

0 comments on commit 0c535c9

Please sign in to comment.