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

Add FileTypePython #52

Merged
merged 1 commit into from
Feb 24, 2025
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: 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
Loading