Skip to content

Commit 13b5f71

Browse files
authored
Merge pull request #353 from legendu-net/dev
Merge dev into main
2 parents 627dbb1 + d43f15f commit 13b5f71

File tree

6 files changed

+25
-23
lines changed

6 files changed

+25
-23
lines changed

aiutil/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
from . import git
44
from . import poetry
55

6-
__version__ = "0.75.0"
6+
__version__ = "0.76.0"

aiutil/dockerhub.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def tags(self, image: str) -> list[str]:
2121
if "/" in image:
2222
user, image = image.split("/")
2323
url = f"https://hub.docker.com/v2/repositories/{user}/{image}/tags/"
24-
res = requests.get(url)
24+
res = requests.get(url, timeout=10)
2525
return res.json()["results"]
2626

2727
def token(self, password: str) -> None:
@@ -35,6 +35,7 @@ def token(self, password: str) -> None:
3535
"username": self.user,
3636
"password": password
3737
},
38+
timeout=10,
3839
)
3940
self._token = res.json()["token"]
4041

@@ -59,6 +60,7 @@ def delete_tag(self, image: str, tag: str = "") -> str:
5960
headers={
6061
"Content-Type": "application/json",
6162
"Authorization": f"JWT {self._token}"
62-
}
63+
},
64+
timeout=10,
6365
)
6466
return tag if res else ""

aiutil/filesystem.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -392,32 +392,32 @@ def append_lines(
392392

393393
def replace_patterns(
394394
path: Path,
395-
patterns: Union[str, Iterable[str]],
396-
repls: Union[str, Iterable[str]],
395+
pattern: Union[str, Iterable[str]],
396+
repl: Union[str, Iterable[str]],
397397
regex: bool = True,
398398
) -> None:
399399
"""Update a text file using regular expression substitution.
400400
401401
:param path: A Path object to the file to be updated.
402-
:param patterns: A (list of) patterns to replace.
403-
:param repls: A list of replacements.
402+
:param pattern: A (list of) patterns to replace.
403+
:param repl: A (list of) replacements.
404404
or a function to map patterns to replacements.
405405
:param regex: If true, treat patterns as regular expression pattern;
406406
otherwise, perform exact matches.
407407
"""
408408
if isinstance(path, str):
409409
path = Path(path)
410410
text = path.read_text(encoding="utf-8")
411-
if isinstance(patterns, str):
412-
patterns = [patterns]
413-
if isinstance(repls, str):
414-
repls = [repls]
411+
if isinstance(pattern, str):
412+
pattern = [pattern]
413+
if isinstance(repl, str):
414+
repl = [repl]
415415
if regex:
416-
for pattern, repl in zip(patterns, repls):
417-
text = re.sub(pattern, repl, text)
416+
for p, r in zip(pattern, repl):
417+
text = re.sub(p, r, text)
418418
else:
419-
for pattern, repl in zip(patterns, repls):
420-
text = text.replace(pattern, repl)
419+
for p, r in zip(pattern, repl):
420+
text = text.replace(p, r)
421421
path.write_text(text, encoding="utf-8")
422422

423423

aiutil/poetry.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _update_version_readme(ver: str, proj_dir: Path) -> None:
5858
:param ver: The new version.
5959
:param proj_dir: The root directory of the Poetry project.
6060
"""
61-
replace_patterns(proj_dir / README, patterns=r"\d+\.\d+\.\d+", repls=f"{ver}")
61+
replace_patterns(proj_dir / README, pattern=r"\d+\.\d+\.\d+", repl=f"{ver}")
6262

6363

6464
def _update_version_toml(ver: str, proj_dir: Path) -> None:
@@ -69,8 +69,8 @@ def _update_version_toml(ver: str, proj_dir: Path) -> None:
6969
"""
7070
replace_patterns(
7171
proj_dir / TOML,
72-
patterns=r"version = .\d+\.\d+\.\d+.",
73-
repls=f'version = "{ver}"'
72+
pattern=r"version = .\d+\.\d+\.\d+.",
73+
repl=f'version = "{ver}"'
7474
)
7575

7676

@@ -84,8 +84,8 @@ def _update_version_init(ver: str, proj_dir: Path) -> None:
8484
for path in (proj_dir / pkg).glob("**/*.py"):
8585
replace_patterns(
8686
path,
87-
patterns=r"__version__ = .\d+\.\d+\.\d+.",
88-
repls=f'__version__ = "{ver}"'
87+
pattern=r"__version__ = .\d+\.\d+\.\d+.",
88+
repl=f'__version__ = "{ver}"'
8989
)
9090

9191

aiutil/pypi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def dep(pkg: str, recursive: bool = False) -> set[str]:
2121

2222
def _dep(pkg):
2323
url = f"https://pypi.org/pypi/{pkg}/json"
24-
deps = requests.get(url).json()["info"]["requires_dist"]
24+
deps = requests.get(url, timeout=10).json()["info"]["requires_dist"]
2525
if deps is None:
2626
return set()
2727
return set(dep for dep in deps if "extra ==" not in dep)

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "aiutil"
3-
version = "0.75.0"
3+
version = "0.76.0"
44
description = "A utils Python package for data scientists."
55
authors = ["Benjamin Du <[email protected]>"]
66
license = "MIT"
@@ -88,7 +88,7 @@ ignored-modules = "pyspark.sql.functions"
8888
ignored-classes = "Namespace"
8989

9090
[tool.pylint.messages_control]
91-
disable = "C0103,C0200,C0301,C0303,C0330,R0902,R0903,R0911,R0912,R0913,W0621,W0622,W0702,W0703,W1116"
91+
disable = "C0103,C0200,C0301,C0303,R0902,R0903,R0911,R0912,R0913,W0621,W0622,W0702,W0703,W1116"
9292

9393
[build-system]
9494
requires = ["poetry>=1.0.0"]

0 commit comments

Comments
 (0)