Skip to content

Commit

Permalink
feat: support wulifang manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
NateScarlet committed Nov 4, 2022
1 parent c72d7c2 commit d678465
Show file tree
Hide file tree
Showing 55 changed files with 1,425 additions and 380 deletions.
1 change: 1 addition & 0 deletions .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"or'ed",
"Popen",
"postchangelog",
"Precomp",
"psutil",
"pyblish",
"pylint",
Expand Down
10 changes: 5 additions & 5 deletions typings/wulifang/vendor/pyblish/plugin.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ class AbstractEntity(__builtin__.list):
list of weak references to the object (if defined)
"""

data: ...
data: typing.Dict[typing.Text, typing.Any]
"""
"""

id: ...
id: str
"""
"""

name: ...
name: str
"""
"""

parent: ...
parent: typing.Optional[AbstractEntity]
"""
"""

Expand Down Expand Up @@ -209,7 +209,7 @@ class Context(AbstractEntity):
"""
...

def create_instance(self, name, **kwargs):
def create_instance(self, name: typing.Text, **kwargs: typing.Any) -> Instance:
"""
Convenience method of the following.
>>> ctx = Context()
Expand Down
Binary file not shown.
3 changes: 2 additions & 1 deletion wulifang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
if TYPE_CHECKING:
from typing import Any

from .types import MessageService, PublishService, FileService
from .types import MessageService, PublishService, FileService, ManifestService

import os

Expand All @@ -30,6 +30,7 @@ def _undefined():
message = _undefined() # type: MessageService
publish = _undefined() # type: PublishService
file = _undefined() # type: FileService
manifest = _undefined() # type: ManifestService
is_debug = os.getenv("DEBUG") == "wulifang"

publish = _DefaultPublishService()
Expand Down
15 changes: 15 additions & 0 deletions wulifang/_util/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding=UTF-8 -*-
# pyright: strict, reportTypeCommentUsage=none,reportUnusedImport=none


from ._atomic_save_path import atomic_save_path
from ._cast_int import cast_int
from ._cast_list import cast_list
from ._cast_text import cast_text
from ._compat import PY2, binary_type, text_type
from ._force_rename import force_rename
from ._is_file_not_found_error import is_file_not_found_error
from ._iteritems import iteritems
from ._iterkeys import iterkeys
from ._null_time import NULL_TIME
from ._timezone import TZ_CHINA, TZ_UTC, FixedTimezone
32 changes: 32 additions & 0 deletions wulifang/_util/_atomic_save_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding=UTF-8 -*-
# pyright: strict, reportTypeCommentUsage=none

from __future__ import absolute_import, division, print_function, unicode_literals

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Text


import contextlib
from typing import Text

from ._force_rename import force_rename


@contextlib.contextmanager
def atomic_save_path(
path,
temp_suffix=".tmp",
backup_suffix="",
):
# type: (Text, Text, Text) -> ...
tmp_path = path + temp_suffix
yield tmp_path
if backup_suffix:
backup_path = path + backup_suffix
try:
force_rename(path, backup_path)
except FileNotFoundError:
pass
force_rename(tmp_path, path)
15 changes: 15 additions & 0 deletions wulifang/_util/_cast_int.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding=UTF-8 -*-
# pyright: strict, reportTypeCommentUsage=none

from __future__ import absolute_import, division, print_function, unicode_literals

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Any


def cast_int(v):
# type: (Any) -> int
if isinstance(v, int):
return v
return int(v)
31 changes: 31 additions & 0 deletions wulifang/_util/_cast_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding=UTF-8 -*-
# pyright: strict, reportTypeCommentUsage=none

from __future__ import absolute_import, division, print_function, unicode_literals

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Any, List

import sys

_py2 = sys.version_info[0] == 2


if _py2:
_text_type = unicode # type: ignore
_binary_type = str # type: ignore
else:
_text_type = str
_binary_type = bytes


def cast_list(v):
# type: (Any) -> List[Any]
if v is None:
return []
if isinstance(v, list):
return v # type: ignore
if isinstance(v, tuple):
return list(v) # type: ignore
return [v]
20 changes: 20 additions & 0 deletions wulifang/_util/_cast_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding=UTF-8 -*-
# pyright: strict, reportTypeCommentUsage=none

from __future__ import absolute_import, division, print_function, unicode_literals

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Any


from ._compat import text_type, binary_type


def cast_text(v):
# type: (Any) -> str
if isinstance(v, binary_type):
return v.decode("utf-8")
if isinstance(v, text_type):
return v
return text_type(v)
32 changes: 32 additions & 0 deletions wulifang/_util/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding=UTF-8 -*-
# pyright: strict, reportTypeCommentUsage=none

from __future__ import absolute_import, division, print_function, unicode_literals

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Type

import sys

PY2 = sys.version_info[0] == 2


def _text_type():
# type: () -> Type[str]
if PY2:
return unicode # type: ignore
return str


text_type = _text_type()


def _binary_type():
# type: () -> Type[bytes]
if PY2:
return str # type: ignore
return bytes


binary_type = _binary_type()
19 changes: 19 additions & 0 deletions wulifang/_util/_force_rename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding=UTF-8 -*-
# pyright: strict, reportTypeCommentUsage=none

from __future__ import absolute_import, division, print_function, unicode_literals

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Text

import os


def force_rename(src, dst):
# type: (Text, Text) -> None
try:
os.rename(src, dst)
except FileExistsError:
os.unlink(dst)
os.rename(src, dst)
16 changes: 16 additions & 0 deletions wulifang/_util/_is_file_not_found_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding=UTF-8 -*-
# pyright: strict, reportTypeCommentUsage=none

from __future__ import absolute_import, division, print_function, unicode_literals

from ._compat import PY2


def is_file_not_found_error(err):
# type: (Exception) -> bool
if PY2:
import errno

return isinstance(err, (OSError, IOError)) and (err.errno == errno.ENOENT)

return isinstance(err, FileNotFoundError)
20 changes: 20 additions & 0 deletions wulifang/_util/_iteritems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding=UTF-8 -*-
# pyright: strict, reportTypeCommentUsage=none

from __future__ import absolute_import, division, print_function, unicode_literals

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Any, Mapping, TypeVar, ItemsView

T = TypeVar("T")


from ._compat import PY2


def iteritems(d):
# type: (Mapping[T, Any]) -> ItemsView[T, Any]
if PY2:
return d.iteritems() # type: ignore
return d.items()
20 changes: 20 additions & 0 deletions wulifang/_util/_iterkeys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding=UTF-8 -*-
# pyright: strict, reportTypeCommentUsage=none

from __future__ import absolute_import, division, print_function, unicode_literals

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Any, Mapping, TypeVar, KeysView

T = TypeVar("T")


from ._compat import PY2


def iterkeys(d):
# type: (Mapping[T, Any]) -> KeysView[T]
if PY2:
return d.iterkeys() # type: ignore
return d.keys()
9 changes: 9 additions & 0 deletions wulifang/_util/_null_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding=UTF-8 -*-
# pyright: strict, reportTypeCommentUsage=none

from __future__ import absolute_import, division, print_function, unicode_literals

from ._timezone import TZ_UTC
from datetime import datetime

NULL_TIME = datetime.fromtimestamp(0, TZ_UTC)
33 changes: 33 additions & 0 deletions wulifang/_util/_timezone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding=UTF-8 -*-
# pyright: strict, reportTypeCommentUsage=none

from __future__ import absolute_import, division, print_function, unicode_literals

TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Text, Optional

from datetime import datetime, timedelta, tzinfo


class FixedTimezone(tzinfo):
def __init__(self, name, utcoffset):
# type: (Text, timedelta) -> None
self._name = name
self._utcoffset = utcoffset

def tzname(self, dt):
# type: (Optional[datetime]) -> Text
return self._name

def utcoffset(self, dt):
# type: (Optional[datetime]) -> timedelta
return self._utcoffset

def dst(self, dt):
# type: (Optional[datetime]) -> timedelta
return timedelta()


TZ_UTC = FixedTimezone("UTC", timedelta())
TZ_CHINA = FixedTimezone("UTC+8", timedelta(hours=8))
1 change: 0 additions & 1 deletion wulifang/infrastructure/logging_message_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# pyright: strict, reportTypeCommentUsage=false

from __future__ import absolute_import, division, print_function, unicode_literals
from cmath import log

TYPE_CHECKING = False
if TYPE_CHECKING:
Expand Down
6 changes: 5 additions & 1 deletion wulifang/nuke/_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import wulifang
import wulifang.nuke
import wulifang.license
import wulifang.nuke
from wulifang.infrastructure.multi_message_service import MultiMessageService
from wulifang.nuke.infrastructure.active_viewer_service import ActiveViewerService
from wulifang.nuke.infrastructure.callback_service import CallbackService
from wulifang.nuke.infrastructure.cleanup_service import CleanupService
from wulifang.nuke.infrastructure.manifest_service import ManifestService

import nuke

Expand All @@ -17,12 +18,15 @@ class _g:
init_once = False
skip_gui = False


def skip_gui():
return _g.skip_gui


def init():
if _g.init_once:
return
wulifang.manifest = ManifestService()
if nuke.GUI:
from wulifang.infrastructure.tray_message_service import TrayMessageService

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import wulifang.vendor.cast_unknown as cast


# TODO: remove this
def import_task_video(entry, shot, sign):
# type: (cgtwq.Entry, Text, Text) -> Optional[nuke.Node]
"""Import corresponse video by filebox sign.
Expand Down
Loading

0 comments on commit d678465

Please sign in to comment.