Skip to content

cffi>=1.16.0 failing to install on mingw #21

@abravalheri

Description

@abravalheri

Recently I was changing something unrelated in setuptools-rust and I noticed that pip install cffi started to fail in mingw. When I tried to cap the version with cffi<1.16 everything installed well.

Which lead me to investigate what is causing this.
I created this repo just to use github CI (since I don't have access to a mingw environment to run the tests manually).

The reproducer (encoded in the Github workflow of the repository mentioned above) is relatively simple:

  • Given: a mingw environment setup using msys2 and with the following packages installed:
    • mingw-w64-{i686/x86_64}-python ⇒ This should give you Python 3.11.6
    • mingw-w64-{i686/x86_64}-python-pip
    • mingw-w64-{i686/x86_64}-openssl
    • mingw-w64-{i686/x86_64}-toolchain
      (The choice between i686 and x86_64 depends on the mingw architecture you are running)
  1. Install the latest versions of pip, setuptools, wheel:
    python -m pip install -U pip setuptools wheel
    python -m pip list
    # Package    Version
    # ---------- -------
    # distlib    0.3.7
    # pip        23.2.1
    # setuptools 68.2.2
    # wheel      0.41.2
  2. Attempt to install the latest version of cffi
    python -m pip -v install -U "cffi>=1.16.0"
    # ...
    #     File "D:/a/_temp/msys64/tmp/pip-build-env-l9qomo_f/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 341, in run_setup
    #       exec(code, locals())
    #     File "<string>", line 126, in <module>
    #     File "<string>", line 105, in uses_msvc
    #     File "D:/a/_temp/msys64/tmp/pip-build-env-l9qomo_f/overlay/lib/python3.11/site-packages/setuptools/_distutils/command/config.py", line 223, in try_compile
    # ...
    # distutils.errors.DistutilsPlatformError: --plat-name must be one of ('win32', 'win-amd64', 'win-arm32', 'win-arm64')
    # ...
    ... and observe the error (triggered by https://github.com/python-cffi/cffi/blob/v1.16.0/setup.py#L105 - https://github.com/python-cffi/cffi/blob/v1.16.0/setup.py#L126).

As show in the Github workflow there are a few interesting things:

  • The error does not happen for cffi<1.16
    (even if I install setuptools and export SETUPTOOLS_USE_DISTUTILS=local, which I expect to replace any imports from distutils with setuptools._distutils even if setuptools is not imported -- including during the build of cffi).
  • The error does not happen if I pass --no-build-isolation to pip

I can see that mingw==1.16.0 added pyproject.toml which makes pip treat the installation process differently (instead of running python setup.py ... it will call the PEP 517 hooks), and the error seems to happen when pip calls the PEP 517 hook: setuptools.build_meta.get_requires_for_build_wheel (which is internally translated by setuptools into a patched egg_info call -- it is a lot of patching...).

Something else that I am not understanding (probably unrelated) is why in some cases distutils is still being loaded from setuptools._distutils even when SETUPTOOLS_USE_DISTUTILS=stdlib.


The reason why I opened the issue is to bring this problem to your attention and ask if you have any suggestions, tips that can help to solve this problem.

In principle it seems to be a compatibility issue with the procedure setuptools employs to support backwards compatibility with packages that need setup_requires, but I still couldn't figure out exactly was is causing the problem.

The fact that cffi<1.16 is compatible with setuptools._distutils puzzles me.

Moreover, cffi==1.16 works fine with pip install --no-build-isolation.
So when running the other PEP 517 hooks, distutils/_msvccompiler.py never seems to be used, but for that specific patched egg_info, this problematic code path is triggered. Any idea why is that the case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions