mevimo / youbit

Host any type of file on YouTube
MIT License
673 stars 27 forks source link

fix warning: Index should be typed for more efficient access #6

Closed LinuxUserGD closed 2 years ago

LinuxUserGD commented 2 years ago

Should fix import error "no module named youbit.ecc.creedsolo" and warnings "Index should be typed for more efficient access".

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 187, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.10/runpy.py", line 146, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.10/runpy.py", line 110, in _get_module_details
    __import__(pkg_name)
  File "/home/user/.local/lib/python3.10/site-packages/youbit/__init__.py", line 9, in <module>
    from .yb import Encoder, Decoder
  File "/home/user/.local/lib/python3.10/site-packages/youbit/yb.py", line 19, in <module>
    import youbit.ecc.ecc as youbit_ecc
  File "/home/user/.local/lib/python3.10/site-packages/youbit/ecc/ecc.py", line 4, in <module>
    from youbit.ecc.creedsolo import RSCodec
ModuleNotFoundError: No module named 'youbit.ecc.creedsolo'
mevimo commented 2 years ago

I would like to avoid using pyximport, as the Cython docs recommend not using it for end-users. The Cython extension should be compiled during pip install.

How and when did you get the ModuleNotFoundError?

LinuxUserGD commented 2 years ago

Seems like the cython extension is not compiled during pip install, tried running

python3.10 -m pip install -U "youbit @ git+https://github.com/MeViMo/youbit.git"
python3.10 -m youbit download

edit: works without adding pyximport after changing setup.py to

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("youbit/ecc/creedsolo.pyx")
)
mevimo commented 2 years ago

Strange. I assume you're on linux and have a C compiler installed?

LinuxUserGD commented 2 years ago

Strange. I assume you're on linux and have a C compiler installed?

Using gcc (Gentoo 11.3.0 p4) 11.3.0 on Mocaccino OS, build_ext is not executed when running python setup.py build_ext. The pyproject.toml seems to replace build.py, so cython extension is only built with pip install after adding extension to setup_args I think, see https://stackoverflow.com/a/66479252

from setuptools import setup, Extension
from Cython.Build import cythonize

creedsolo = [Extension('creedsolo', ['youbit/ecc/creedsolo.pyx'], include_dirs = ['youbit/ecc'])]
setup_args = dict(
    ext_modules = cythonize(creedsolo)
)
setup(**setup_args)
mevimo commented 2 years ago

Note that the setup.py file is (was) there only for backward compatibility for editable installs.

I just pushed v0.1.4 which just foregoes the setup.py to let Poetry build one when it needs it for a wheel. Could you try again with pip install youbit==0.1.4 --no-binary :all:? If it persists I might have to add a complete setup.py for backward compatibility.

LinuxUserGD commented 2 years ago

I just pushed v0.1.4 which just foregoes the setup.py to let Poetry build one when it needs it for a wheel. Could you try again with pip install youbit==0.1.4 --no-binary :all:? If it persists I might have to add a complete setup.py for backward compatibility.

Thanks, works now with pip install and creedsolo.cpython-310-x86_64-linux-gnu.so is included in /usr/lib/python3.10/site-packages/youbit/ecc