Skip to content

Commit

Permalink
feat: Stop sorting eggs
Browse files Browse the repository at this point in the history
* Card ID: CCT-397

We know the preferred order for eggs: ENV > LAST > STABLE > RPM.
It is unlikely that the RPM egg will be newer than STABLE.
  • Loading branch information
m-horky committed Mar 12, 2024
1 parent b0a7d2d commit fb34a6c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 48 deletions.
46 changes: 1 addition & 45 deletions src/insights_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
import os
import shutil
import subprocess
from subprocess import Popen, PIPE
import sys
import tempfile

from distutils.version import LooseVersion


INSIGHTS_DEBUG = os.environ.get("INSIGHTS_DEBUG", "").lower() == "true"
NO_COLOR = os.environ.get("NO_COLOR") is not None
Expand Down Expand Up @@ -64,46 +61,6 @@ def log(msg):
print(msg, file=sys.stderr)


def egg_version(egg):
"""
Determine the egg version
"""
if not sys.executable:
return None
try:
proc = Popen(
[
sys.executable,
"-c",
"from insights.client import InsightsClient; print(InsightsClient(None, False).version())",
],
env={"PYTHONPATH": egg, "PATH": os.getenv("PATH")},
stdout=PIPE,
stderr=PIPE,
)
except OSError:
return None
stdout, stderr = proc.communicate()
return stdout.decode("utf-8")


def sorted_eggs(eggs):
"""
Sort eggs to go into sys.path by highest version
"""
if len(eggs) < 2:
# nothing to sort
return eggs
# default versions to 0 so LooseVersion doesn't throw a fit
egg0_version = egg_version(eggs[0]) or "0"
egg1_version = egg_version(eggs[1]) or "0"

if LooseVersion(egg0_version) > LooseVersion(egg1_version):
return eggs
else:
return [eggs[1], eggs[0]]


def _remove_gpg_home(home):
"""Clean GPG's temporary home directory at path 'home'.
Expand Down Expand Up @@ -353,8 +310,7 @@ def _main():
attempt to collect and upload with new, then current, then rpm
if an egg fails a phase never try it again
"""
# sort rpm and stable eggs after verification
validated_eggs = sorted_eggs(list(filter(gpg_validate, [STABLE_EGG, RPM_EGG])))
validated_eggs = list(filter(gpg_validate, [STABLE_EGG, RPM_EGG]))
# if ENV_EGG was specified and it's valid, add that to front of sys.path
# so it can be loaded initially. keep it in its own var so we don't
# pass it to run_phase where we load it again
Expand Down
3 changes: 0 additions & 3 deletions src/insights_client/tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
pytest
# Setuptools is required because we still rely on 'distutils' which have been dropped in Python 3.12.
# setuptools package ships it vendorized as a top-level package, so for a time being we can rely on it.
setuptools
-r requirements-core.txt

0 comments on commit fb34a6c

Please sign in to comment.