mongodb-labs / python-bsonjs

A fast BSON to MongoDB Extended JSON converter for Python - This Repository is NOT a supported MongoDB product
Apache License 2.0
40 stars 10 forks source link

PYTHON-4163 Rename src/ to bsonjs/ to avoid setuptools bug that shadows bson package #53

Closed ShaneHarvey closed 9 months ago

ShaneHarvey commented 9 months ago

https://jira.mongodb.org/browse/PYTHON-4163

New installed site-packages looks like this:

$ ls /Users/shane/work/pycharm/python-bsonjs/lib/python3.11/site-packages/       
__pycache__                     build                           easy-install.pth                pkg_resources                   setuptools-67.4.0.dist-info
_distutils_hack                 build-0.10.0.dist-info          gridfs                          pymongo                         setuptools-67.4.0.virtualenv
_virtualenv.pth                 check_manifest-0.49.dist-info   packaging                       pymongo-4.4.1.dist-info         wheel
_virtualenv.py                  check_manifest.py               packaging-23.1.dist-info        pyproject_hooks                 wheel-0.38.4.dist-info
bson                            distutils-precedence.pth        pip                             pyproject_hooks-1.0.0.dist-info wheel-0.38.4.virtualenv
bsonjs                          dns                             pip-23.0.1.dist-info            python_bsonjs-0.3.0.dist-info
bsonjs.abi3.so                  dnspython-2.4.1.dist-info       pip-23.0.1.virtualenv           setuptools
$  ls /Users/shane/work/pycharm/python-bsonjs/lib/python3.11/site-packages/bsonjs/
bson     bsonjs.c bsonjs.h common   jsonsl

The packages and loaded as expected:

$ python
>>> import bsonjs
>>> bsonjs.__spec__
ModuleSpec(name='bsonjs', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x100659910>, origin='/Users/shane/git/python-bsonjs/bsonjs.abi3.so')
>>> import bson
>>> bson.encode({})
b'\x05\x00\x00\x00\x00'
>>> import jsonsl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'jsonsl'
blink1073 commented 9 months ago
        To avoid accidental inclusion of unwanted files or directories,
        setuptools will not proceed with this build.

        If you are trying to create a single distribution with multiple packages
        on purpose, you should not rely on automatic discovery.
        Instead, consider the following options:

        1. set up custom discovery (`find` directive with `include` or `exclude`)
        2. use a `src-layout`
        3. explicitly set `py_modules` or `packages` with a list of names

        To find more information, look for "package discovery" on setuptools docs.
        [end of output]
ShaneHarvey commented 9 months ago

Fixed the wheel error by adding this:

[tool.setuptools]
packages = ["bsonjs"]