Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(client): fix mypy exclude typo and some code lint error #1343

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions client/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ exclude = '''

[tool.mypy]
exclude = [
"venv",
"build",
"dist",
"__pycache__",
"tests",
"venv/",
"build/",
"dist/",
"__pycache__/",
"tests/",
"dummy/setup.py",
]
show_column_numbers = true
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