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

Allows manifest.json to be gzip compressed #68

Merged
merged 4 commits into from
Jun 21, 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
8 changes: 7 additions & 1 deletion dbt_loom/clients/az_blob.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
import os
import gzip
from io import BytesIO
from typing import Dict

from azure.identity import DefaultAzureCredential
Expand Down Expand Up @@ -49,7 +51,11 @@ def load_manifest(self) -> Dict:

# Deserialize the body of the object.
try:
content = blob_client.download_blob(encoding="utf-8").readall()
if self.object_name.endswith('.gz'):
with gzip.GzipFile(fileobj=BytesIO(blob_client.download_blob().readall())) as gzipfile:
content = gzipfile.read().decode('utf-8')
else:
content = blob_client.download_blob(encoding="utf-8").readall()
except Exception:
raise Exception(
f"Unable to read the data contained in the object `{self.object_name}"
Expand Down
9 changes: 8 additions & 1 deletion dbt_loom/clients/gcs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import gzip
from io import BytesIO
from pathlib import Path
from typing import Dict, Optional

Expand Down Expand Up @@ -47,7 +49,12 @@ def load_manifest(self) -> Dict:
f"`{self.bucket_name}`."
)

manifest_json = blob.download_as_text()
if self.object_name.endswith('.gz'):
compressed_manifest = blob.download_as_bytes()
with gzip.GzipFile(fileobj=BytesIO(compressed_manifest)) as gzip_file:
manifest_json = gzip_file.read()
else:
manifest_json = blob.download_as_text()

try:
return json.loads(manifest_json)
Expand Down
9 changes: 8 additions & 1 deletion dbt_loom/clients/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import Dict, Optional

import boto3
import gzip
from io import BytesIO
from pydantic import BaseModel


Expand Down Expand Up @@ -39,7 +41,12 @@ def load_manifest(self) -> Dict:

# Deserialize the body of the object.
try:
content = response["Body"].read().decode("utf-8")
if self.object_name.endswith(".gz"):
body = response["Body"].read()
with gzip.GzipFile(fileobj=BytesIO(body)) as gzipfile:
content = gzipfile.read().decode('utf-8')
else:
content = response["Body"].read().decode("utf-8")
except Exception:
raise Exception(
f"Unable to read the data contained in the object `{self.object_name}"
Expand Down
9 changes: 7 additions & 2 deletions dbt_loom/manifests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import json
import gzip
from typing import Dict, List, Optional

from pydantic import BaseModel, Field, validator
Expand Down Expand Up @@ -80,8 +81,12 @@ def load_from_local_filesystem(config: FileReferenceConfig) -> Dict:
"""Load a manifest dictionary from a local file"""
if not config.path.exists():
raise LoomConfigurationError(f"The path `{config.path}` does not exist.")

return json.load(open(config.path))

if config.path.suffix == '.gz':
with gzip.open(config.path, 'rt') as file:
return json.load(file)
else:
return json.load(open(config.path))

@staticmethod
def load_from_dbt_cloud(config: DbtCloudReferenceConfig) -> Dict:
Expand Down
Loading