Skip to content

Commit

Permalink
removed deprecated pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
craigbarratt committed Jul 26, 2024
1 parent 774842d commit fbc8bce
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions custom_components/pyscript/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import os
import sys

from pkg_resources import Requirement

from homeassistant.loader import bind_hass
from homeassistant.requirements import async_process_requirements

Expand Down Expand Up @@ -90,19 +88,14 @@ def process_all_requirements(pyscript_folder, requirements_paths, requirements_f
pkg = pkg[:i]
pkg = pkg.strip()

if not pkg:
if not pkg or len(pkg) == 0:
continue

try:
# Attempt to get version of package. Do nothing if it's found since
# we want to use the version that's already installed to be safe
requirement = Requirement.parse(pkg)
pkg_name = requirement.project_name

# Requirements must be pinned and will be skipped if they aren't
if len(requirement.specs) == 1 and (
len(requirement.specs[0]) != 2 or requirement.specs[0][0] != "=="
):
parts = pkg.split("==")
if len(parts) > 2 or "," in pkg or ">" in pkg or "<" in pkg:
_LOGGER.error(
(
"Ignoring invalid requirement '%s' specified in '%s'; if a specific version"
Expand All @@ -112,11 +105,12 @@ def process_all_requirements(pyscript_folder, requirements_paths, requirements_f
pkg,
)
continue

if not requirement.specs:
if len(parts) == 1:
new_version = UNPINNED_VERSION
else:
new_version = requirement.specs[0][1]
new_version = parts[1]
pkg_name = parts[0]

current_pinned_version = all_requirements_to_install.get(pkg_name, {}).get(ATTR_VERSION)
current_sources = all_requirements_to_install.get(pkg_name, {}).get(ATTR_SOURCES, [])
# If a version hasn't already been recorded, record this one
Expand Down

0 comments on commit fbc8bce

Please sign in to comment.