dahlb / ha_hatch

Home Assistant Integration for Hatch Rest Mini
MIT License
76 stars 16 forks source link

Could not build wheels for the awscrt package #100

Closed brystmar closed 4 months ago

brystmar commented 4 months ago

Restarted my HA instance (2024.1.2) recently and found that the ha_hatch custom integration failed to load upon restarting. I think pip is having issues installing the awscrt package, which appears to be a dependency of the hatch_rest_api package. I'm running HA in a container using docker compose, in case that matters. Was working just fine last week.

Error messages:

Logger: homeassistant.setup
Source: setup.py:221
First occurred: January 15, 2024 at 15:46:42 (1 occurrences)
Last logged: January 15, 2024 at 15:46:42

Setup failed for custom integration 'ha_hatch': Requirements for ha_hatch not found: ['hatch_rest_api==1.20.9'].
Logger: homeassistant.util.package
Source: util/package.py:102
First occurred: January 15, 2024 at 15:45:54 (3 occurrences)
Last logged: January 15, 2024 at 15:46:42

Unable to install package hatch_rest_api==1.20.9: error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [68 lines of output] running bdist_wheel running build running build_py creating build creating build/lib.linux-aarch64-cpython-311 creating build/lib.linux-aarch64-cpython-311/awscrt copying awscrt/websocket.py -> build/lib.linux-aarch64-cpython-311/awscrt copying awscrt/io.py -> build/lib.linux-aarch64-cpython-311/awscrt copying awscrt/mqtt5.py -> build/lib.linux-aarch64-cpython-311/awscrt copying awscrt/crypto.py -> build/lib.linux-aarch64-cpython-311/awscrt copying awscrt/common.py -> build/lib.linux-aarch64-cpython-311/awscrt copying awscrt/s3.py -> build/lib.linux-aarch64-cpython-311/awscrt copying awscrt/_test.py -> build/lib.linux-aarch64-cpython-311/awscrt copying awscrt/exceptions.py -> build/lib.linux-aarch64-cpython-311/awscrt copying awscrt/checksums.py -> build/lib.linux-aarch64-cpython-311/awscrt copying awscrt/http.py -> build/lib.linux-aarch64-cpython-311/awscrt copying awscrt/auth.py -> build/lib.linux-aarch64-cpython-311/awscrt copying awscrt/mqtt.py -> build/lib.linux-aarch64-cpython-311/awscrt copying awscrt/__init__.py -> build/lib.linux-aarch64-cpython-311/awscrt creating build/lib.linux-aarch64-cpython-311/awscrt/eventstream copying awscrt/eventstream/rpc.py -> build/lib.linux-aarch64-cpython-311/awscrt/eventstream copying awscrt/eventstream/__init__.py -> build/lib.linux-aarch64-cpython-311/awscrt/eventstream running build_ext Traceback (most recent call last): File "<string>", line 2, in <module> File "<pip-setuptools-caller>", line 34, in <module> File "/tmp/pip-install-4xs9ddta/awscrt_e59351b30a7b46148e9ac01c392805c0/setup.py", line 399, in <module> setuptools.setup( File "/usr/local/lib/python3.11/site-packages/setuptools/__init__.py", line 103, in setup return distutils.core.setup(**attrs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 185, in setup return run_commands(dist) ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/setuptools/_distutils/core.py", line 201, in run_commands dist.run_commands() File "/usr/local/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands self.run_command(cmd) File "/usr/local/lib/python3.11/site-packages/setuptools/dist.py", line 989, in run_command super().run_command(command) File "/usr/local/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command cmd_obj.run() File "/usr/local/lib/python3.11/site-packages/wheel/bdist_wheel.py", line 364, in run self.run_command("build") File "/usr/local/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command self.distribution.run_command(command) File "/usr/local/lib/python3.11/site-packages/setuptools/dist.py", line 989, in run_command super().run_command(command) File "/usr/local/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command cmd_obj.run() File "/usr/local/lib/python3.11/site-packages/setuptools/_distutils/command/build.py", line 131, in run self.run_command(cmd_name) File "/usr/local/lib/python3.11/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command self.distribution.run_command(command) File "/usr/local/lib/python3.11/site-packages/setuptools/dist.py", line 989, in run_command super().run_command(command) File "/usr/local/lib/python3.11/site-packages/setuptools/_distutils/dist.py", line 988, in run_command cmd_obj.run() File "/tmp/pip-install-4xs9ddta/awscrt_e59351b30a7b46148e9ac01c392805c0/setup.py", line 263, in run self._build_dependencies(dep_build_dir, dep_install_path) File "/tmp/pip-install-4xs9ddta/awscrt_e59351b30a7b46148e9ac01c392805c0/setup.py", line 255, in _build_dependencies self._build_dependencies_impl(build_dir, install_path) File "/tmp/pip-install-4xs9ddta/awscrt_e59351b30a7b46148e9ac01c392805c0/setup.py", line 163, in _build_dependencies_impl cmake = get_cmake_path() ^^^^^^^^^^^^^^^^ File "/tmp/pip-install-4xs9ddta/awscrt_e59351b30a7b46148e9ac01c392805c0/setup.py", line 122, in get_cmake_path raise Exception("CMake must be installed to build from source.") 

Exception: CMake must be installed to build from source. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for awscrt ERROR: Could not build wheels for awscrt, which is required to install pyproject.toml-based projects
matchmee commented 4 months ago

I am showing the same error in my update today.

dahlb commented 4 months ago

I updated the dependency in the latest release, v1.16.4. if you are still having this error you are likely using a unsupported environment and this is a duplicate of #56

matchmee commented 4 months ago

What are the unsupported environments? I am on HA Core 2024.1.4 - Home Assistant Container - shouldn't this be supported?

matchmee commented 4 months ago

After deleting the integration and removing it from HACS, then restarting and adding it again and restarting - I am now getting a 504 error when trying to add the integration. Is there any insight in to that?

`Config flow could not be loaded:

504 Gateway Time-out

504 Gateway Time-out


openresty

`

dahlb commented 4 months ago

looks like your error has changed, both this and the previous error can be caused by an unreliable internet connection

matchmee commented 4 months ago

I am on fiber and my internet is very stable. No issues with network connectivity or anything. This issue comes when trying to add the integration back - but is not given with anything else or any other integration I try to add. The past error was there when I had the integration installed and running previously. Now that it isn't installed or running (because it was deleted) it now gives this error when trying to get it back.

brystmar commented 4 months ago

Tried v1.16.4 with the same results:

Logger: homeassistant.util.package
Source: util/package.py:102
First occurred: 16:32:04 (3 occurrences)
Last logged: 16:32:51

Unable to install package hatch_rest_api==1.20.10: error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully.  [...]
Exception: CMake must be installed to build from source. [end of output] note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for awscrt ERROR: Could not build wheels for awscrt, which is required to install pyproject.toml-based projects

I'm curious which environment is not supported? HASS runs in a docker container on my RPi 4, which is wired via CAT6 to my LAN. Fiber to the home; my home network is solid.

I recognize that this may be a dependency chain issue beyond your control and greatly appreciate any help you can provide! But I'm lost on troubleshooting next steps. I tried ssh-ing into the container and installing awscrt myself, got the same "unable to build wheels" error reported above.

robbles commented 2 months ago

I'm seeing the same original error as @brystmar on 2024.2.5.

I was able to work around it manually by installing cmake, make and build-base in the container like so:

apk add cmake make build-base

It looks like there was some work done in the past to work around a similar looking issue (https://github.com/dahlb/ha_hatch/commit/6bce65ffdf96b1b45ec680b7f00d4e7adb8055a3) but the lazy install bit seems to have reverted since then. What's the story there?

dahlb commented 2 months ago

@robbles aws used to not prebuild any wheels, a while ago aws added prebuilt wheel for 4 platforms including the one used by the official home assistant image so the work around/lazy install was removed. Those using platforms unsupported by the official aws wheels still need to build their own

brystmar commented 2 months ago

@robbles I ssh'd into my hass container (running 2024.2.5) and attempted to install the make and cmake packages using apk as you suggested. Didn't fix the issue, and I'm not familiar with apk, so I tried using pip instead and successfully installed make:

/config # pip install make
Looking in indexes: https://pypi.org/simple, https://wheels.home-assistant.io/musllinux-index/
Collecting make
  Downloading make-0.1.6.post2-py3-none-any.whl.metadata (4.6 kB)
Requirement already satisfied: Jinja2 in /usr/local/lib/python3.12/site-packages (from make) (3.1.3)
Collecting jinja2-time (from make)
  Downloading jinja2_time-0.2.0-py2.py3-none-any.whl.metadata (5.1 kB)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.12/site-packages (from Jinja2->make) (2.1.5)
Requirement already satisfied: arrow in /usr/local/lib/python3.12/site-packages (from jinja2-time->make) (1.3.0)
Requirement already satisfied: python-dateutil>=2.7.0 in /usr/local/lib/python3.12/site-packages (from arrow->jinja2-time->make) (2.8.2)
Requirement already satisfied: types-python-dateutil>=2.8.10 in /usr/local/lib/python3.12/site-packages (from arrow->jinja2-time->make) (2.8.19.20240106)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.12/site-packages (from python-dateutil>=2.7.0->arrow->jinja2-time->make) (1.16.0)
Downloading make-0.1.6.post2-py3-none-any.whl (14 kB)
Downloading jinja2_time-0.2.0-py2.py3-none-any.whl (6.4 kB)
Installing collected packages: jinja2-time, make
Successfully installed jinja2-time-0.2.0 make-0.1.6.post2
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

Still having issues with cmake, but at least this provides a different trail of breadcrumbs:

/config # pip install cmake
Looking in indexes: https://pypi.org/simple, https://wheels.home-assistant.io/musllinux-index/
Collecting cmake
  Downloading cmake-3.28.3.tar.gz (42 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.2/42.2 kB 8.5 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: cmake
  Building wheel for cmake (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for cmake (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [41 lines of output]
      /tmp/pip-build-env-j6j1jx52/overlay/lib/python3.12/site-packages/setuptools_scm/git.py:308: UserWarning: git archive did not support describe output
        warnings.warn("git archive did not support describe output")
      /tmp/pip-build-env-j6j1jx52/overlay/lib/python3.12/site-packages/setuptools_scm/git.py:327: UserWarning: unprocessed git archival found (no export subst applied)
        warnings.warn("unprocessed git archival found (no export subst applied)")
      Traceback (most recent call last):
        File "/tmp/pip-build-env-j6j1jx52/overlay/lib/python3.12/site-packages/skbuild/setuptools_wrap.py", line 645, in setup
          cmkr = cmaker.CMaker(cmake_executable)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-j6j1jx52/overlay/lib/python3.12/site-packages/skbuild/cmaker.py", line 148, in __init__
          self.cmake_version = get_cmake_version(self.cmake_executable)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/tmp/pip-build-env-j6j1jx52/overlay/lib/python3.12/site-packages/skbuild/cmaker.py", line 105, in get_cmake_version
          raise SKBuildError(msg) from err

          =============================DEBUG ASSISTANCE=============================
          If you are seeing a compilation error please try the following steps to
          successfully install cmake:
          1) Upgrade to the latest pip and try again. This will fix errors for most
             users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
          2) If running on Raspberry Pi OS, you can set PIP_ONLY_BINARY=cmake in
             order to retrieve the latest wheels built by piwheels.
             c.f. https://github.com/scikit-build/cmake-python-distributions/issues/392#issuecomment-1676284749
          3) If on Linux, with glibc < 2.12, you can set PIP_ONLY_BINARY=cmake in
             order to retrieve the last manylinux1 compatible wheel.
          4) If on Linux, with glibc < 2.12, you can cap "cmake<3.23" in your
             requirements in order to retrieve the last manylinux1 compatible wheel.
          5) Open an issue with the debug information that follows at
             https://github.com/scikit-build/cmake-python-distributions/issues

          Python: 3.12.1
          platform: Linux-6.1.21-v8+-aarch64-with
          machine: aarch64
          bits: 32
          pip: n/a
          setuptools: 69.1.1
          scikit-build: 0.17.6
          PEP517_BUILD_BACKEND=setuptools.build_meta
          =============================DEBUG ASSISTANCE=============================

      Problem with the CMake installation, aborting build. CMake executable is cmake
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for cmake
Failed to build cmake
ERROR: Could not build wheels for cmake, which is required to install pyproject.toml-based projects

No dice, so let's try the CMake debug steps. First, update pip:

pip install pip -U

Updated from v23.1 to v24.0. Cool. Now we set PIP_ONLY_BINARY=cmake:

export PIP_ONLY_BINARY=cmake

Trying pip install cmake again resulted in this error:

/config # pip install cmake
Looking in indexes: https://pypi.org/simple, https://wheels.home-assistant.io/musllinux-index/
ERROR: Could not find a version that satisfies the requirement cmake (from versions: none)
ERROR: No matching distribution found for cmake

Argh. Is this a RPi bullseye + python 3.12 thing? ❓ 😕 ❓

I'd really appreciate if someone could point me in the right direction here because I'm stumped. I'm an amateur hobbyist with light experience building flask backends and React UIs. Troubleshooting compilers and binaries is over my head.

robbles commented 2 months ago

@brystmar I made a typo in my comment - it looks like I actually needed to install build-base as well. So the apk command to run inside the container would be:

apk add build-base make cmake

edit: apk add instead of install

My understanding here is as follows:

  1. HA uses pip (which installs Python packages only) to install awscrt, which normally relies on having a prebuilt "wheel" available for all supported platforms
  2. Because there isn't a prebuilt wheel for our platform (unclear to me why) it falls back to building the package from source
  3. Building this particular package from source requires a few OS packages to be installed - build-base (for the C/C++ compilers), make, and cmake. These are OS packages and can't be installed with pip.
  4. Without each of these packages installed, I was seeing a different error, which pointed to needing cmake, which then needed make, which then needed gcc (included in build-base)

Your error looks a little different from the ones I was seeing, so it's possible there's something different going on for you. Try installing build-base as well though, and restarting. It took a long time on my RPi to finish building the package, so you might be waiting a while if it works.

robbles commented 2 months ago

@dahlb My RPi appears to be linux-armv7l. Think that's an unsupported architecture? I'm not clear on how pip resolves wheels, or whether there's any sort of fallbacks to more generic builds.

$ uname -a
Linux homeassistant 5.15.32-v7l+ #1538 SMP Thu Mar 31 19:39:41 BST 2022 armv7l Linux
brystmar commented 2 months ago

@robbles: It worked!!! Thank you so much! 🎉 😃

Btw, apparently apk uses the add command instead of install — want to update your above comment for posterity?

Appreciate you mentioning how long it took to build. The UI spinner was going for probably 5 full minutes when adding a new Hatch integration. I checked the error logs halfway through and didn't see any hatch errors, so I kept waiting and was eventually prompted for my Hatch credentials.

To (hopefully) relieve me from needing to manually send commands to the container every time it builds/rebuilds, I'm adding this under the HASS service in my docker-compose file: command: apk add build-base make cmake

Thanks again @robbles, and of course @dahlb for building & maintaining this integration!

dahlb commented 2 months ago

this could help you both automate that based on an old method that was removed when aws added wheels (https://github.com/dahlb/ha_hatch/commit/6bce65ffdf96b1b45ec680b7f00d4e7adb8055a3)

can be automated with configuration.yaml

shell_command:
  hatch_rest_apk: /config/setup_ha_hatch.sh

and automation.yaml

- id: '1646074445984'
  alias: APK install
  description: ''
  trigger:
  - platform: homeassistant
    event: start
  condition: []
  action:
  - service: shell_command.hatch_rest_apk
    data: {}
  mode: single

setup_ha_hatch.sh

#!/bin/bash

pip install hatch-rest-api==1.12.1 -f https://qqaatw.github.io/aws-crt-python-musllinux/
#exit 0

# old version for below 1.10.0 release

apk -e info make
if [[ $? -eq 0 ]]; then
    echo "noop exiting"
    exit 0
fi

echo "installing and restarting"
apk add gcc g++ cmake make
pkill python3