Skip to content

Commit

Permalink
Deprecate pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
vkresch committed Jun 30, 2024
1 parent 58cddbf commit 099fc44
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
32 changes: 26 additions & 6 deletions src/launch_common.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import sys
import pkg_resources
import subprocess

from time import sleep
from datetime import date
from importlib.metadata import version, PackageNotFoundError
from packaging.version import parse

from Constants import (
PYTHON_MAJOR,
Expand All @@ -31,7 +32,7 @@ def python_version_ok(args=None):
)
else:
print(
"... installed Python version {}.{} is greater then minimum required version {}.{}. OK!\n".format(
"... installed Python version {}.{} is greater than the minimum required version {}.{}. OK!\n".format(
major,
minor,
PYTHON_MAJOR,
Expand Down Expand Up @@ -81,7 +82,7 @@ def new_protocol_not_live(args=None):
(
"Protocol {} could be live now. If it is live there are risks using this branch.\n"
"It is suggested to reach out to the community to confirm, and switch to the new test branch \n"
"or accept of the risks of using this branch".format(NEW_PROTOCOL_NAME)
"or accept the risks of using this branch".format(NEW_PROTOCOL_NAME)
)
)
return True
Expand Down Expand Up @@ -109,10 +110,29 @@ def requirements_installed(requirement_path=REQUIREMENTS_FILE_PATH):
try:
with open(requirement_path, "r") as requirements:
for requirement in requirements:
requirement = requirement.strip()
if not requirement or requirement.startswith("#"):
continue
try:
pkg_resources.require(requirement)
except Exception as e:
requirement = requirement.replace("\n", "")
if ">=" in requirement:
package_name, package_version = requirement.split(">=")
elif "==" in requirement:
package_name, package_version = requirement.split("==")
else:
package_name = requirement
package_version = None

installed_version = version(package_name)
if package_version and not parse(installed_version) >= parse(
package_version
):
missing_requirements.append(requirement)
print(
"... requirement {} was not met: installed version {}\n".format(
requirement, installed_version
)
)
except (PackageNotFoundError, ValueError) as e:
missing_requirements.append(requirement)
print(
"... requirement {} was not found: {}\n".format(requirement, e)
Expand Down
3 changes: 0 additions & 3 deletions tests/regression/test_requirements_installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ def test_application_aborts_if_requirements_missing():
assert start_application() == 1


@pytest.mark.skip(
"Python 3.12 throws error when prompting user for input thus skipping this for now."
)
def test_requirements_installed():
assert requirements_installed() is True

Expand Down

0 comments on commit 099fc44

Please sign in to comment.