Skip to content

Commit

Permalink
feat: use ocdskit to wrap data into release package
Browse files Browse the repository at this point in the history
  • Loading branch information
yshalenyk committed Jul 3, 2024
1 parent bd9927c commit 97881f1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
7 changes: 6 additions & 1 deletion nightingale/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import tomllib
from dataclasses import field
from pathlib import Path
from typing import Optional, Self

Expand All @@ -20,9 +21,13 @@ class Datasource:

@dataclass(frozen=True)
class Publishing:
version: str
publisher: str
base_uri: str
version: str = ""
publisher_uid: str = ""
publisher_scheme: str = ""
publisher_uri: str = ""
extensions: list[str] = field(default_factory=list)


@dataclass(frozen=True)
Expand Down
40 changes: 31 additions & 9 deletions nightingale/publisher.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Any

from ocdskit.combine import package_releases

from .utils import get_iso_now, produce_package_name


Expand All @@ -19,8 +21,9 @@ def __init__(self, config):
:type config: Config
"""
self.config = config
self.date = get_iso_now()

def produce_uri(self, date: str) -> str:
def produce_uri(self) -> str:
"""
Produce a URI for the package based on the given date.
Expand All @@ -29,7 +32,7 @@ def produce_uri(self, date: str) -> str:
:return: The produced URI.
:rtype: str
"""
return f"{self.config.base_uri}/{produce_package_name(date)}"
return f"{self.config.base_uri}/{produce_package_name(self.date)}"

def package(self, data: list[dict[str, Any]]) -> dict[str, Any]:
"""
Expand All @@ -40,11 +43,30 @@ def package(self, data: list[dict[str, Any]]) -> dict[str, Any]:
:return: A dictionary representing the release package.
:rtype: dict[str, Any]
"""
now = get_iso_now()
return {
"uri": self.produce_uri(now),
"version": self.config.version,
"publisher": {"name": self.config.publisher},
"publishedDate": now,
"releases": data,
kwargs = dict(
uri=self.produce_uri(),
publisher=self.get_publisher(),
published_date=self.date,
extensions=self.get_extensions(),
)
if self.config.version:
kwargs["version"] = self.config.version
return package_releases(data, **kwargs)

def get_publisher(self):
publisher = {
"name": self.config.publisher,
}
if self.config.publisher_scheme:
publisher["scheme"] = self.config.publisher_scheme
if self.config.publisher_uid:
publisher["uid"] = self.config.publisher_uid
if self.config.publisher_uri:
publisher["uri"] = self.config.publisher_uri
return publisher

def get_extensions(self):
return self.config.extensions

def get_version(self):
self.config.version
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dict_hash==1.1.37
et-xmlfile==1.1.0
flatten-dict==0.4.2
numpy==1.26.4
ocdskit==1.1.13
openpyxl==3.1.3
pandas==2.2.2
polars==0.20.30
Expand Down

0 comments on commit 97881f1

Please sign in to comment.