Skip to content

Commit

Permalink
Revert "fix: pip-compile on windows (#139)"
Browse files Browse the repository at this point in the history
This reverts commit d7235f2.

Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com>
  • Loading branch information
ThibaultFy committed Jun 14, 2023
1 parent d7235f2 commit 8be2e06
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 35 deletions.
2 changes: 1 addition & 1 deletion benchmark/camelyon/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def substrafl_fed_avg(
# Dependencies
base = Path(__file__).parent
dependencies = Dependency(
pypi_dependencies=["torch", "numpy", "scikit-learn"],
pypi_dependencies=["torch", "numpy", "sklearn"],
local_code=[base / "common", base / "weldon_fedavg.py"],
editable_mode=False,
)
Expand Down
39 changes: 15 additions & 24 deletions substrafl/remote/register/manage_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
Utility functions to manage dependencies (building wheels, compiling requirement...)
"""
import logging
import os
import re
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
from pathlib import PurePosixPath
from types import ModuleType
from typing import List
from typing import Union

from substrafl.dependency import Dependency
from substrafl.exceptions import InvalidDependenciesError
Expand Down Expand Up @@ -41,7 +38,7 @@ def build_user_dependency_wheel(lib_path: Path, operation_dir: Path) -> str:
"-m",
"pip",
"wheel",
str(lib_path) + os.sep,
str(lib_path) + "/",
"--no-deps",
],
cwd=str(operation_dir),
Expand Down Expand Up @@ -167,7 +164,7 @@ def get_pypi_dependencies_versions(lib_modules: List) -> List[str]:
return [f"{lib_module.__name__}=={lib_module.__version__}" for lib_module in lib_modules]


def compile_requirements(dependency_list: List[Union[str, Path]], *, operation_dir: Path, sub_dir: Path) -> None:
def compile_requirements(dependency_list: List[str], *, operation_dir: Path, sub_dir: Path) -> None:
"""Compile a list of requirements using pip-compile to generate a set of fully pinned third parties requirements
Writes down a `requirements.in` file with the list of explicit dependencies, then generates a `requirements.txt`
Expand All @@ -189,29 +186,23 @@ def compile_requirements(dependency_list: List[Union[str, Path]], *, operation_d

requirements = ""
for dependency in dependency_list:
if str(dependency).endswith(".whl"):
# pip compile require '/', even on windows. The double conversion resolves that.
requirements += f"file:{PurePosixPath(Path(dependency))}\n"
if dependency.__str__().endswith(".whl"):
requirements += f"file:{dependency}\n"
else:
requirements += f"{dependency}\n"

requirements_in.write_text(requirements)
command = [
sys.executable,
"-m",
"piptools",
"compile",
"--resolver=backtracking",
str(requirements_in),
]
try:
subprocess.run(
command,
subprocess.check_output(
[
sys.executable,
"-m",
"piptools",
"compile",
"--resolver=backtracking",
requirements_in,
],
cwd=operation_dir,
check=True,
capture_output=True,
text=True,
)
except subprocess.CalledProcessError as e:
raise InvalidDependenciesError(
f"Error in command {' '.join(command)}\nstdout: {e.stdout}\nstderr: {e.stderr}"
) from e
raise InvalidDependenciesError from e
6 changes: 2 additions & 4 deletions substrafl/remote/register/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import warnings
from distutils import util
from pathlib import Path
from pathlib import PurePosixPath
from platform import python_version

import substra
Expand Down Expand Up @@ -140,9 +139,8 @@ def _get_base_docker_image(python_major_minor: str, editable_mode: bool) -> str:
return substratools_image


def _generate_copy_local_files(local_files: typing.List[Path]) -> str:
# In Dockerfiles, we need to always have '/'. PurePosixPath resolves that.
return "\n".join([f"COPY {PurePosixPath(file)} {PurePosixPath(file)}" for file in local_files])
def _generate_copy_local_files(local_files: typing.List[str]) -> str:
return "\n".join([f"COPY {file} {file}" for file in local_files])


def _create_dockerfile(install_libraries: bool, dependencies: Dependency, operation_dir: Path, method_name: str) -> str:
Expand Down
1 change: 0 additions & 1 deletion tests/dependency/installable_library/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
setup(
name="substrafltestlibrary",
version="0.0.1",
packages=["substrafltestlibrary"],
)
1 change: 0 additions & 1 deletion tests/dependency/installable_library2/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
setup(
name="substrafltestlibrary2",
version="0.0.1",
packages=["substrafltestlibrary2"],
)
7 changes: 3 additions & 4 deletions tests/dependency/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import tempfile
import uuid
from pathlib import Path
from unittest.mock import MagicMock
from unittest.mock import patch

import numpy as np
import pytest
Expand Down Expand Up @@ -297,17 +299,14 @@ def train(
utils.wait(client, train_task)

@pytest.mark.docker_only
@patch("substrafl.remote.register.register.local_lib_wheels", MagicMock(return_value="INSTALL IN EDITABLE MODE"))
def test_force_editable_mode(
self,
mocker,
monkeypatch,
network,
session_dir,
dummy_algo_class,
):
mocker.patch("substrafl.remote.register.register.local_lib_wheels", return_value=["INSTALL IN EDITABLE MODE"])
mocker.patch("substrafl.remote.register.register.compile_requirements")

client = network.clients[0]
algo_deps = Dependency(pypi_dependencies=["pytest"], editable_mode=False)

Expand Down

0 comments on commit 8be2e06

Please sign in to comment.