kivy / kivy-ios

Toolchain for compiling Python / Kivy / other libraries for iOS
https://kivy.org/docs/guide/packaging-ios.html
MIT License
781 stars 240 forks source link

Materialyoucolor-python Recipe #895

Closed MNwake closed 7 months ago

MNwake commented 8 months ago

Mac: M3 Sonoma 14.4 Python: 3.12, 3.10 https://github.com/T-Dynamos/materialyoucolor-python

KivyMD version 2.0.1 requires materialyoucolor for its theme_manager.

when I toolchain pip install I get this error:

(venv) theokoester@Theos-MacBook-Pro build % toolchain pip3 install https://github.com/T-Dynamos/materialyoucolor-python/archive/main.zip
[INFO    ] Using the bundled version for recipe 'freetype'
[INFO    ] Include dir added: {arch.arch}/freetype
[INFO    ] Using the bundled version for recipe 'hostopenssl'
[INFO    ] Using the bundled version for recipe 'hostpython3'
[INFO    ] Global: hostpython located at /Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/bin/python
[INFO    ] Global: hostpgen located at /Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/bin/pgen
[INFO    ] Using the bundled version for recipe 'ios'
[INFO    ] Using the bundled version for recipe 'kivy'
[INFO    ] Using the bundled version for recipe 'libffi'
[INFO    ] Include dir added: {arch.arch}/ffi
[INFO    ] Using the bundled version for recipe 'libjpeg'
[INFO    ] Include dir added: {arch.arch}/libjpeg
[INFO    ] Using the bundled version for recipe 'libpng'
[INFO    ] Include dir added: common/libpng
[INFO    ] Using the bundled version for recipe 'openssl'
[INFO    ] Include dir added: {arch.arch}/openssl
[INFO    ] Using the bundled version for recipe 'pillow'
[INFO    ] Using the bundled version for recipe 'pyobjus'
[INFO    ] Using the bundled version for recipe 'python3'
[INFO    ] Using the bundled version for recipe 'sdl2'
[INFO    ] Include dir added: common/sdl2
[INFO    ] Using the bundled version for recipe 'sdl2_image'
[INFO    ] Include dir added: common/sdl2_image
[INFO    ] Using the bundled version for recipe 'sdl2_mixer'
[INFO    ] Include dir added: common/sdl2_mixer
[INFO    ] Using the bundled version for recipe 'sdl2_ttf'
[INFO    ] Include dir added: common/sdl2_ttf
[INFO    ] Executing pip with: ['install', '--isolated', '--prefix', '/Users/theokoester/dev/projects/kivy-ios/build/dist/root/python3', 'https://github.com/T-Dynamos/materialyoucolor-python/archive/main.zip']
[INFO    ] Running Shell: /Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/bin/pip3 ('install', '--isolated', '--prefix', '/Users/theokoester/dev/projects/kivy-ios/build/dist/root/python3', 'https://github.com/T-Dynamos/materialyoucolor-python/archive/main.zip') {'_env': {'CC': '/bin/false', 'CXX': '/bin/false', 'PYTHONPATH': '/Users/theokoester/dev/projects/kivy-ios/build/dist/root/python3/lib/python3.10/site-packages', 'PYTHONOPTIMIZE': '2'}, '_iter': True, '_out_bufsize': 1, '_err_to_out': True}
[DEBUG   ] Collecting https://github.com/T-Dynamos/materialyoucolor-python/archive/main.zip
[DEBUG   ]   Downloading https://github.com/T-Dynamos/materialyoucolor-python/archive/main.zip
[DEBUG   ]      - 0 bytes ? 0:00:00
     - 19.8 kB 451.2 kB/s 0:00:00
     \ 19.8 kB 451.2 kB/s 0:00:00
     \ 27.9 kB 249.4 kB/s 0:00:00
     | 36.1 kB 209.8 kB/s 0:00:00
     | 36.1 kB 209.8 kB/s 0:00:00
     | 52.8 kB 227.9 kB/s 0:00:00
     / 56.9 kB 199.2 kB/s 0:00:00
     / 56.9 kB 199.2 kB/s 0:00:00
     - 75.7 kB 218.4 kB/s 0:00:00
     - 90.4 kB 223.5 kB/s 0:00:00
     \ 90.4 kB 223.5 kB/s 0:00:00
     \ 103.4 kB 222.8 kB/s 0:00:00
     | 117.7 kB 223.1 kB/s 0:00:00
     | 117.7 kB 223.1 kB/s 0:00:00
     / 135.1 kB 229.5 kB/s 0:00:00
     / 149.5 kB 231.0 kB/s 0:00:00
     - 159.7 kB 230.5 kB/s 0:00:00
     - 167.9 kB 237.8 kB/s 0:00:00
     \ 184.2 kB 241.3 kB/s 0:00:00
     \ 193.8 kB 240.4 kB/s 0:00:00
     \ 202.3 kB 245.4 kB/s 0:00:00
[DEBUG   ]   Installing build dependencies ... done
[DEBUG   ]   Getting requirements to build wheel ... error
[DEBUG   ]   error: subprocess-exited-with-error
[DEBUG   ]   
[DEBUG   ]   ? Getting requirements to build wheel did not run successfully.
[DEBUG   ]   ? exit code: 1
[DEBUG   ]   ??> [55 lines of output]
[DEBUG   ]       Downloading required files...
[DEBUG   ]       Traceback (most recent call last):
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/urllib/request.py", line 1348, in do_open
[DEBUG   ]           h.request(req.get_method(), req.selector, req.data, headers,
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/http/client.py", line 1282, in request
[DEBUG   ]           self._send_request(method, url, body, headers, encode_chunked)
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/http/client.py", line 1328, in _send_request
[DEBUG   ]           self.endheaders(body, encode_chunked=encode_chunked)
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/http/client.py", line 1277, in endheaders
[DEBUG   ]           self._send_output(message_body, encode_chunked=encode_chunked)
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/http/client.py", line 1037, in _send_output
[DEBUG   ]           self.send(msg)
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/http/client.py", line 975, in send
[DEBUG   ]           self.connect()
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/http/client.py", line 1454, in connect
[DEBUG   ]           self.sock = self._context.wrap_socket(self.sock,
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/ssl.py", line 513, in wrap_socket
[DEBUG   ]           return self.sslsocket_class._create(
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/ssl.py", line 1071, in _create
[DEBUG   ]           self.do_handshake()
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/ssl.py", line 1342, in do_handshake
[DEBUG   ]           self._sslobj.do_handshake()
[DEBUG   ]       ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)
[DEBUG   ]       
[DEBUG   ]       During handling of the above exception, another exception occurred:
[DEBUG   ]       
[DEBUG   ]       Traceback (most recent call last):
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
[DEBUG   ]           main()
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
[DEBUG   ]           json_out['return_val'] = hook(**hook_input['kwargs'])
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
[DEBUG   ]           return hook(config_settings)
[DEBUG   ]         File "/private/tmp/pip-build-env-8loqlz7x/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
[DEBUG   ]           return self._get_build_requires(config_settings, requirements=['wheel'])
[DEBUG   ]         File "/private/tmp/pip-build-env-8loqlz7x/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
[DEBUG   ]           self.run_setup()
[DEBUG   ]         File "/private/tmp/pip-build-env-8loqlz7x/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 487, in run_setup
[DEBUG   ]           super().run_setup(setup_script=setup_script)
[DEBUG   ]         File "/private/tmp/pip-build-env-8loqlz7x/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 311, in run_setup
[DEBUG   ]           exec(code, locals())
[DEBUG   ]         File "<string>", line 540, in <module>
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/urllib/request.py", line 216, in urlopen
[DEBUG   ]           return opener.open(url, data, timeout)
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/urllib/request.py", line 519, in open
[DEBUG   ]           response = self._open(req, data)
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/urllib/request.py", line 536, in _open
[DEBUG   ]           result = self._call_chain(self.handle_open, protocol, protocol +
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/urllib/request.py", line 496, in _call_chain
[DEBUG   ]           result = func(*args)
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/urllib/request.py", line 1391, in https_open
[DEBUG   ]           return self.do_open(http.client.HTTPSConnection, req,
[DEBUG   ]         File "/Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/lib/python3.10/urllib/request.py", line 1351, in do_open
[DEBUG   ]           raise URLError(err)
[DEBUG   ]       urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>
[DEBUG   ]       [end of output]
[DEBUG   ]   
[DEBUG   ]   note: This error originates from a subprocess, and is likely not a problem with pip.
[DEBUG   ] error: subprocess-exited-with-error
[DEBUG   ] 
[DEBUG   ] ? Getting requirements to build wheel did not run successfully.
[DEBUG   ] ? exit code: 1
[DEBUG   ] ??> See above for output.
[DEBUG   ] 
[DEBUG   ] note: This error originates from a subprocess, and is likely not a problem with pip.
[DEBUG   ] 
Exception in thread background thread for pid 6683:
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/opt/homebrew/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/lib/python3.12/site-packages/sh.py", line 1639, in wrap
    fn(*rgs, **kwargs)
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/lib/python3.12/site-packages/sh.py", line 2641, in background_thread
    handle_exit_code(exit_code)
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/lib/python3.12/site-packages/sh.py", line 2332, in fn
    return self.command.handle_command_exit_code(exit_code)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/lib/python3.12/site-packages/sh.py", line 826, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/bin/pip3 install --isolated --prefix /Users/theokoester/dev/projects/kivy-ios/build/dist/root/python3 https://github.com/T-Dynamos/materialyoucolor-python/archive/main.zip

  STDOUT:
Collecting https://github.com/T-Dynamos/materialyoucolor-python/archive/main.zip
  Downloading https://github.com/T-Dynamos/materialyoucolor-python/archive/main.zip
... (7308 more, please see e.stdout)

  STDERR:

Traceback (most recent call last):
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/bin/toolchain", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/lib/python3.12/site-packages/kivy_ios/toolchain.py", line 1562, in main
    ToolchainCL()
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/lib/python3.12/site-packages/kivy_ios/toolchain.py", line 1306, in __init__
    getattr(self, args.command)()
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/lib/python3.12/site-packages/kivy_ios/toolchain.py", line 1518, in pip3
    self.pip()
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/lib/python3.12/site-packages/kivy_ios/toolchain.py", line 1521, in pip
    _pip(sys.argv[2:])
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/lib/python3.12/site-packages/kivy_ios/toolchain.py", line 1193, in _pip
    shprint(pip_cmd, *args, _env=pip_env)
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/lib/python3.12/site-packages/kivy_ios/toolchain.py", line 60, in shprint
    for line in cmd:
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/lib/python3.12/site-packages/sh.py", line 882, in __next__
    self.wait()
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/lib/python3.12/site-packages/sh.py", line 799, in wait
    self.handle_command_exit_code(exit_code)
  File "/Users/theokoester/dev/projects/kivy-ios/build/venv/lib/python3.12/site-packages/sh.py", line 826, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /Users/theokoester/dev/projects/kivy-ios/build/dist/hostpython3/bin/pip3 install --isolated --prefix /Users/theokoester/dev/projects/kivy-ios/build/dist/root/python3 https://github.com/T-Dynamos/materialyoucolor-python/archive/main.zip

  STDOUT:
Collecting https://github.com/T-Dynamos/materialyoucolor-python/archive/main.zip
  Downloading https://github.com/T-Dynamos/materialyoucolor-python/archive/main.zip
... (7308 more, please see e.stdout)

  STDERR:

(venv) theokoester@Theos-MacBook-Pro build % x

if I build and run the kivymd app without it I get:

INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
[INFO   ] [GL          ] Backend used <sdl2>
[INFO   ] [GL          ] OpenGL version <b'OpenGL ES 2.0 APPLE-21.0.15'>
[INFO   ] [GL          ] OpenGL vendor <b'Apple Inc.'>
[INFO   ] [GL          ] OpenGL renderer <b'Apple Software Renderer'>
[INFO   ] [GL          ] OpenGL parsed version: 2, 0
[INFO   ] [GL          ] Shading version <b'OpenGL ES GLSL ES 1.00'>
[INFO   ] [GL          ] Texture max size <4096>
[INFO   ] [GL          ] Texture max units <8>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
 Traceback (most recent call last):
   File "/Users//dev/projects/kivy-ios/build/thecwa-ios/YourApp/main.py", line 22, in <module>
   File "/Users//Library/Developer/CoreSimulator/Devices/99F6B8A7-91AF-405F-B5FC-6C2C67D2CF45/data/Containers/Bundle/Application/596D9F89-5CA9-4A27-8F28-1120D1590638/thecwa.app/lib/python3.10/site-packages/kivymd/app.py", line 67, in <module>
     from kivymd.theming import ThemeManager
   File "/Users//Library/Developer/CoreSimulator/Devices/99F6B8A7-91AF-405F-B5FC-6C2C67D2CF45/data/Containers/Bundle/Application/596D9F89-5CA9-4A27-8F28-1120D1590638/thecwa.app/lib/python3.10/site-packages/kivymd/theming.py", line 49, in <module>
     from materialyoucolor.utils.color_utils import argb_from_rgba_01
 ModuleNotFoundError: No module named 'materialyoucolor'

/Users//dev/projects/kivy-ios/build/thecwa-ios/YourApp/main.py, line 22 this line imports MDApp from kivymd

MNwake commented 8 months ago

I know nothing about recipes but this is what chatgpt was able to do. It said it would need a materialyoucolor recipe and a pybind11 recipe. Neither will build though:

from kivy_ios.toolchain import PythonRecipe, CythonRecipe, shprint
import sh
import os
from os.path import join

class MaterialYouColorRecipe(CythonRecipe):
    version = "1.0"  # Replace with the actual version
    url = "https://github.com/T-Dynamos/materialyoucolor-python/archive/{version}.zip"
    depends = ["python3", "pillow", "pybind11"]  # Add pybind11 as a dependency
    library = "libmaterialyoucolor.a"  # Name of the library to be built
    include_per_platform = True
    cythonize = False

    def prebuild_arch(self, arch):
        # Prebuild steps if necessary
        pass

    def build_arch(self, arch):
        # Build steps for the C++ extensions
        build_env = self.get_recipe_env(arch)
        hostpython = sh.Command(self.ctx.hostpython)
        shprint(hostpython, "setup.py", "build_ext", _env=build_env)
        shprint(hostpython, "setup.py", "install", "--prefix", join(self.ctx.dist_dir, "root", "python3"), _env=build_env)

    def get_recipe_env(self, arch):
        env = super().get_recipe_env(arch)
        # Set additional environment variables if needed
        return env

recipe = MaterialYouColorRecipe()
from kivy_ios.toolchain import PythonRecipe, shprint
import sh
import os
from os.path import join

class Pybind11Recipe(PythonRecipe):
    version = "2.6.2"  # Replace with the version you need
    url = "https://github.com/pybind/pybind11/archive/v{version}.tar.gz"
    depends = ["python3"]

    def install(self):
        archs = self.filtered_archs
        for arch in archs:
            build_dir = self.get_build_dir(arch.arch)
            dest_dir = join(self.ctx.dist_dir, "root", "python3")
            os.chdir(build_dir)
            hostpython = sh.Command(self.ctx.hostpython)
            shprint(hostpython, "setup.py", "install", "--prefix", dest_dir, _env=self.get_recipe_env(arch))

recipe = Pybind11Recipe()