ulid-transform 0.8.1__tar.gz → 0.10.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ulid-transform
3
- Version: 0.8.1
3
+ Version: 0.10.0
4
4
  Summary: Create and transform ULIDs
5
5
  Home-page: https://github.com/bdraco/ulid-transform
6
6
  License: MIT
@@ -15,6 +15,7 @@ Classifier: Operating System :: OS Independent
15
15
  Classifier: Programming Language :: Python :: 3
16
16
  Classifier: Programming Language :: Python :: 3.10
17
17
  Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
18
19
  Classifier: Topic :: Software Development :: Libraries
19
20
  Project-URL: Bug Tracker, https://github.com/bdraco/ulid-transform/issues
20
21
  Project-URL: Changelog, https://github.com/bdraco/ulid-transform/blob/main/CHANGELOG.md
@@ -68,6 +69,12 @@ This library will use the CPP implementation from https://github.com/suyash/ulid
68
69
  b'\x00\x00c\xfe\x82\xbc\x00!\xc0t\x877\x0b\xad\xad\xee'
69
70
  >> ulid_transform.bytes_to_ulid(b"\x01\x86\x99?\xe8\xf3\x11\xbc\xed\xef\x86U.9\x03z")
70
71
  '01GTCKZT7K26YEVVW6AMQ3J0VT'
72
+ >>> ulid_transform.ulid_to_bytes_or_none('0001HZX0NW00GW0X476W5TVBFE')
73
+ b'\x00\x00c\xfe\x82\xbc\x00!\xc0t\x877\x0b\xad\xad\xee'
74
+ >>> ulid_transform.ulid_to_bytes_or_none(None)
75
+ >>> ulid_transform.bytes_to_ulid_or_none(b'\x00\x00c\xfe\x82\xbc\x00!\xc0t\x877\x0b\xad\xad\xee')
76
+ '0001HZX0NW00GW0X476W5TVBFE'
77
+ >>> ulid_transform.bytes_to_ulid_or_none(None)
71
78
  ```
72
79
 
73
80
  ## Installation
@@ -45,6 +45,12 @@ This library will use the CPP implementation from https://github.com/suyash/ulid
45
45
  b'\x00\x00c\xfe\x82\xbc\x00!\xc0t\x877\x0b\xad\xad\xee'
46
46
  >> ulid_transform.bytes_to_ulid(b"\x01\x86\x99?\xe8\xf3\x11\xbc\xed\xef\x86U.9\x03z")
47
47
  '01GTCKZT7K26YEVVW6AMQ3J0VT'
48
+ >>> ulid_transform.ulid_to_bytes_or_none('0001HZX0NW00GW0X476W5TVBFE')
49
+ b'\x00\x00c\xfe\x82\xbc\x00!\xc0t\x877\x0b\xad\xad\xee'
50
+ >>> ulid_transform.ulid_to_bytes_or_none(None)
51
+ >>> ulid_transform.bytes_to_ulid_or_none(b'\x00\x00c\xfe\x82\xbc\x00!\xc0t\x877\x0b\xad\xad\xee')
52
+ '0001HZX0NW00GW0X476W5TVBFE'
53
+ >>> ulid_transform.bytes_to_ulid_or_none(None)
48
54
  ```
49
55
 
50
56
  ## Installation
@@ -47,6 +47,9 @@ def build(setup_kwargs: Any) -> None:
47
47
  cmdclass=dict(build_ext=BuildExt),
48
48
  )
49
49
  )
50
+ setup_kwargs["exclude_package_data"] = {
51
+ pkg: ["_ulid_impl.cpp"] for pkg in setup_kwargs["packages"]
52
+ }
50
53
  except Exception:
51
54
  if os.environ.get("REQUIRE_CYTHON"):
52
55
  raise
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "ulid-transform"
3
- version = "0.8.1"
3
+ version = "0.10.0"
4
4
  description = "Create and transform ULIDs"
5
5
  authors = ["J. Nick Koston <nick@koston.org>"]
6
6
  license = "MIT"
@@ -31,7 +31,7 @@ python = "^3.10"
31
31
  [tool.poetry.group.dev.dependencies]
32
32
  pytest = "^7.0"
33
33
  pytest-cov = "^3.0"
34
- Cython = "^0.29.32"
34
+ Cython = ">=3.0.5"
35
35
  setuptools = "^65.4.1"
36
36
 
37
37
  [tool.semantic_release]
@@ -80,5 +80,5 @@ allow_untyped_defs = true
80
80
 
81
81
 
82
82
  [build-system]
83
- requires = ['setuptools>=65.4.1', 'wheel', 'Cython', "poetry-core>=1.0.0"]
83
+ requires = ['setuptools>=65.4.1', 'wheel', 'Cython>=3.0.2', "poetry-core>=1.0.0"]
84
84
  build-backend = "poetry.core.masonry.api"
@@ -12,9 +12,9 @@ package_data = \
12
12
 
13
13
  setup_kwargs = {
14
14
  'name': 'ulid-transform',
15
- 'version': '0.8.1',
15
+ 'version': '0.10.0',
16
16
  'description': 'Create and transform ULIDs',
17
- 'long_description': '# Fast ULID transformations\n\n<p align="center">\n <a href="https://github.com/bdraco/ulid-transform/actions/workflows/ci.yml?query=branch%3Amain">\n <img src="https://img.shields.io/github/actions/workflow/status/bdraco/ulid-transform/ci.yml?branch=main&label=CI&logo=github&style=flat-square" alt="CI Status" >\n </a>\n <a href="https://codecov.io/gh/bdraco/ulid-transform">\n <img src="https://img.shields.io/codecov/c/github/bdraco/ulid-transform.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">\n </a>\n</p>\n<p align="center">\n <a href="https://python-poetry.org/">\n <img src="https://img.shields.io/badge/packaging-poetry-299bd7?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJJSURBVHgBfZLPa1NBEMe/s7tNXoxW1KJQKaUHkXhQvHgW6UHQQ09CBS/6V3hKc/AP8CqCrUcpmop3Cx48eDB4yEECjVQrlZb80CRN8t6OM/teagVxYZi38+Yz853dJbzoMV3MM8cJUcLMSUKIE8AzQ2PieZzFxEJOHMOgMQQ+dUgSAckNXhapU/NMhDSWLs1B24A8sO1xrN4NECkcAC9ASkiIJc6k5TRiUDPhnyMMdhKc+Zx19l6SgyeW76BEONY9exVQMzKExGKwwPsCzza7KGSSWRWEQhyEaDXp6ZHEr416ygbiKYOd7TEWvvcQIeusHYMJGhTwF9y7sGnSwaWyFAiyoxzqW0PM/RjghPxF2pWReAowTEXnDh0xgcLs8l2YQmOrj3N7ByiqEoH0cARs4u78WgAVkoEDIDoOi3AkcLOHU60RIg5wC4ZuTC7FaHKQm8Hq1fQuSOBvX/sodmNJSB5geaF5CPIkUeecdMxieoRO5jz9bheL6/tXjrwCyX/UYBUcjCaWHljx1xiX6z9xEjkYAzbGVnB8pvLmyXm9ep+W8CmsSHQQY77Zx1zboxAV0w7ybMhQmfqdmmw3nEp1I0Z+FGO6M8LZdoyZnuzzBdjISicKRnpxzI9fPb+0oYXsNdyi+d3h9bm9MWYHFtPeIZfLwzmFDKy1ai3p+PDls1Llz4yyFpferxjnyjJDSEy9CaCx5m2cJPerq6Xm34eTrZt3PqxYO1XOwDYZrFlH1fWnpU38Y9HRze3lj0vOujZcXKuuXm3jP+s3KbZVra7y2EAAAAAASUVORK5CYII=" alt="Poetry">\n </a>\n <a href="https://github.com/ambv/black">\n <img src="https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square" alt="black">\n </a>\n <a href="https://github.com/pre-commit/pre-commit">\n <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">\n </a>\n</p>\n<p align="center">\n <a href="https://pypi.org/project/ulid-transform/">\n <img src="https://img.shields.io/pypi/v/ulid-transform.svg?logo=python&logoColor=fff&style=flat-square" alt="PyPI Version">\n </a>\n <img src="https://img.shields.io/pypi/pyversions/ulid-transform.svg?style=flat-square&logo=python&amp;logoColor=fff" alt="Supported Python versions">\n <img src="https://img.shields.io/pypi/l/ulid-transform.svg?style=flat-square" alt="License">\n</p>\n\nCreate and transform ULIDs\n\nThis library will use the CPP implementation from https://github.com/suyash/ulid if cython is available, and will fallback to pure python if it is not.\n\n## Example\n\n```python\n>>> import ulid_transform\n>>> ulid_transform.ulid_hex()\n\'01869a2ea5fb0b43aa056293e47c0a35\'\n>>> ulid_transform.ulid_now()\n\'0001HZX0NW00GW0X476W5TVBFE\'\n>>> ulid_transform.ulid_at_time(1234)\n\'000000016JC62D620DGYNG2R8H\'\n>>> ulid_transform.ulid_to_bytes(\'0001HZX0NW00GW0X476W5TVBFE\')\nb\'\\x00\\x00c\\xfe\\x82\\xbc\\x00!\\xc0t\\x877\\x0b\\xad\\xad\\xee\'\n>> ulid_transform.bytes_to_ulid(b"\\x01\\x86\\x99?\\xe8\\xf3\\x11\\xbc\\xed\\xef\\x86U.9\\x03z")\n\'01GTCKZT7K26YEVVW6AMQ3J0VT\'\n```\n\n## Installation\n\nInstall this via pip (or your favourite package manager):\n\n`pip install ulid-transform`\n\n## Contributors ✨\n\nThanks to https://github.com/suyash/ulid which provides the cython implementation guts.\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n<!-- prettier-ignore-start -->\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- markdownlint-disable -->\n<!-- markdownlint-enable -->\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n<!-- prettier-ignore-end -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n## Credits\n\nThis package was created with\n[Copier](https://copier.readthedocs.io/) and the\n[browniebroke/pypackage-template](https://github.com/browniebroke/pypackage-template)\nproject template.\n',
17
+ 'long_description': '# Fast ULID transformations\n\n<p align="center">\n <a href="https://github.com/bdraco/ulid-transform/actions/workflows/ci.yml?query=branch%3Amain">\n <img src="https://img.shields.io/github/actions/workflow/status/bdraco/ulid-transform/ci.yml?branch=main&label=CI&logo=github&style=flat-square" alt="CI Status" >\n </a>\n <a href="https://codecov.io/gh/bdraco/ulid-transform">\n <img src="https://img.shields.io/codecov/c/github/bdraco/ulid-transform.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">\n </a>\n</p>\n<p align="center">\n <a href="https://python-poetry.org/">\n <img src="https://img.shields.io/badge/packaging-poetry-299bd7?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJJSURBVHgBfZLPa1NBEMe/s7tNXoxW1KJQKaUHkXhQvHgW6UHQQ09CBS/6V3hKc/AP8CqCrUcpmop3Cx48eDB4yEECjVQrlZb80CRN8t6OM/teagVxYZi38+Yz853dJbzoMV3MM8cJUcLMSUKIE8AzQ2PieZzFxEJOHMOgMQQ+dUgSAckNXhapU/NMhDSWLs1B24A8sO1xrN4NECkcAC9ASkiIJc6k5TRiUDPhnyMMdhKc+Zx19l6SgyeW76BEONY9exVQMzKExGKwwPsCzza7KGSSWRWEQhyEaDXp6ZHEr416ygbiKYOd7TEWvvcQIeusHYMJGhTwF9y7sGnSwaWyFAiyoxzqW0PM/RjghPxF2pWReAowTEXnDh0xgcLs8l2YQmOrj3N7ByiqEoH0cARs4u78WgAVkoEDIDoOi3AkcLOHU60RIg5wC4ZuTC7FaHKQm8Hq1fQuSOBvX/sodmNJSB5geaF5CPIkUeecdMxieoRO5jz9bheL6/tXjrwCyX/UYBUcjCaWHljx1xiX6z9xEjkYAzbGVnB8pvLmyXm9ep+W8CmsSHQQY77Zx1zboxAV0w7ybMhQmfqdmmw3nEp1I0Z+FGO6M8LZdoyZnuzzBdjISicKRnpxzI9fPb+0oYXsNdyi+d3h9bm9MWYHFtPeIZfLwzmFDKy1ai3p+PDls1Llz4yyFpferxjnyjJDSEy9CaCx5m2cJPerq6Xm34eTrZt3PqxYO1XOwDYZrFlH1fWnpU38Y9HRze3lj0vOujZcXKuuXm3jP+s3KbZVra7y2EAAAAAASUVORK5CYII=" alt="Poetry">\n </a>\n <a href="https://github.com/ambv/black">\n <img src="https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square" alt="black">\n </a>\n <a href="https://github.com/pre-commit/pre-commit">\n <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">\n </a>\n</p>\n<p align="center">\n <a href="https://pypi.org/project/ulid-transform/">\n <img src="https://img.shields.io/pypi/v/ulid-transform.svg?logo=python&logoColor=fff&style=flat-square" alt="PyPI Version">\n </a>\n <img src="https://img.shields.io/pypi/pyversions/ulid-transform.svg?style=flat-square&logo=python&amp;logoColor=fff" alt="Supported Python versions">\n <img src="https://img.shields.io/pypi/l/ulid-transform.svg?style=flat-square" alt="License">\n</p>\n\nCreate and transform ULIDs\n\nThis library will use the CPP implementation from https://github.com/suyash/ulid if cython is available, and will fallback to pure python if it is not.\n\n## Example\n\n```python\n>>> import ulid_transform\n>>> ulid_transform.ulid_hex()\n\'01869a2ea5fb0b43aa056293e47c0a35\'\n>>> ulid_transform.ulid_now()\n\'0001HZX0NW00GW0X476W5TVBFE\'\n>>> ulid_transform.ulid_at_time(1234)\n\'000000016JC62D620DGYNG2R8H\'\n>>> ulid_transform.ulid_to_bytes(\'0001HZX0NW00GW0X476W5TVBFE\')\nb\'\\x00\\x00c\\xfe\\x82\\xbc\\x00!\\xc0t\\x877\\x0b\\xad\\xad\\xee\'\n>> ulid_transform.bytes_to_ulid(b"\\x01\\x86\\x99?\\xe8\\xf3\\x11\\xbc\\xed\\xef\\x86U.9\\x03z")\n\'01GTCKZT7K26YEVVW6AMQ3J0VT\'\n>>> ulid_transform.ulid_to_bytes_or_none(\'0001HZX0NW00GW0X476W5TVBFE\')\nb\'\\x00\\x00c\\xfe\\x82\\xbc\\x00!\\xc0t\\x877\\x0b\\xad\\xad\\xee\'\n>>> ulid_transform.ulid_to_bytes_or_none(None)\n>>> ulid_transform.bytes_to_ulid_or_none(b\'\\x00\\x00c\\xfe\\x82\\xbc\\x00!\\xc0t\\x877\\x0b\\xad\\xad\\xee\')\n\'0001HZX0NW00GW0X476W5TVBFE\'\n>>> ulid_transform.bytes_to_ulid_or_none(None)\n```\n\n## Installation\n\nInstall this via pip (or your favourite package manager):\n\n`pip install ulid-transform`\n\n## Contributors ✨\n\nThanks to https://github.com/suyash/ulid which provides the cython implementation guts.\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n<!-- prettier-ignore-start -->\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- markdownlint-disable -->\n<!-- markdownlint-enable -->\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n<!-- prettier-ignore-end -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n## Credits\n\nThis package was created with\n[Copier](https://copier.readthedocs.io/) and the\n[browniebroke/pypackage-template](https://github.com/browniebroke/pypackage-template)\nproject template.\n',
18
18
  'author': 'J. Nick Koston',
19
19
  'author_email': 'nick@koston.org',
20
20
  'maintainer': 'None',
@@ -0,0 +1,21 @@
1
+ __version__ = "0.10.0"
2
+
3
+ from .ulid_impl import (
4
+ bytes_to_ulid,
5
+ bytes_to_ulid_or_none,
6
+ ulid_at_time,
7
+ ulid_hex,
8
+ ulid_now,
9
+ ulid_to_bytes,
10
+ ulid_to_bytes_or_none,
11
+ )
12
+
13
+ __all__ = [
14
+ "ulid_now",
15
+ "ulid_at_time",
16
+ "ulid_hex",
17
+ "ulid_to_bytes",
18
+ "bytes_to_ulid",
19
+ "ulid_to_bytes_or_none",
20
+ "bytes_to_ulid_or_none",
21
+ ]
@@ -2,6 +2,7 @@
2
2
  from libcpp.string cimport string
3
3
 
4
4
  from time import time
5
+ from typing import Optional
5
6
 
6
7
  import cython
7
8
 
@@ -28,3 +29,13 @@ def _bytes_to_ulid(ulid_bytes: bytes) -> str:
28
29
  if len(ulid_bytes) != 16:
29
30
  raise ValueError(f"ULID bytes be 16 bytes: {ulid_bytes}")
30
31
  return _cpp_bytes_to_ulid(ulid_bytes).decode("ascii")
32
+
33
+ def _ulid_to_bytes_or_none(ulid_str: Optional[str]) -> Optional[bytes]:
34
+ if ulid_str is None or len(ulid_str) != 26:
35
+ return None
36
+ return _cpp_ulid_to_bytes(ulid_str.encode("ascii"))
37
+
38
+ def _bytes_to_ulid_or_none(ulid_bytes: Optional[bytes]) -> Optional[str]:
39
+ if ulid_bytes is None or len(ulid_bytes) != 16:
40
+ return None
41
+ return _cpp_bytes_to_ulid(ulid_bytes).decode("ascii")
@@ -410,10 +410,33 @@ def bytes_to_ulid(value: bytes) -> str:
410
410
  return _encode(value)
411
411
 
412
412
 
413
+ def ulid_to_bytes_or_none(ulid: str | None) -> bytes | None:
414
+ """Convert an ulid to bytes."""
415
+ if ulid is None:
416
+ return None
417
+ try:
418
+ return ulid_to_bytes(ulid)
419
+ except ValueError:
420
+ return None
421
+
422
+
423
+ def bytes_to_ulid_or_none(_bytes: bytes | None) -> str | None:
424
+ """Convert bytes to a ulid."""
425
+ if _bytes is None:
426
+ return None
427
+ try:
428
+ return bytes_to_ulid(_bytes)
429
+ except ValueError:
430
+ return None
431
+
432
+
413
433
  try:
414
434
  from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
415
435
  _bytes_to_ulid as bytes_to_ulid,
416
436
  )
437
+ from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
438
+ _bytes_to_ulid_or_none as bytes_to_ulid_or_none,
439
+ )
417
440
  from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
418
441
  _ulid_at_time as ulid_at_time,
419
442
  )
@@ -423,5 +446,8 @@ try:
423
446
  from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
424
447
  _ulid_to_bytes as ulid_to_bytes,
425
448
  )
449
+ from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
450
+ _ulid_to_bytes_or_none as ulid_to_bytes_or_none,
451
+ )
426
452
  except ImportError: # pragma: no cover
427
453
  pass # pragma: no cover
@@ -1,5 +0,0 @@
1
- __version__ = "0.8.1"
2
-
3
- from .ulid_impl import bytes_to_ulid, ulid_at_time, ulid_hex, ulid_now, ulid_to_bytes
4
-
5
- __all__ = ["ulid_now", "ulid_at_time", "ulid_hex", "ulid_to_bytes", "bytes_to_ulid"]
File without changes