Skip to content

Commit

Permalink
feat: remove substrafl wheel cache (#175)
Browse files Browse the repository at this point in the history
Signed-off-by: SdgJlbl <[email protected]>
  • Loading branch information
SdgJlbl authored Oct 10, 2023
1 parent 172b42e commit c9b52b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Support on Python 3.11 ([#169](https://github.com/Substra/substrafl/pull/169))

### Changed
- Remove substrafl wheel cache ([#175](https://github.com/Substra/substrafl/pull/175))

## [0.41.1](https://github.com/Substra/substrafl/releases/tag/0.41.1) - 2023-10-06

### Fixed
Expand Down
44 changes: 20 additions & 24 deletions substrafl/dependency/manage_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"""
import logging
import os
import pathlib
import re
import shutil
import subprocess
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 +19,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 +96,22 @@ 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 = (
[
"--find-links",
dest_dir.parent / "substra",
"--find-links",
dest_dir.parent / "substratools",
]
if lib_name == "substrafl"
else []
)

with TemporaryDirectory() as tmp_dir:
ret = subprocess.check_output(
[
sys.executable,
Expand All @@ -124,7 +120,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 +135,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(pathlib.Path(tmp_dir) / wheel_name, dest_dir / wheel_name)
wheel_names.append(wheel_name)

return wheel_names
Expand Down

0 comments on commit c9b52b3

Please sign in to comment.