Skip to content

Commit

Permalink
feat: FileTypePython (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
fritz-astronomer authored Feb 24, 2025
1 parent 4344f52 commit cf41eb3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion orbiter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from typing import Any, Tuple

__version__ = "1.5.3"
__version__ = "1.5.4"

version = __version__

Expand Down
25 changes: 21 additions & 4 deletions orbiter/file_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pydantic.v1 import validator

from jilutil.jil_parser import JilParser
from ast2json import str2json


class FileType(BaseModel, ABC, arbitrary_types_allowed=True):
Expand Down Expand Up @@ -208,8 +209,8 @@ class FileTypeYAML(FileType):
dump_fn: ClassVar[Callable[[dict], str]] = yaml.safe_dump


def dump_jil(_: dict) -> str:
raise NotImplementedError("JIL dumping is not implemented yet.")
def unimplemented_dump(_: dict) -> str:
raise NotImplementedError("Dumping is not implemented yet.")


class FileTypeJIL(FileType):
Expand All @@ -219,13 +220,29 @@ class FileTypeJIL(FileType):
:type extension: Set[str]
:param load_fn: custom JIL loading function
:type load_fn: Callable[[str], dict]
:param dump_fn: custom JIL dumping function
:param dump_fn: JIL dumping function not yet implemented, raises an error
:type dump_fn: Callable[[dict], str]
"""

extension: ClassVar[Set[str]] = {"JIL"}
load_fn: ClassVar[Callable[[str], dict]] = JilParser(None).parse_jobs_from_str
dump_fn: ClassVar[Callable[[dict], str]] = dump_jil
dump_fn: ClassVar[Callable[[dict], str]] = unimplemented_dump


class FileTypePython(FileType):
"""Python File Type
:param extension: PY
:type extension: Set[str]
:param load_fn: Python AST loading function (via `ast2json`)
:type load_fn: Callable[[str], dict]
:param dump_fn: Python dumping function not yet implemented, raises an error
:type dump_fn: Callable[[dict], str]
"""

extension: ClassVar[Set[str]] = {"PY"}
load_fn: ClassVar[Callable[[str], dict]] = str2json
dump_fn: ClassVar[Callable[[dict], str]] = unimplemented_dump


if __name__ == "__main__":
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ dependencies = [
# original @ https://github.com/mscribellito/jilutil
"jilutil",

# for parsing python
"ast2json",

# to render timezone-aware DAGs
"pendulum",
"tzdata", # for timezone data, if system doesn't have it?
Expand Down

0 comments on commit cf41eb3

Please sign in to comment.