Skip to content

sysconfig --generate-posix-vars fails because of AttributeError #103130

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

Open
nomadsinteractive opened this issue Mar 30, 2023 · 5 comments
Open
Labels
stdlib Python modules in the Lib dir topic-sysconfig type-bug An unexpected behavior, bug, or error

Comments

@nomadsinteractive
Copy link

nomadsinteractive commented Mar 30, 2023

Bug report

When cross compiling python on Windows system, -m sysconfig --generate-posix-vars fails.
Raising:

AttributeError: module 'sys' has no attribute 'abiflags'

Yeah, cross compiling python is a daunting task, especially on Windows. But I want to make a first little step.

The problem lies within the function '_get_sysconfigdata_name' in sysconfig.py

def _get_sysconfigdata_name():
    multiarch = getattr(sys.implementation, '_multiarch', '')
    return os.environ.get(
        '_PYTHON_SYSCONFIGDATA_NAME',
        f'_sysconfigdata_{sys.abiflags}_{sys.platform}_{multiarch}',
    )

I think we should hornor the environment variable first, then fall to the fallback value.
So changing the function like this below

def _get_sysconfigdata_name():
    multiarch = getattr(sys.implementation, '_multiarch', '')
    return os.environ.get(
        '_PYTHON_SYSCONFIGDATA_NAME',
        None
    ) or f'_sysconfigdata_{sys.abiflags}_{sys.platform}_{multiarch}'

This would help us to find a work around when cross compiling python on Windows.

Thanks

A clear and concise description of what the bug is.
Include a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example), if possible.

Your environment

  • CPython versions tested on: 3.10.7
  • Operating system and architecture: Windows 10 x86_64
@nomadsinteractive nomadsinteractive added the type-bug An unexpected behavior, bug, or error label Mar 30, 2023
@arhadthedev arhadthedev added the stdlib Python modules in the Lib dir label Mar 30, 2023
@arhadthedev
Copy link
Member

@FFY00 (as a sysconfig expert)

@FFY00
Copy link
Member

FFY00 commented Mar 30, 2023

@arhadthedev thanks for the ping! FYI we have an expert-sysconfig label now too, which is helpful to, as on top of letting interested people subscribe to it, it also allows us to easily filter issues.

@FFY00
Copy link
Member

FFY00 commented Mar 30, 2023

@nomadsinteractive thank you for the report!

Yeah, cross compiling python is a daunting task, especially on Windows. But I want to make a first little step.

I agree, this is a major paint point, and something I am trying to look into how to fix.

I think we should hornor the environment variable first, then fall to the fallback value.

We are doing that, it's just the code is assuming sys.abiflags is set, but it is not actually guaranteed!

https://github.com/python/cpython/blob/f192a558f538489ad1be30aa145e71d942798d1c/Python/sysmodule.c#L3173-L31775

Your fix seem the okay, but I'd actually do the same as we do for _multiarch.

Do you want to submit a PR?


I now want to look in which cases sys.abiflags is not defined, and all the other cases where it is assumes to be defined.

@FFY00
Copy link
Member

FFY00 commented Mar 30, 2023

@nomadsinteractive actually, would you be able to share the instructions to reproduce this issue? It would help a lot in my debugging.

@nomadsinteractive
Copy link
Author

@FFY00
I'd like to submit a PR, it would be my pleasure.
But I was assuming that what I proposed is a quick and dirty work around. So I'm asking experts, like you, who are aiming for the bigger picture, for advices. My fix seems be okay, but is there a more than okay way to do it?

And for the sys.abiflags, documents on this page https://docs.python.org/3/library/sys.html says

On POSIX systems where Python was built with the standard configure script, this contains the ABI flags as specified by PEP 3149.

For Windows builds, I guess it's undefined behavior.

And about reproducing, it's a bit tricky now, the story begins here:
microsoft/vcpkg#30501
The vcpkg community are trying to cross compiling python3.
You can try ./vcpkg install python3 --triplet arm64-android after getting the latest version of vcpkg. It would probably fail, by some other issues, not by this one, because of unmerged pull requests. But eventually we'll get here.

It may not be easy to reproduce this issue, but finding the reason is easy: sys.abiflags may not be defined in Windows builds of Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-sysconfig type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants