Skip to content

Commit 7ec8280

Browse files
committed
refactor: reorganize core modules
- move TypeID implementation, factory, parsing, validation, constants, and errors into typeid.core - add typeid.codecs.base32 and keep typeid.base32 as a compatibility re-export - update public imports and tests to use new module paths - update CLI to live in typeid.cli.main and fix project script entrypoint - keep legacy modules (typeid.typeid, typeid.factory, typeid.validation, typeid.errors, typeid.constants) as shims
1 parent da2af42 commit 7ec8280

24 files changed

Lines changed: 585 additions & 420 deletions

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Repository = "https://github.com/akhundMurad/typeid-python"
2929
"Bug Tracker" = "https://github.com/akhundMurad/typeid-python/issues"
3030

3131
[project.scripts]
32-
typeid = "typeid.cli:cli"
32+
typeid = "typeid.cli.main:cli"
3333

3434
[dependency-groups]
3535
dev = [

tests/test_base32.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typeid.base32 import decode, encode
1+
from typeid.codecs.base32 import decode, encode
22

33

44
def test_encode_decode_logic() -> None:

tests/test_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from typeid import TypeID, cached_typeid_factory, typeid_factory
4-
from typeid.errors import PrefixValidationException
4+
from typeid.core.errors import PrefixValidationException
55

66

77
def test_typeid_factory_generates_typeid_with_prefix():

tests/test_spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from uuid_utils import UUID
33

44
from typeid import TypeID
5-
from typeid.errors import TypeIDException
5+
from typeid.core.errors import TypeIDException
66

77

88
def test_invalid_spec(invalid_spec: list) -> None:

tests/test_typeid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import uuid_utils
55

66
from typeid import TypeID
7-
from typeid.errors import SuffixValidationException
7+
from typeid.core.errors import SuffixValidationException
88

99

1010
def test_default_suffix() -> None:

tests/test_validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from uuid_utils import uuid7
33

44
from typeid import base32
5-
from typeid.errors import PrefixValidationException, SuffixValidationException
6-
from typeid.validation import validate_prefix, validate_suffix_and_decode
5+
from typeid.core.errors import PrefixValidationException, SuffixValidationException
6+
from typeid.core.validation import validate_prefix, validate_suffix_and_decode
77

88

99
def test_validate_correct_prefix() -> None:

typeid/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from .factory import TypeIDFactory, cached_typeid_factory, typeid_factory
2-
from .typeid import TypeID, from_string, from_uuid, get_prefix_and_suffix
1+
from typeid.core.factory import TypeIDFactory, cached_typeid_factory, typeid_factory
2+
from typeid.core.typeid import TypeID, from_string, from_uuid
3+
from typeid.core.parsing import get_prefix_and_suffix
34

45
__all__ = (
56
"TypeID",

typeid/base32.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
from typeid._base32 import encode as _encode_rust, decode as _decode_rust # type: ignore
1+
# Compatibility shim.
2+
#
3+
# This module exists to preserve backward compatibility with earlier
4+
# versions of the library. Public symbols are re-exported from their
5+
# current implementation locations.
6+
#
7+
# New code should prefer importing from the canonical modules, but
8+
# existing imports will continue to work.
29

10+
from typeid.codecs.base32 import encode, decode
311

4-
def encode(src: bytes) -> str:
5-
return _encode_rust(src)
612

7-
8-
def decode(s: str) -> bytes:
9-
return _decode_rust(s)
13+
__all__ = ("encode", "decode")

typeid/cli/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from typeid.cli.main import cli
2+
3+
4+
if __name__ == "__main__":
5+
cli()

typeid/cli.py renamed to typeid/cli/main.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import click
55
from uuid_utils import UUID
66

7-
from typeid import TypeID, base32, from_uuid, get_prefix_and_suffix
7+
from typeid import TypeID
8+
from typeid.codecs import base32
9+
from typeid.core.parsing import get_prefix_and_suffix
810
from typeid.explain.discovery import discover_schema_path
911
from typeid.explain.engine import explain as explain_engine
1012
from typeid.explain.formatters import format_explanation_json, format_explanation_pretty
@@ -42,7 +44,7 @@ def encode(uuid: str, prefix: Optional[str] = None) -> None:
4244
(e.g. stored in a database) and need to be represented as TypeIDs.
4345
"""
4446
uuid_obj = UUID(uuid)
45-
typeid = from_uuid(suffix=uuid_obj, prefix=prefix)
47+
typeid = TypeID.from_uuid(suffix=uuid_obj, prefix=prefix)
4648

4749
click.echo(str(typeid))
4850

@@ -151,7 +153,3 @@ def explain(
151153
click.echo(format_explanation_json(exp))
152154
else:
153155
click.echo(format_explanation_pretty(exp))
154-
155-
156-
if __name__ == "__main__":
157-
cli()

0 commit comments

Comments
 (0)