Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent cache defaults, export bucket cache name #12

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/gypsum_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
del version, PackageNotFoundError


from ._utils import BUCKET_CACHE_NAME
from .auth import access_token, set_access_token
from .cache_directory import cache_directory
from .clone_operations import clone_version
Expand Down Expand Up @@ -44,3 +45,4 @@
from .set_operations import set_permissions, set_quota
from .upload_api_operations import abort_upload, complete_upload, start_upload
from .upload_file_actions import upload_directory, upload_files
from .validate_metadata import validate_metadata
6 changes: 4 additions & 2 deletions src/gypsum_client/fetch_metadata_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@


def fetch_metadata_database(
name: str = "bioconductor.sqlite3", cache_dir: str = None, overwrite: bool = False
name: str = "bioconductor.sqlite3",
cache_dir: str = cache_directory(),
overwrite: bool = False,
) -> str:
"""Fetch the SQLite database containing metadata from the gypsum backend.

Expand Down Expand Up @@ -72,7 +74,7 @@ def fetch_metadata_database(
if cache_dir is None:
cache_path = tempfile.NamedTemporaryFile(suffix=".sqlite3").name
else:
cache_dir = os.path.join(cache_directory(cache_dir), "databases")
cache_dir = os.path.join(cache_dir, "databases")

cache_path = os.path.join(cache_dir, name)
if not os.path.exists(cache_path):
Expand Down
4 changes: 2 additions & 2 deletions src/gypsum_client/fetch_metadata_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def fetch_metadata_schema(
name: str = "bioconductor/v1.json",
cache_dir: str = None,
cache_dir: str = cache_directory(),
overwrite: bool = False,
) -> str:
"""Fetch a JSON schema file for metadata to be inserted into a SQLite database.
Expand Down Expand Up @@ -58,7 +58,7 @@ def fetch_metadata_schema(
if cache_dir is None:
cache_path = tempfile.mktemp(suffix=".json")
else:
cache_dir = os.path.join(cache_directory(cache_dir), "schemas")
cache_dir = os.path.join(cache_dir, "schemas")

cache_path = os.path.join(cache_dir, name)
if not os.path.exists(cache_path):
Expand Down
12 changes: 6 additions & 6 deletions src/gypsum_client/prepare_directory_for_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,13 @@ def prepare_directory_upload(
for root, _, files in os.walk(directory):
for name in files:
rel_path = os.path.relpath(os.path.join(root, name), directory)
dest = (
os.readlink(os.path.join(directory, rel_path))
if os.path.islink(os.path.join(directory, rel_path))
else None
)
if not dest:

if not os.path.islink(os.path.join(directory, rel_path)):
out_files.append(rel_path)
continue

dest = os.readlink(os.path.join(directory, rel_path))

if links == "never":
if not os.path.exists(dest):
raise ValueError(
Expand All @@ -140,6 +138,7 @@ def prepare_directory_upload(

dest = _normalize_and_sanitize_path(dest)
dest_components = _match_path_to_cache(dest, cache_dir)

if dest_components:
out_links.append(
{
Expand All @@ -160,6 +159,7 @@ def prepare_directory_upload(
raise ValueError(
f"Cannot use a dangling link to '{dest}' as a regular upload."
)

out_files.append(rel_path)

return {"files": out_files, "links": out_links}
Expand Down
2 changes: 1 addition & 1 deletion src/gypsum_client/resolve_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def resolve_links(
project: str,
asset: str,
version: str,
cache_dir: Optional[str] = None,
cache_dir: Optional[str] = cache_directory(),
overwrite: str = False,
url: str = rest_url(),
):
Expand Down
4 changes: 2 additions & 2 deletions src/gypsum_client/save_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def save_version(
project: str,
asset: str,
version: str,
cache_dir: Optional[str] = None,
cache_dir: Optional[str] = cache_directory(),
overwrite: bool = False,
relink: bool = True,
concurrent: int = 1,
Expand Down Expand Up @@ -203,7 +203,7 @@ def save_file(
asset: str,
version: str,
path: str,
cache_dir: Optional[str] = None,
cache_dir: Optional[str] = cache_directory(),
overwrite: bool = False,
url: str = rest_url(),
):
Expand Down
Loading