Open The-Compiler opened 3 years ago
Can you reproduce this behaviour with (run in root of git repository):
#!/bin/sh
set -xe
python3.9 -m pip uninstall -y adblock
maturin build --release --interpreter python3.9
python3.9 -m pip install --user target/wheels/adblock-0.4.0-cp39-*.whl
python3.9 -c "import adblock; print('success! version:', adblock.__version__)"
I can't, unfortunately.
It looks like that
adblock
module is only required for type annotations?
That's right. It's the most straightforward way I found to make a PEP 561 compatible package.
Is the
__init__.py
really required, and is the import even correct?
I'm not sure, but it is the pattern that a number of PyO3 examples seem to follow. See for example:
I think this is fixed in https://github.com/ArniDagur/python-adblock/commit/dc33223fcb1583bf31b89474ec299d45d8f80ef0
I have the same issue, and dc33223 did not fix it for me.
I'm seeing this on the package installed system-wide via setup.py
@b3n @ddevault Ah, I had been trying to reproduce this when installing with --user
. I can reproduce when:
python-adblock
git repository.python3 -c "import adblock"
When I leave the git repository, import adblock
works again. Does this match your experience, or does it also happen outside of the git repo?
I've never tried it from the git repository, and that's not how I would use it anyway - I am packaging this for Alpine Linux.
This seemed to surface for Alpine when we went from python 3.8 to 3.9...
+1 inside the git directory:
$ python3 -c "import adblock"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/stefan/projects/python-adblock/adblock/__init__.py", line 1, in <module>
from adblock.adblock import __version__, Engine, FilterSet, BlockerResult, UrlSpecificResources
ModuleNotFoundError: No module named 'adblock.adblock'
There is no abi3.so inside the adblock/ directory even after the build... (maybe it's not supposed to be there, I don't know)
After building via
maturin build
and installing the wheel via pip, runningpython3 -c "import adblock"
results in:This is because the
adblock
module gets imported, and due tofrom .adblock
import, Python tries to importadblock.adblock
.When trying again outside of the git repository, the import works fine.
It looks like that
adblock
module is only required for type annotations? Is the__init__.py
really required, and is the import even correct? Perhaps it could be moved tosrc/
somehow to not interfere with the native extension module?