Skip to content

Commit

Permalink
feat: remove substrafl wheel cache
Browse files Browse the repository at this point in the history
Signed-off-by: SdgJlbl <[email protected]>
  • Loading branch information
SdgJlbl committed Oct 4, 2023
1 parent 16d6c85 commit dd8c32f
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions substrafl/dependency/manage_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys
from pathlib import Path
from pathlib import PurePosixPath
from tempfile import TemporaryDirectory
from types import ModuleType
from typing import List
from typing import Union
Expand All @@ -17,8 +18,6 @@

logger = logging.getLogger(__name__)

LOCAL_WHEELS_FOLDER = Path.home() / ".substrafl"


def build_user_dependency_wheel(lib_path: Path, dest_dir: Path) -> str:
"""Build the wheel for user dependencies passed as a local module.
Expand Down Expand Up @@ -96,26 +95,19 @@ def local_lib_wheels(lib_modules: List[ModuleType], *, dest_dir: Path) -> List[s
lib_name = lib_module.__name__
wheel_name = f"{lib_name}-{lib_module.__version__}-py3-none-any.whl"

wheel_path = LOCAL_WHEELS_FOLDER / wheel_name
# Recreate the wheel only if it does not exist
if wheel_path.exists():
logger.warning(
f"Existing wheel {wheel_path} will be used to build {lib_name}. "
"It may lead to errors if you are using an unreleased version of this lib: "
"if it's the case, you can delete the wheel and it will be re-generated."
)
else:
# if the right version of substra or substratools is not found, it will search if they are already
# installed in 'dist' and take them from there.
# sys.executable takes the current Python interpreter instead of the default one on the computer
extra_args: list = []
if lib_name == "substrafl":
extra_args = [
"--find-links",
dest_dir.parent / "substra",
"--find-links",
dest_dir.parent / "substratools",
]
# if the right version of substra or substratools is not found, it will search if they are already
# installed in 'dist' and take them from there.
# sys.executable takes the current Python interpreter instead of the default one on the computer
extra_args: list = []
if lib_name == "substrafl":
extra_args = [
"--find-links",
dest_dir.parent / "substra",
"--find-links",
dest_dir.parent / "substratools",
]

with TemporaryDirectory() as tmp_dir:
ret = subprocess.check_output(
[
sys.executable,
Expand All @@ -124,7 +116,7 @@ def local_lib_wheels(lib_modules: List[ModuleType], *, dest_dir: Path) -> List[s
"wheel",
".",
"-w",
LOCAL_WHEELS_FOLDER,
tmp_dir,
"--no-deps",
]
+ extra_args,
Expand All @@ -139,7 +131,7 @@ def local_lib_wheels(lib_modules: List[ModuleType], *, dest_dir: Path) -> List[s
f"instead of {wheel_name}."
)

shutil.copy(wheel_path.parent / wheel_name, dest_dir / wheel_name)
shutil.copy(tmp_dir / wheel_name, dest_dir / wheel_name)
wheel_names.append(wheel_name)

return wheel_names
Expand Down

0 comments on commit dd8c32f

Please sign in to comment.