Skip to content

Commit 6ac0ced

Browse files
committed
Version 0.7.4
* Add options for mypy --implicit-optional --allow-redefinition --disable-error-code abstract * Fix typings * Install setuptools firstly * Use typing_extensions.Final for python3.7 * Disable attr-defined checking at windows
1 parent f5c30bf commit 6ac0ced

File tree

15 files changed

+140
-67
lines changed

15 files changed

+140
-67
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ jobs:
2424
with:
2525
virtualenvs-create: true
2626
- name: Install dependencies
27-
run: poetry install --no-root
27+
run: |
28+
poetry run pip3 install setuptools
29+
poetry install --no-root
2830
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
2931
- name: Format check with black
3032
run: poetry run black --check .
31-
- name: Typecheck with mypy
32-
run: poetry run mypy -p baidupcs_py --ignore-missing-imports --warn-unreachable
33+
- name: Typecheck with mypy at Windows
34+
run: poetry run mypy -p baidupcs_py --ignore-missing-imports --warn-unreachable --implicit-optional --allow-redefinition --disable-error-code abstract --disable-error-code attr-defined
35+
if: matrix.os == 'windows-latest'
36+
- name: Typecheck with mypy at Linux
37+
run: poetry run mypy -p baidupcs_py --ignore-missing-imports --warn-unreachable --implicit-optional --allow-redefinition --disable-error-code abstract
38+
if: matrix.os == 'ubuntu-latest'
3339
- name: Test with pytest
3440
run: |
3541
poetry run python build.py build_ext --inplace

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Changelog
22

3-
## v0.7.3 - 2022-10-31
3+
## v0.7.4 - 2022-11-10
4+
5+
### Changed
6+
7+
- 在下载和上传时,让调用者去初始化进度条。
8+
9+
### Updated
10+
11+
- 更新依赖。
12+
13+
## v0.7.3 - 2022-11-09
414

515
### Updated
616

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
typecheck:
2-
mypy -p baidupcs_py --ignore-missing-imports --warn-unreachable
2+
mypy -p baidupcs_py \
3+
--ignore-missing-imports \
4+
--warn-unreachable \
5+
--implicit-optional \
6+
--allow-redefinition \
7+
--disable-error-code abstract
38

49
format-check:
510
black --check .
@@ -10,6 +15,8 @@ format:
1015
build-pyx:
1116
python build.py build_ext --inplace
1217

18+
test: build-pyx
19+
pytest -s tests/test_common.py
1320

1421
build: all
1522
rm -fr dist

baidupcs_py/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from baidupcs_py.baidupcs import BaiduPCS, BaiduPCSApi
22

3-
__version__ = "0.7.3"
3+
__version__ = "0.7.4"

baidupcs_py/app/account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def cd(self, remotedir: str = "/"):
110110

111111
assert account
112112

113-
pwd = join_path(account.pwd, remotedir)
113+
pwd = join_path(Path(account.pwd), Path(remotedir))
114114
account = account._replace(pwd=pwd)
115115
self._accounts[self._who] = account
116116

baidupcs_py/commands/log.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
from typing import cast
12
import os
23
from pathlib import Path
34

4-
from baidupcs_py.common.log import LogLevels, get_logger as _get_logger
5+
from baidupcs_py.common.log import TLogLevel, LogLevels, get_logger as _get_logger
56
from baidupcs_py.commands.env import LOG_LEVEL, LOG_PATH
67

78

89
def get_logger(name: str):
910
_LOG_PATH = Path(os.getenv("LOG_PATH") or LOG_PATH).expanduser()
10-
_LOG_LEVEL = os.getenv("LOG_LEVEL", LOG_LEVEL).upper()
11+
_LOG_LEVEL: TLogLevel = cast(
12+
TLogLevel,
13+
os.getenv("LOG_LEVEL", LOG_LEVEL).upper(),
14+
)
1115
assert _LOG_LEVEL in LogLevels
1216

1317
return _get_logger(name, filename=_LOG_PATH, level=_LOG_LEVEL)

baidupcs_py/commands/rapid_upload.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Optional, List, Dict, Any
22

3+
from pathlib import Path
34
from threading import Semaphore
45
from concurrent.futures import ThreadPoolExecutor, as_completed
56

@@ -176,7 +177,7 @@ def rapid_upload(
176177
content_crc32 = content_crc32 or 0
177178
filename = filename or _filename
178179

179-
remotepath = join_path(remotedir, filename)
180+
remotepath = join_path(Path(remotedir), Path(filename))
180181

181182
assert all(
182183
[slice_md5, content_md5, content_length]

baidupcs_py/commands/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async def handle_request(
6161

6262
remotepath = remotepath.strip("/")
6363

64-
_rp = join_path(_root_dir, remotepath)
64+
_rp = join_path(Path(_root_dir), Path(remotepath))
6565

6666
# Anti path traversal attack
6767
if not _rp.startswith(_root_dir):

baidupcs_py/commands/sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ def sync(
6666
fts: List[FromTo] = []
6767
check_list: List[Tuple[str, PcsFile]] = []
6868
all_localpaths = set()
69-
for localpath in walk(localdir):
69+
for localpath in walk(Path(localdir)):
7070
path = localpath[len(localdir) + 1 :]
7171
all_localpaths.add(path)
7272

7373
if path not in all_pcs_files:
74-
fts.append(FromTo(localpath, join_path(remotedir, path)))
74+
fts.append(FromTo(localpath, join_path(Path(remotedir), Path(path))))
7575
else:
7676
check_list.append((localpath, all_pcs_files[path]))
7777

baidupcs_py/commands/upload.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ def from_tos(localpaths: List[str], remotedir: str) -> List[FromTo]:
7575

7676
ft: List[FromTo] = []
7777
for localpath in localpaths:
78-
if not exists(localpath):
78+
if not exists(Path(localpath)):
7979
continue
8080

81-
if is_file(localpath):
81+
if is_file(Path(localpath)):
8282
remotepath = to_remotepath(os.path.basename(localpath), remotedir)
8383
ft.append(FromTo(localpath, remotepath))
8484
else:
8585
parents_num = max(len(Path(localpath).parts) - 1, 0)
86-
for sub_path in walk(localpath):
86+
for sub_path in walk(Path(localpath)):
8787
relative_path = Path(*Path(sub_path).parts[parents_num:]).as_posix()
8888
remotepath = to_remotepath(relative_path, remotedir)
8989
ft.append(FromTo(sub_path, remotepath))

0 commit comments

Comments
 (0)