Browse Source

[FIX] fix bugs in package_utils

tags/v0.3.2
bxdd 2 years ago
parent
commit
06d230b223
2 changed files with 6 additions and 4 deletions
  1. +3
    -3
      learnware/client/container.py
  2. +3
    -1
      learnware/client/package_utils.py

+ 3
- 3
learnware/client/container.py View File

@@ -7,7 +7,7 @@ import tempfile
import shortuuid
from concurrent.futures import ThreadPoolExecutor

from typing import List, Union
from typing import List, Union, Optional
from .utils import system_execute, install_environment, remove_enviroment
from ..config import C
from ..learnware import Learnware
@@ -77,7 +77,7 @@ class ModelContainer(BaseModel):


class ModelCondaContainer(ModelContainer):
def __init__(self, model_config: dict, learnware_dirpath: str, conda_env: str = None, build: bool = True):
def __init__(self, model_config: dict, learnware_dirpath: str, conda_env: Optional[str] = None, build: bool = True):
self.conda_env = f"learnware_{shortuuid.uuid()}" if conda_env is None else conda_env
super(ModelCondaContainer, self).__init__(model_config, learnware_dirpath, build)

@@ -567,7 +567,7 @@ class LearnwaresContainer:
return

model_list = [_learnware.get_model() for _learnware in self.learnware_containers]
with ThreadPoolExecutor(max_workers=max(os.cpu_count() // 2, 1)) as executor:
with ThreadPoolExecutor(max_workers=(os.cpu_count() // 2, 1)) as executor:
executor.map(self._destroy_model_container, model_list, [self.ignore_error] * len(model_list))

self.learnware_containers = None


+ 3
- 1
learnware/client/package_utils.py View File

@@ -47,7 +47,7 @@ def parse_pip_requirement(line: str):
return package_str


def read_pip_packages_from_requirements(requirements_file: str) -> List[str]:
def read_pip_packages_from_requirements(requirements_file: str) -> Tuple[List[str], List[str]]:
"""Read requiremnts.txt and parse it to list"""

packages = []
@@ -74,6 +74,8 @@ def filter_nonexist_pip_packages(packages: list) -> Tuple[List[str], List[str]]:
exist_packages = []
nonexist_packages = []
for package in packages:
if package is None:
continue
try:
package_name = parse_pip_requirement(package)
if package_name != "learnware":


Loading…
Cancel
Save