Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions src/aedifix/packages/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

from ..package import Package
from ..util.argument_parser import ArgSpec, ConfigArgument
from ..util.exception import UnsatisfiableConfigurationError
from ..util.utility import find_active_python_version_and_path

if TYPE_CHECKING:
from ..manager import ConfigurationManager
Expand All @@ -27,53 +25,6 @@ class Python(Package):
primary=True,
)

def __init__(self, manager: ConfigurationManager) -> None:
super().__init__(manager=manager)

def configure_lib_version_and_paths(self) -> None:
r"""Determine the Python library version and its location."""
try:
version, lib_path = find_active_python_version_and_path()
except (RuntimeError, FileNotFoundError) as excn:
if self.state.disabled():
# Not sure how we'd get here
msg = (
"The Python package does not appear to be enabled, yet we "
"are in the middle of configuring it. I'm not sure how we "
"got here, this should not happen"
)
raise RuntimeError(msg) from excn
# Python is requested, now to determine whether the user did
# that or some other piece of the code
if self.state.explicitly_enabled():
# If the user wants python, but we cannot find/use it, then
# that's a hard error
msg = (
f"{excn}. You have explicitly requested Python via "
f"{self.With_Python.name} {self.cl_args.with_python.value}"
)
raise UnsatisfiableConfigurationError(msg) from excn
# Some other piece of code has set the cl_args to true
msg = (
f"{excn}. Some other package has implicitly enabled python"
" but could not locate active lib directories for it"
)
raise RuntimeError(msg) from excn

self.lib_version = version
self.lib_path = lib_path
self.log(
f"Python: found lib version: {version} and library path {lib_path}"
)

def configure(self) -> None:
r"""Configure Python."""
super().configure()
if not self.state.enabled():
return

self.log_execute_func(self.configure_lib_version_and_paths)

def summarize(self) -> str:
r"""Summarize configured Python.

Expand Down
51 changes: 0 additions & 51 deletions src/aedifix/util/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import re
import enum
import shlex
import platform
import sysconfig
import subprocess
from pathlib import Path
from signal import SIGINT
Expand All @@ -19,7 +17,6 @@
Popen,
TimeoutExpired,
)
from sys import version_info
from typing import TYPE_CHECKING, Any, Final, TypeVar

from .exception import CommandError
Expand Down Expand Up @@ -253,54 +250,6 @@ class ValueProvenance(enum.Enum):
GENERATED = enum.auto()


def find_active_python_version_and_path() -> tuple[str, Path]:
r"""Determine the current Python version and the path to its shared
library.

Returns
-------
version : str
The current Python version as a string.
lib_path : Path
The full path to the python shared library.

Raises
------
FileNotFoundError
If the python shared library could not be located.
"""
# Launching a sub-process to do this in a general way seems hard
version = f"{version_info.major}.{version_info.minor}.{version_info.micro}"
cv = sysconfig.get_config_vars()
# Homebrew or pkg mgr installations may give bad values for LDLIBRARY.
# Uses a fallback default path in case LDLIBRARY fails.
default_libname = f"libpython{cv['LDVERSION']}.a"
libdirs = [str(cv["LIBDIR"]), str(cv["LIBPL"])]
libnames = [str(cv["LDLIBRARY"]), default_libname]
paths = [
libdir / libname
for libdir in map(Path, libdirs)
for libname in libnames
]
# ensure that static libraries are replaced with the dynamic version
shlib_suffix = ".dylib" if platform.system() == "Darwin" else ".so"
paths = [p.with_suffix(shlib_suffix) for p in paths]
paths = [p for p in paths if p.is_file()]
try:
py_lib_path = paths[0]
except IndexError as ie:
msg = "Could not auto-locate Python library"
raise FileNotFoundError(msg) from ie

if not py_lib_path.exists():
msg = (
"Could not auto-locate Python library, "
f"found library ({py_lib_path}) does not appear to exist"
)
raise RuntimeError(msg)
return version, py_lib_path


def prune_command_line_args(
argv: Sequence[str], remove_args: set[str]
) -> list[str]:
Expand Down
Loading