Skip to content

Commit 5c0bd5b

Browse files
authored
feat: update bk-storages to 2.0.0 (TencentBlueKing#195)
1 parent cb23fbb commit 5c0bd5b

10 files changed

Lines changed: 154 additions & 247 deletions

File tree

.github/workflows/bk-storages.yml

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,62 @@ name: CI Check for bk-storages
22

33
on:
44
push:
5-
branches: [ master, staging ]
5+
branches: [master, staging]
66
paths:
7-
- 'sdks/bk-storages/**'
7+
- "sdks/bk-storages/**"
88
pull_request:
9-
branches: [ master, staging ]
9+
branches: [master, staging]
1010
paths:
11-
- 'sdks/bk-storages/**'
11+
- "sdks/bk-storages/**"
1212
workflow_dispatch:
13-
1413
jobs:
1514
check:
1615
runs-on: macos-latest
1716
steps:
18-
- uses: actions/checkout@v2
19-
- name: Set up Python
20-
uses: actions/setup-python@v2
21-
with:
22-
python-version: 3.7
23-
- name: Format with isort
24-
run: |
25-
pip install isort==5.9.2
26-
isort sdks/ --settings-path=sdks/bk-storages/pyproject.toml
27-
- name: Format with black
28-
run: |
29-
pip install black==21.7b0 click==8.0.4
30-
black sdks/ --config=sdks/bk-storages/pyproject.toml
31-
- name: Lint with flake8
32-
run: |
33-
pip install pyproject-flake8
34-
pflake8 sdks/ --config=sdks/bk-storages/pyproject.toml
35-
- name: Lint with mypy
36-
run: |
37-
pip install mypy==0.910 types-requests==2.25.0 types-setuptools==57.0.0 types-dataclasses==0.1.5 types-redis==3.5.4 types-PyMySQL==1.0.0 types-six==0.1.7 types-toml==0.1.3
38-
mypy sdks/bk-storages --config-file=sdks/bk-storages/pyproject.toml
17+
- uses: actions/checkout@v2
18+
- name: Set up Python
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: 3.11
22+
- name: Format with isort
23+
working-directory: sdks/bk-storages
24+
run: |
25+
pip install isort==5.12.0
26+
isort . --settings-path=pyproject.toml
27+
- name: Format with black
28+
working-directory: sdks/bk-storages
29+
run: |
30+
pip install black==23.7.0 click==8.1.6
31+
black . --config=pyproject.toml
32+
- name: Lint with flake8
33+
working-directory: sdks/bk-storages
34+
run: |
35+
pip install flake8==4.0.1 pyproject-flake8==0.0.1a5
36+
pflake8 . --config=pyproject.toml
37+
- name: Lint with mypy
38+
working-directory: sdks/bk-storages
39+
run: |
40+
pip install mypy==0.910 types-requests==2.31.0.2 types-setuptools==57.4.18 types-dataclasses==0.1.7 types-redis==3.5.18 types-PyMySQL==1.1.0.1 types-six==0.1.9 types-toml==0.1.5
41+
mypy . --config-file=pyproject.toml
3942
test:
4043
strategy:
4144
fail-fast: false
4245
matrix:
43-
python-version: ['3.7', '3.8', '3.9', '3.10']
44-
poetry-version: [1.3.2]
46+
python-version: ["3.8", "3.9", "3.10", "3.11"]
4547
os: [ubuntu-latest, macos-latest]
4648
runs-on: ${{ matrix.os }}
4749
steps:
48-
- uses: actions/checkout@v2
49-
- name: Set up Python
50-
uses: actions/setup-python@v2
51-
with:
52-
python-version: ${{ matrix.python-version }}
53-
- name: Set up Poetry
54-
uses: abatilo/actions-poetry@v2.1.0
55-
with:
56-
poetry-version: ${{ matrix.poetry-version }}
57-
- name: Test bk-storages
58-
run: |
59-
cd sdks/bk-storages
60-
poetry install
61-
poetry run pytest
50+
- uses: actions/checkout@v2
51+
- name: Set up Python
52+
uses: actions/setup-python@v2
53+
with:
54+
python-version: ${{ matrix.python-version }}
55+
- name: Set up Poetry
56+
uses: abatilo/actions-poetry@v2.3.0
57+
with:
58+
poetry-version: 1.5.1
59+
- name: Test bk-storages
60+
run: |
61+
cd sdks/bk-storages
62+
poetry install
63+
poetry run pytest

sdks/bk-storages/CHANGE.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
## Change logs
2+
3+
### 2.0.0
4+
5+
- 支持 Python 3.11,移除对 Python 3.6, 3.7 的支持
6+
- Django 版本要求 >= 3.2.25
7+
- 禁止在保存的文件名中使用绝对路径(如:/etc/passwd)或相对路径(如:../../passwd)
8+
29
### 1.1.1
10+
311
- 扩展支持的 Python 版本(>=3.6,<3.12)
412

513
### 1.1.0
14+
615
- 调整 `BKRepoStorage` 公开仓库的 url 实现: 直接返回资源的路径, 而并非生成临时访问地址
716

817
### 1.0.8
18+
919
- 扩展支持的 Python 版本(>=3.6,<3.11), 并修复单元测试在 django>=2.2.27 时无法通过的问题
1020

1121
### 1.0.7
22+
1223
- 修复 `BKRepoStorage` 在保存没有配置名称的 File 对象时会触发无法上传的问题
1324

1425
### 1.0.6
26+
1527
- `BKRepoStorage` 增加 DownloadFailedError 和 UploadFailedError 异常
1628

1729
### 1.0.5

sdks/bk-storages/README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ storage.delete('/test/temp_file.txt')
162162

163163
## 开发指南
164164

165-
首先安装 [poetry](https://github.com/python-poetry/poetry) ,之后在项目目录下执行 `poetry env use python3.6` 初始化开发用虚拟环境。然后用 `poetry shell` 命令激活虚拟环境。
165+
首先安装 [poetry](https://github.com/python-poetry/poetry) ,之后在项目目录下执行 `poetry env use python3.11` 初始化开发用虚拟环境。然后用 `poetry shell` 命令激活虚拟环境。
166166

167167
- 执行 `poetry install` 安装所有依赖
168168
- 使用 `pytest -s .` 执行所有单元测试
@@ -174,12 +174,3 @@ storage.delete('/test/temp_file.txt')
174174
### 发布包
175175

176176
首先,执行 `poetry build` 命令在 dist 目录下生成当前版本的包。然后执行 `twine upload dist/* --repository-url {pypi_address} --username {your_name} --password {your_token}` 将其上传到 pypi 服务器上。
177-
178-
### 关于 setup.py
179-
180-
虽然在 [PEP 517](https://python-poetry.org/docs/pyproject/#poetry-and-pep-517) 规范里,Python 包不再需要 `setup.py` 文件。但真正少了 `setup.py` 文件后,会发现有些功能就没法正常使用,比如 pip 的可编辑安装模式、tox 等( [相关文档](https://github.com/python-poetry/poetry/issues/761) )。所以我们仍然需要它。
181-
182-
为了避免维护重复的 `pyproject.toml``setup.py` 文件,我们使用了 [dephell](https://github.com/dephell/dephell) 工具来自动生成 `setup.py` 文件。
183-
184-
- 安装 dephell
185-
- 在根目录执行 `dephell deps convert --from pyproject.toml --to setup.py`

sdks/bk-storages/bkstorages/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
99
* specific language governing permissions and limitations under the License.
1010
"""
11-
__version__ = "1.1.1"
11+
__version__ = "2.0.0"

sdks/bk-storages/bkstorages/backends/rgw.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from django.core.files.base import File
2424
from django.core.files.storage import Storage
2525
from django.utils.deconstruct import deconstructible
26-
from django.utils.encoding import filepath_to_uri, force_bytes, force_text, smart_str
26+
from django.utils.encoding import filepath_to_uri, force_bytes, force_str, smart_str
2727
from django.utils.timezone import is_naive, localtime
2828
from six import BytesIO, string_types
2929
from six.moves.urllib import parse as urlparse
@@ -46,8 +46,8 @@ def percent_encode(input_str, safe=SAFE_CHARS, encoding=None):
4646
encoding = encoding or setting('RGW_FILE_NAME_CHARSET', 'utf-8')
4747

4848
if not isinstance(input_str, string_types):
49-
input_str = force_text(input_str, encoding)
50-
return quote(force_text(input_str, encoding).encode('utf-8'), safe=safe)
49+
input_str = force_str(input_str, encoding)
50+
return quote(force_str(input_str, encoding).encode('utf-8'), safe=safe)
5151

5252

5353
# Start patch botocore to fix Non-ascii filename exception
@@ -408,7 +408,7 @@ def _encode_name(self, name):
408408
return smart_str(name, encoding=self.file_name_charset)
409409

410410
def _decode_name(self, name):
411-
return force_text(name, encoding=self.file_name_charset)
411+
return force_str(name, encoding=self.file_name_charset)
412412

413413
def _compress_content(self, content):
414414
"""Gzip a given string content."""

sdks/bk-storages/bkstorages/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from django.conf import settings
1515
from django.core.exceptions import ImproperlyConfigured, SuspiciousFileOperation
16-
from django.utils.encoding import force_text
16+
from django.utils.encoding import force_str
1717
from six.moves.urllib.parse import urljoin
1818

1919

@@ -70,9 +70,9 @@ def safe_join(base, *paths):
7070
Paths outside the base path indicate a possible security
7171
sensitive operation.
7272
"""
73-
base_path = force_text(base)
73+
base_path = force_str(base)
7474
base_path = base_path.rstrip('/')
75-
paths = [force_text(p) for p in paths]
75+
paths = [force_str(p) for p in paths]
7676

7777
final_path = base_path
7878
for path in paths:

0 commit comments

Comments
 (0)