-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Very hacky workaround for pyasic being unable to be installed.
- Loading branch information
Showing
8 changed files
with
128 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,6 @@ | |
|
||
TERA_HASH_PER_SECOND = "TH/s" | ||
JOULES_PER_TERA_HASH = "J/TH" | ||
|
||
|
||
PYASIC_VERSION = "0.62.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import site | ||
import sys | ||
from subprocess import PIPE, Popen | ||
|
||
from homeassistant.util.package import is_virtual_env, _LOGGER | ||
|
||
_UV_ENV_PYTHON_VARS = ( | ||
"UV_SYSTEM_PYTHON", | ||
"UV_PYTHON", | ||
) | ||
|
||
# Copy-paste of home assistant core install, but pre-releases are supported | ||
def install_package( | ||
package: str, | ||
upgrade: bool = True, | ||
target: str | None = None, | ||
constraints: str | None = None, | ||
timeout: int | None = None, | ||
) -> bool: | ||
"""Install a package on PyPi. Accepts pip compatible package strings. | ||
Return boolean if install successful. | ||
""" | ||
_LOGGER.info("Attempting install of %s", package) | ||
env = os.environ.copy() | ||
args = [ | ||
sys.executable, | ||
"-m", | ||
"uv", | ||
"pip", | ||
"install", | ||
"--quiet", | ||
package, | ||
# Allow prereleases in sub-packages | ||
"--prerelease=allow", | ||
# We need to use unsafe-first-match for custom components | ||
# which can use a different version of a package than the one | ||
# we have built the wheel for. | ||
"--index-strategy", | ||
"unsafe-first-match", | ||
] | ||
if timeout: | ||
env["HTTP_TIMEOUT"] = str(timeout) | ||
if upgrade: | ||
args.append("--upgrade") | ||
if constraints is not None: | ||
args += ["--constraint", constraints] | ||
if target: | ||
abs_target = os.path.abspath(target) | ||
args += ["--target", abs_target] | ||
elif ( | ||
not is_virtual_env() | ||
and not (any(var in env for var in _UV_ENV_PYTHON_VARS)) | ||
and (abs_target := site.getusersitepackages()) | ||
): | ||
# Pip compatibility | ||
# Uv has currently no support for --user | ||
# See https://github.com/astral-sh/uv/issues/2077 | ||
# Using workaround to install to site-packages | ||
# https://github.com/astral-sh/uv/issues/2077#issuecomment-2150406001 | ||
args += ["--python", sys.executable, "--target", abs_target] | ||
|
||
|
||
_LOGGER.debug("Running uv pip command: args=%s", args) | ||
with Popen( | ||
args, | ||
stdin=PIPE, | ||
stdout=PIPE, | ||
stderr=PIPE, | ||
env=env, | ||
close_fds=False, # required for posix_spawn | ||
) as process: | ||
_, stderr = process.communicate() | ||
if process.returncode != 0: | ||
_LOGGER.error( | ||
"Unable to install package %s: %s", | ||
package, | ||
stderr.decode("utf-8").lstrip().strip(), | ||
) | ||
return False | ||
|
||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
colorlog==6.8.2 | ||
homeassistant>=2024.10.0 | ||
pip>=21.0,<23.2 | ||
ruff==0.7.2 | ||
pyasic==0.62.1 | ||
betterproto==2.0.0b7 | ||
setuptools==75.3.0 | ||
ruff==0.6.9 | ||
pyasic==0.62.3 | ||
setuptools==75.1.0 | ||
pre-commit |