core.common: move assert_subpackage to my.core.internal

This commit is contained in:
Dima Gerasimov 2024-08-15 18:49:19 +03:00 committed by karlicoss
parent 88f3c17c27
commit 7f8a502310
9 changed files with 17 additions and 13 deletions

View file

@ -1,4 +1,4 @@
from .common import assert_subpackage; assert_subpackage(__name__)
from .internal import assert_subpackage; assert_subpackage(__name__)
from contextlib import contextmanager
import logging

View file

@ -173,12 +173,6 @@ def asdict(thing: Any) -> Json:
raise TypeError(f'Could not convert object {thing} to dict')
def assert_subpackage(name: str) -> None:
# can lead to some unexpected issues if you 'import cachew' which being in my/core directory.. so let's protect against it
# NOTE: if we use overlay, name can be smth like my.origg.my.core.cachew ...
assert name == '__main__' or 'my.core' in name, f'Expected module __name__ ({name}) to be __main__ or start with my.core'
# TODO deprecate and suggest to use one from my.core directly? not sure
from .utils.itertools import unique_everseen

View file

@ -1,4 +1,4 @@
from .common import assert_subpackage; assert_subpackage(__name__)
from .internal import assert_subpackage; assert_subpackage(__name__)
import dataclasses as dcl
import inspect

View file

@ -1,7 +1,8 @@
'''
TODO doesn't really belong to 'core' morally, but can think of moving out later
'''
from .common import assert_subpackage; assert_subpackage(__name__)
from .internal import assert_subpackage; assert_subpackage(__name__)
from typing import Iterable, Any, Optional, Dict

9
my/core/internal.py Normal file
View file

@ -0,0 +1,9 @@
"""
Utils specific to hpi core, shouldn't really be used by HPI modules
"""
def assert_subpackage(name: str) -> None:
# can lead to some unexpected issues if you 'import cachew' which being in my/core directory.. so let's protect against it
# NOTE: if we use overlay, name can be smth like my.origg.my.core.cachew ...
assert name == '__main__' or 'my.core' in name, f'Expected module __name__ ({name}) to be __main__ or start with my.core'

View file

@ -1,4 +1,4 @@
from .common import assert_subpackage; assert_subpackage(__name__)
from .internal import assert_subpackage; assert_subpackage(__name__)
from . import warnings
# do this later -- for now need to transition modules to avoid using kompress directly (e.g. ZipPath)

View file

@ -2,7 +2,7 @@
Utils for mime/filetype handling
"""
from .common import assert_subpackage; assert_subpackage(__name__)
from .internal import assert_subpackage; assert_subpackage(__name__)
import functools

View file

@ -2,7 +2,7 @@
Helpers to prevent depending on pytest in runtime
"""
from .common import assert_subpackage; assert_subpackage(__name__)
from .internal import assert_subpackage; assert_subpackage(__name__)
import sys
import typing

View file

@ -1,4 +1,4 @@
from .common import assert_subpackage; assert_subpackage(__name__)
from .internal import assert_subpackage; assert_subpackage(__name__)
from contextlib import contextmanager