Skip to content

Cannot build numpy in specific situation #60

Closed
@rmartin16

Description

@rmartin16

Describe the bug

When the number of characters for the parent file path for the mobile-forge repo is sufficiently low, the numpy build fails.

File "/opt/homebrew/Cellar/[email protected]/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 548, in run
with Popen(*popenargs, **kwargs) as process:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/opt/homebrew/Cellar/[email protected]/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 1955, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/Users/marko/Documents/Repos/mobileforge2/build/cp311/numpy/1.26.2/venv3.11-ios_13_0_arm64_iphoneos/cross/bin/ninja'

ERROR Backend subprocess exited when trying to invoke get_requires_for_build_wheel
--------------------------------------------------------------------------------
<<< Return code: 1
********************************************************************************
Failed build: numpy 1.26.2 for iphoneos 13.0 on arm64
********************************************************************************
Traceback (most recent call last):
  File "/Users/marko/Documents/Repos/mobileforge2/src/forge/build.py", line 296, in build
    self._build()
  File "/Users/marko/Documents/Repos/mobileforge2/src/forge/build.py", line 563, in _build
    self.cross_venv.run(
  File "/Users/marko/Documents/Repos/mobileforge2/src/forge/cross.py", line 375, in run
    return subprocess.run(logfile, *args, **self.cross_kwargs(kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/marko/Documents/Repos/mobileforge2/src/forge/subprocess.py", line 49, in run
    raise stdlib_subprocess.CalledProcessError(return_code, args)
subprocess.CalledProcessError: Command '(['python', '-m', 'build', '--no-isolation', '--wheel', '--outdir', '/Users/marko/Documents/Repos/mobileforge2/dist'],)' returned non-zero exit status 1.

Steps to reproduce

Clone mobile-forge in to /tmp and attempt to build numpy.

Expected behavior

Numpy can build regardless of where mobile-forge exists in the file system.

The underlying problem is the shebang that pip creates for ninja which is used by numpy's build system. Numpy invokes ninja with this file:

> cat mobile-forge/build/cp311/numpy/1.26.2/venv3.11-ios_13_0_arm64_iphoneos/cross/bin/ninja

#!/Users/user/github/beeware/mobile-forge/build/cp311/numpy/1.26.2/venv3.11-ios_13_0_arm64_iphoneos/cross/bin/python3.11
# -*- coding: utf-8 -*-
import re
import sys
from ninja import ninja
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(ninja())

The problem here is that venv3.11-ios_13_0_arm64_iphoneos/cross/bin/python3.11 is not a binary; it is another python script that eventually calls os.execv() for venv3.11-ios_13_0_arm64_iphoneos/build/bin/python3.11....and this python3.11 is a binary.

pip creates this shebang when installing ninja. As you can see there, if the shebang is long enough, it creates a shebang that has /bin/sh run venv3.11-ios_13_0_arm64_iphoneos/build/bin/python3.11. This avoids this issue altogether.

pip does a lot of introspection to determine what to use for the shebang....and a lot of the possible values come from sysconfig. Given how much crossenv is messing with sysconfig, this could possibly be considered a bug in crossenv.

Screenshots

No response

Environment

  • Operating System: Sonoma
  • Python version: 3.11
  • Software versions:

Logs

numpy-1.26.2-cp311-ios_13_0_x86_64_iphonesimulator.log
numpy-1.26.2-cp311-ios_13_0_arm64_iphonesimulator.log
numpy-1.26.2-cp311-ios_13_0_arm64_iphoneos.log

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions