Skip to content
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ __pycache__
/dist/
/build/
/docs/build

/ulid/_version.py
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Fixed
when a value on an exact millisecond multiplies to just below that integer as a float.
* :meth:`.ULID.from_datetime` and :meth:`.ULID.from_timestamp` raise a :exc:`ValueError` for values
before the Unix epoch instead of a bare :exc:`OverflowError`.
* ``import ulid`` no longer fails when the package metadata is missing, e.g. in applications frozen
with cx_Freeze or PyInstaller. The version is now written into the package at build time.

`4.1.0`_ - 2026-10-27
---------------------
Expand Down
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ If you want to run all checks against your staged or unstaged files manually:
uv run prek run --all-files
```

### Troubleshooting: `cannot import name '_version' from 'ulid'`

The package version is written to `ulid/_version.py` when the package is built or installed, and the
file is not tracked by Git. If it is missing (e.g. after `git clean -X`), `import ulid` fails. Reinstall
the package into your environment to regenerate it:

```bash
uv sync --reinstall-package python-ulid
```

---

## 🎨 Coding Standards
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ ulid = "ulid.__main__:entrypoint"
[tool.hatch.version]
source = "vcs"

[tool.hatch.build.hooks.vcs]
version-file = "ulid/_version.py"

[tool.hatch.build.targets.wheel]
packages = [
"ulid",
Expand Down
6 changes: 4 additions & 2 deletions ulid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from collections.abc import Callable
from datetime import datetime
from datetime import UTC
from importlib.metadata import version
from threading import Lock
from typing import Any
from typing import cast
Expand All @@ -21,6 +20,7 @@
except ImportError:
from typing_extensions import override # type: ignore

from ulid import _version
from ulid import base32
from ulid import constants

Expand All @@ -33,7 +33,9 @@
from pydantic_core import CoreSchema


__version__ = version("python-ulid")
# Generated at build time so that the version is available even without package metadata,
# e.g. in applications frozen with cx_Freeze or PyInstaller.
__version__ = _version.__version__


RandomnessSource = Callable[[int], bytes]
Expand Down
Loading