Skip to content

Commit

Permalink
fix mypy lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
tianweidut committed Oct 11, 2022
1 parent 36a3a61 commit d5a9f0d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
1 change: 0 additions & 1 deletion client/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
PY_CHANGED_FILES = $(shell git diff --name-only --relative -- '*.py')


.POHNY: check
check:
python3 setup.py check
Expand Down
2 changes: 1 addition & 1 deletion client/starwhale/api/_impl/dataset/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def _copy_files(
if _dest_path.resolve() == _obj_path:
continue
else:
_dest_path.unlink(missing_ok=True)
_dest_path.unlink()

_dest_path.symlink_to(_obj_path)

Expand Down
40 changes: 26 additions & 14 deletions client/starwhale/utils/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
_ConfigsT = t.Optional[t.Dict[str, t.Dict[str, t.Union[str, t.List[str]]]]]
_DepsT = t.Optional[t.Dict[str, t.Union[t.List[str], str]]]
_PipConfigT = t.Optional[t.Dict[str, t.Union[str, t.List[str]]]]
_PipReqT = t.Union[str, Path, PosixPath]


class EnvTarType:
Expand Down Expand Up @@ -103,19 +104,30 @@ def _do_pip_install_req(
pip_config = pip_config or {}
_env = os.environ

_extra_index: t.List[str] = [_env.get("SW_PYPI_EXTRA_INDEX_URL", "")]
_hosts: t.List[str] = [_env.get("SW_PYPI_TRUSTED_HOST", "")]
_index: str = _env.get("SW_PYPI_INDEX_URL", "")
list_to_str: t.Callable[[t.Union[str, list]], str] = (
lambda x: " ".join(x) if isinstance(x, list) else x
)

# TODO: remove SW_PYPI_* envs

_index_url = _env.get("SW_PYPI_INDEX_URL", "")
_extra_index_urls = [
_env.get("SW_PYPI_EXTRA_INDEX_URL", ""),
list_to_str(pip_config.get("extra_index_url", [])),
]
_hosts = [
_env.get("SW_PYPI_TRUSTED_HOST", ""),
list_to_str(pip_config.get("trusted_host", [])),
]

if _index:
_extra_index.append(pip_config.get("index_url", ""))
config_index_url = list_to_str(pip_config.get("index_url", ""))
if _index_url:
_extra_index_urls.append(config_index_url)
else:
_index = pip_config.get("index_url", "")
_extra_index.extend(pip_config.get("extra_index_url", []))
_hosts.extend(pip_config.get("trusted_host", []))
_index_url = config_index_url

_s_index = _index.strip()
_s_extra_index = " ".join([s for s in _extra_index if s.strip()])
_s_index = _index_url.strip()
_s_extra_index = " ".join([s for s in _extra_index_urls if s.strip()])
_s_hosts = " ".join([s for s in _hosts if s.strip()])

if _s_index:
Expand Down Expand Up @@ -144,7 +156,7 @@ def _do_pip_install_req(

def venv_install_req(
venvdir: t.Union[str, Path],
req: t.Union[str, Path],
req: _PipReqT,
enable_pre: bool = False,
pip_config: _PipConfigT = None,
) -> None:
Expand Down Expand Up @@ -383,7 +395,7 @@ def conda_export(
if prefix:
cmd += ["--prefix", prefix]

cmd += ["--file", lock_fpath]
cmd += ["--file", str(lock_fpath)]
check_call(cmd)


Expand Down Expand Up @@ -856,10 +868,10 @@ def iter_pip_reqs(
workdir: Path,
wheels: t.Optional[t.List[str]],
deps: _DepsT,
) -> t.Generator[t.Union[str, Path, PosixPath], None, None]:
) -> t.Generator[_PipReqT, None, None]:
from starwhale.base.type import RuntimeArtifactType

reqs = []
reqs: t.List[_PipReqT] = []
deps = deps or {}
for _pf in deps.get("pip_files", []):
reqs.append(workdir / RuntimeArtifactType.DEPEND / _pf)
Expand Down

0 comments on commit d5a9f0d

Please sign in to comment.