Skip to content
This repository was archived by the owner on Jun 23, 2024. It is now read-only.

Commit ce1e821

Browse files
committed
Optimize _get_changelog_common
1 parent 7cbae9e commit ce1e821

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

Diff for: sync/core/Pull.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import shutil
2+
from pathlib import Path
23

34
from .Config import Config
45
from ..error import Result
@@ -52,8 +53,13 @@ def _get_file_url(self, module_id, file):
5253
return url
5354

5455
def _get_changelog_common(self, module_id, changelog):
55-
if not isinstance(changelog, str) or changelog == "":
56+
is_file = False
57+
58+
if isinstance(changelog, str) and changelog == "":
5659
return None
60+
elif isinstance(changelog, Path):
61+
changelog = changelog.name
62+
is_file = True
5763

5864
if changelog.startswith("http"):
5965
changelog_file = self._modules_folder.joinpath(module_id, f"{module_id}.md")
@@ -62,13 +68,18 @@ def _get_changelog_common(self, module_id, changelog):
6268
msg = Log.get_msg(result.error)
6369
self._log.e(f"_get_changelog_common: [{module_id}] -> {msg}")
6470
changelog_file = None
65-
else:
71+
72+
elif is_file:
6673
changelog_file = self._local_folder.joinpath(changelog)
6774
if not changelog_file.exists():
6875
msg = f"{changelog} is not in {self._local_folder}"
6976
self._log.d(f"_get_changelog_common: [{module_id}] -> {msg}")
7077
changelog_file = None
7178

79+
else:
80+
self._log.w(f"_get_changelog_common: [{module_id}] -> unsupported type [{changelog}]")
81+
changelog_file = None
82+
7283
if changelog_file is not None:
7384
if not self._check_changelog(module_id, changelog_file):
7485
changelog_file.unlink()
@@ -210,7 +221,7 @@ def from_zip(self, track):
210221
self._log.i(f"from_zip: [{track.id}] -> {msg}")
211222
return None, 0.0
212223

213-
changelog = self._get_changelog_common(track.id, track.changelog)
224+
changelog = self._get_changelog_common(track.id, Path(track.changelog))
214225
online_module = self._from_zip_common(track.id, zip_file, changelog, delete_tmp=False)
215226
return online_module, last_modified
216227

Diff for: sync/core/Pull.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pathlib import Path
2-
from typing import Optional, Tuple
2+
from typing import Optional, Tuple, Union
33

44
from ..error import Result
55
from ..model import (
@@ -27,7 +27,7 @@ class Pull:
2727
def _download(url: str, out: Path) -> Result: ...
2828
def _check_changelog(self, module_id: str, file: Path) -> bool: ...
2929
def _get_file_url(self, module_id: str, file: Path) -> str: ...
30-
def _get_changelog_common(self, module_id: str, changelog: str) -> Optional[Path]: ...
30+
def _get_changelog_common(self, module_id: str, changelog: Union[str, Path]) -> Optional[Path]: ...
3131
def _from_zip_common(
3232
self,
3333
module_id: str,

0 commit comments

Comments
 (0)