Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import name 'safer_name' from 'wheel.bdist_wheel' #3

Closed
mercurytoxic opened this issue Nov 10, 2024 · 5 comments
Closed

cannot import name 'safer_name' from 'wheel.bdist_wheel' #3

mercurytoxic opened this issue Nov 10, 2024 · 5 comments
Assignees

Comments

@mercurytoxic
Copy link

from wheel.bdist_wheel import safer_name, get_platform

While trying to compile electrum-ecc on Archlinux I get this error.

Traceback (most recent call last):
  File "/usr/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 389, in <module>
    main()
  File "/usr/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 373, in main
    json_out["return_val"] = hook(**hook_input["kwargs"])
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/pyproject_hooks/_in_process/_in_process.py", line 143, in get_requires_for_build_wheel
    return hook(config_settings)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
    return self._get_build_requires(config_settings, requirements=['wheel'])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
    self.run_setup()
  File "/usr/lib/python3.12/site-packages/setuptools/build_meta.py", line 311, in run_setup
    exec(code, locals())
  File "<string>", line 13, in <module>
ImportError: cannot import name 'safer_name' from 'wheel.bdist_wheel' (/usr/lib/python3.12/site-packages/wheel/bdist_wheel.py)

ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel

I noted that the function safer_name is part of the module _bdist_wheel and NOT part of the module bdist_wheel as referenced in the above line.

@ecdsa
Copy link
Member

ecdsa commented Nov 14, 2024

I noted that the function safer_name is part of the module _bdist_wheel and NOT part of the module bdist_wheel as referenced in the above line.

How did you find that? Do you really have a _bdist_wheel.py module in /usr/lib/python3.12/site-packages/wheel/?
AFAICT _bdist_wheel is just the name under which the class bdist_wheel is imported.

@mercurytoxic
Copy link
Author

Yes I do. On Archlinux's python-wheel 0.44.0-2

$ find /usr/lib/python3.12/site-packages/wheel/ -name "*bdist_wheel.py"
/usr/lib/python3.12/site-packages/wheel/_bdist_wheel.py
/usr/lib/python3.12/site-packages/wheel/bdist_wheel.py

Another way to see it is listing the modules from the package wheel with:

import pkgutil
import wheel

modules = [module.name for module in pkgutil.iter_modules(wheel.__path__)]
print(modules)

which gives:

$ python src/electrum-ecc-0.0.3/test-2.py 
['__main__', '_bdist_wheel', '_setuptools_logging', 'bdist_wheel', 'cli', 'macosx_libfile', 'metadata', 'util', 'wheelfile']

If you list the functions of wheel.bdist_wheel with :

import wheel.bdist_wheel

print(dir(wheel.bdist_wheel))

You get:

['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '__warningregistry__', 'bdist_wheel', 'warn']

But if you list the ones from wheel._bdist_wheel you get:

['BytesGenerator', 'Callable', 'Command', 'EmailPolicy', 'Generator', 'Iterable', 'Literal', 'PY_LIMITED_API_PATTERN', 'Sequence', 'TYPE_CHECKING', 'WheelFile', 'ZIP_DEFLATED', 'ZIP_STORED', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_is_32bit_interpreter', '_packaging_version', 'annotations', 'bdist_wheel', 'cast', 'get_abi_tag', 'get_flag', 'get_platform', 'iglob', 'log', 'os', 'pkginfo_to_metadata', 'python_tag', 're', 'remove_readonly', 'remove_readonly_exc', 'rmtree', 'safe_name', 'safe_version', 'safer_name', 'safer_version', 'setuptools', 'setuptools_major_version', 'shutil', 'stat', 'struct', 'sys', 'sysconfig', 'tags', 'warnings', 'wheel_version']

which includes the above mentioned safer_name function.

A brief google of packages with leading underscores :
Non-Public Modules

Non-Public Modules
...
In your own Python projects, you may have modules that provide code for internal use only. In those cases, you can use a leading underscore in their names to tell other developers that they shouldn’t use these modules directly in their code.

@ecdsa
Copy link
Member

ecdsa commented Nov 15, 2024

ok, I guess we should not expect that function to be available.
Maybe we could redeclare safer_name in our setup.py:

import pkg_resources
def safer_name(name):
    return pkg_resources.safe_name(name).replace('-', '_')

does that fix it for you, or are there other imports that are failing?

@SomberNight
Copy link
Member

SomberNight commented Nov 18, 2024

Looks like this is a change in wheel 0.44, which started deprecating the bdist_wheel module.
See pypa/wheel#631

also ref: pypa/setuptools#4369

@SomberNight SomberNight self-assigned this Nov 18, 2024
@SomberNight
Copy link
Member

I think it should be fixed with 0be1ca2.
Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants