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

Fix importing build extension for Python >= 3.8 in Windows #12

Merged
merged 4 commits into from
May 27, 2021

Conversation

diegoferigo
Copy link
Owner

@diegoferigo diegoferigo commented May 27, 2021

Fixes #8

Apparently the problem is not a bug but a change of behavior in Windows. Refer to add_dll_directory for more details.

Differently from many, I implemented this fix using a context manager that automatically closes the dll cookies. Since this functionality is necessary to properly import SWIG bindings in the affected platform (I suspect that also pybind11 is affected), I added the context manager to cmake-build-extension so that it can be used downstream. The only change is that, if the context manager is used e.g. in the __init__.py file, the downstream package has to mark cmake-build-extension as install_require and no longer as only setup_require (or, in a more modern setup, in the requires field of pyproject.toml).

from cmake_build_extension import build_extension_env

with build_extension_env():
    # Assuming that 'bindings' is the name of the SWIG / pybind11 module
    from . import bindings

Related resources from which this PR was inspired:

@diegoferigo diegoferigo added the enhancement New feature or request label May 27, 2021
@diegoferigo diegoferigo self-assigned this May 27, 2021
@diegoferigo diegoferigo merged commit cefa43e into master May 27, 2021
@diegoferigo diegoferigo deleted the fix/win branch May 27, 2021 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Example cannot be imported in Windows if python >= 3.8
1 participant