Skip to content

Bug: broken package on pre/2.1 branch #1357

@d-v-b

Description

@d-v-b
# /// script
# requires-python = ">=3.11"
# dependencies = [
#     "datajoint @ git+https://github.com/datajoint/datajoint-python.git@82a9223b484f639bd2cf26a9d48bc29d56cda8aa",
# ]
# ///
"""
Reproducer for circular import bug in datajoint pre/v2.1 branch.

Run with: uv run reproducer.py

Expected: datajoint imports successfully and prints version
Actual: ImportError due to missing builtin_codecs module

The issue is in datajoint/codecs.py:590 which tries to import:
    from . import builtin_codecs as _builtin_codecs
but builtin_codecs does not exist in the package.
"""

import datajoint

print(f"datajoint version: {datajoint.__version__}")
(dj-zarr-codecs) d-v-b@pc ➜  dj-zarr-codecs git:(chore/repo-housekeeping) ✗ uv run reproducer.py 
Traceback (most recent call last):
  File "/home/d-v-b/dev/dj-zarr-codecs/reproducer.py", line 20, in <module>
    import datajoint
  File "/home/d-v-b/.cache/uv/environments-v2/reproducer-561c46f342a40bb5/lib/python3.11/site-packages/datajoint/__init__.py", line 65, in <module>
    from .codecs import (
  File "/home/d-v-b/.cache/uv/environments-v2/reproducer-561c46f342a40bb5/lib/python3.11/site-packages/datajoint/codecs.py", line 590, in <module>
    from . import builtin_codecs as _builtin_codecs  # noqa: F401, E402
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: cannot import name 'builtin_codecs' from partially initialized module 'datajoint' (most likely due to a circular import) (/home/d-v-b/.cache/uv/environments-v2/reproducer-561c46f342a40bb5/lib/python3.11/site-packages/datajoint/__init__.py)

The root cause is the misconfiguration of setuptools in pyproject.toml. Setuptools is not finding subpackages (like builtin_codecs) and so they are not being packaged. The fix is to fix the setuptools configuration, or even better, use a modern build system like hatchling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviortriageIndicates issues, pull requests, or discussions need to be reviewed for the first time

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions