Skip to content

Commit 7b0c59d

Browse files
authored
refator: [blue-krill] upgrade pyproject.toml to follow PEP 621 standard & update license header (TencentBlueKing#215)
1 parent f517576 commit 7b0c59d

92 files changed

Lines changed: 2324 additions & 1811 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/blue-krill.yml

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,11 @@ jobs:
2222
uses: actions/setup-python@v2
2323
with:
2424
python-version: 3.11
25-
- name: Format with isort
25+
- name: Check with ruff
2626
working-directory: sdks/blue-krill
2727
run: |
28-
pip install isort==5.12.0
29-
isort . --settings-path=pyproject.toml
30-
- name: Format with black
31-
working-directory: sdks/blue-krill
32-
run: |
33-
pip install black==23.7.0 click==8.1.6
34-
black . --config=pyproject.toml
35-
- name: Lint with flake8
36-
working-directory: sdks/blue-krill
37-
run: |
38-
pip install flake8==4.0.1 pyproject-flake8==0.0.1a5
39-
pflake8 . --config=pyproject.toml
28+
pip install ruff==0.9.6
29+
ruff check --config ../../pyproject.toml
4030
- name: Lint with mypy
4131
working-directory: sdks/blue-krill
4232
run: |
@@ -46,7 +36,7 @@ jobs:
4636
strategy:
4737
fail-fast: false
4838
matrix:
49-
python-version: ["3.8", "3.9", "3.10", "3.11"]
39+
python-version: ["3.9", "3.10", "3.11"]
5040
os: [ubuntu-latest, macos-latest]
5141
runs-on: ${{ matrix.os }}
5242
steps:
@@ -55,10 +45,6 @@ jobs:
5545
uses: actions/setup-python@v2
5646
with:
5747
python-version: ${{ matrix.python-version }}
58-
- name: Set up Poetry
59-
uses: abatilo/actions-poetry@v2.3.0
60-
with:
61-
poetry-version: 1.5.1
6248
- name: Start Redis Container
6349
uses: supercharge/redis-github-action@1.4.0
6450
if: runner.os == 'Linux'
@@ -68,29 +54,26 @@ jobs:
6854
if: runner.os == 'Linux'
6955
run: |
7056
echo "REDIS_URL=redis://localhost:6379/0" >> $GITHUB_ENV
71-
- name: Install dependencies
72-
working-directory: sdks/blue-krill
73-
run: |
74-
poetry export --without-hashes --dev -o requirements-dev.txt
75-
python -m pip install --upgrade pip
76-
python -m pip install -r requirements-dev.txt
77-
python -m pip install tox-gh-actions==2.8.1
78-
- name: Run test with tox targets for ${{ matrix.python-version }}
57+
- name: Setup uv
58+
uses: astral-sh/setup-uv@v5
59+
- name: Install Nox
60+
run: uv pip install --system nox
61+
- name: Run tests on ${{ matrix.os }}
7962
working-directory: sdks/blue-krill
80-
run: tox
63+
run: nox --non-interactive --error-on-missing-interpreter --session "tests(python='${{ matrix.python-version }}')" -- --full-trace
8164
build:
8265
runs-on: macos-latest
8366
if: github.event.release && contains(github.event.release.tag_name, 'blue-krill')
8467
steps:
8568
- uses: actions/checkout@v2
8669
- name: Set up Python
87-
uses: actions/setup-python@v2
70+
uses: actions/setup-python@v5
8871
with:
89-
python-version: 3.8
72+
python-version: 3.11
9073
- name: Set up Poetry
9174
uses: abatilo/actions-poetry@v2.3.0
9275
with:
93-
poetry-version: 1.5.1
76+
poetry-version: 2.1.1
9477
- name: Build blue-krill
9578
run: |
9679
cd sdks/blue-krill

pyproject.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ ruff = "^0.1.7"
1313
[tool.ruff]
1414
line-length = 119
1515

16+
# 添加需要额外忽略的目录,比如 Django 自动生成的 migrations 目录
17+
extend-exclude = ["*/migrations"]
18+
19+
[tool.ruff.lint]
20+
1621
# 每个规则集的具体内容请参考:https://docs.astral.sh/ruff/rules/
1722
select = [
1823
"E",
@@ -32,6 +37,7 @@ select = [
3237
"PT",
3338
]
3439

40+
3541
# 理论上来说,ignore 规则列表中的条目越少越好。但在实际项目中,选择性地忽略某些规则常常是必须的。
3642
# 下面收集了常见的待忽略规则集,并将其分为两类:“推荐忽略”和“谨慎忽略”。“推荐忽略”类中所包含的规
3743
# 则,所有项目建议默认启用。“谨慎忽略”类中的规则,项目可酌情添加。
@@ -94,13 +100,10 @@ ignore = [
94100
"PLW0603",
95101
]
96102

97-
# 添加需要额外忽略的目录,比如 Django 自动生成的 migrations 目录
98-
extend-exclude = ["*/migrations"]
99-
100103
[tool.ruff.format]
101104
quote-style = "double"
102105

103-
[tool.ruff.isort]
106+
[tool.ruff.lint.isort]
104107
# 总是显式制定 import section 的顺序
105108
section-order = [
106109
"future",
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# -*- coding: utf-8 -*-
2-
"""
3-
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-蓝鲸 PaaS 平台(BlueKing-PaaS) available.
4-
* Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved.
5-
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at http://opensource.org/licenses/MIT
7-
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8-
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9-
* specific language governing permissions and limitations under the License.
10-
"""
2+
# TencentBlueKing is pleased to support the open source community by making
3+
# 蓝鲸智云 - PaaS 平台 (BlueKing - PaaS System) available.
4+
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
5+
# Licensed under the MIT License (the "License"); you may not use this file except
6+
# in compliance with the License. You may obtain a copy of the License at
7+
#
8+
# http://opensource.org/licenses/MIT
9+
#
10+
# Unless required by applicable law or agreed to in writing, software distributed under
11+
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
# either express or implied. See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# We undertake not to change the open source license (MIT license) applicable
16+
# to the current version of the project delivered to anyone in the future.
17+
1118
__version__ = "2.0.7"
Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# -*- coding: utf-8 -*-
2-
"""
3-
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-蓝鲸 PaaS 平台(BlueKing-PaaS) available.
4-
* Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved.
5-
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at http://opensource.org/licenses/MIT
7-
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8-
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9-
* specific language governing permissions and limitations under the License.
10-
"""
2+
# TencentBlueKing is pleased to support the open source community by making
3+
# 蓝鲸智云 - PaaS 平台 (BlueKing - PaaS System) available.
4+
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
5+
# Licensed under the MIT License (the "License"); you may not use this file except
6+
# in compliance with the License. You may obtain a copy of the License at
7+
#
8+
# http://opensource.org/licenses/MIT
9+
#
10+
# Unless required by applicable law or agreed to in writing, software distributed under
11+
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
# either express or implied. See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# We undertake not to change the open source license (MIT license) applicable
16+
# to the current version of the project delivered to anyone in the future.
17+

sdks/blue-krill/blue_krill/async_utils/django_utils.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
# -*- coding: utf-8 -*-
2-
"""
3-
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-蓝鲸 PaaS 平台(BlueKing-PaaS) available.
4-
* Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved.
5-
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at http://opensource.org/licenses/MIT
7-
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8-
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9-
* specific language governing permissions and limitations under the License.
10-
"""
2+
# TencentBlueKing is pleased to support the open source community by making
3+
# 蓝鲸智云 - PaaS 平台 (BlueKing - PaaS System) available.
4+
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
5+
# Licensed under the MIT License (the "License"); you may not use this file except
6+
# in compliance with the License. You may obtain a copy of the License at
7+
#
8+
# http://opensource.org/licenses/MIT
9+
#
10+
# Unless required by applicable law or agreed to in writing, software distributed under
11+
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
# either express or implied. See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# We undertake not to change the open source license (MIT license) applicable
16+
# to the current version of the project delivered to anyone in the future.
17+
1118

1219
import logging
1320
from functools import partial
@@ -24,7 +31,7 @@ def apply_async_on_commit(celery_task, using: Optional[str] = None, *args, **kwa
2431
it will trigger the task on transaction commit when it is in a atomic block.
2532
"""
2633

27-
fn = partial(celery_task.apply_async, ignore_result=True, *args, **kwargs)
34+
fn = partial(celery_task.apply_async, ignore_result=True, *args, **kwargs) # noqa: B026
2835

2936
connection = transaction.get_connection(using)
3037
if connection.in_atomic_block:

sdks/blue-krill/blue_krill/async_utils/poll_task.py

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
# -*- coding: utf-8 -*-
2-
"""
3-
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-蓝鲸 PaaS 平台(BlueKing-PaaS) available.
4-
* Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved.
5-
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at http://opensource.org/licenses/MIT
7-
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8-
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9-
* specific language governing permissions and limitations under the License.
10-
"""
2+
# TencentBlueKing is pleased to support the open source community by making
3+
# 蓝鲸智云 - PaaS 平台 (BlueKing - PaaS System) available.
4+
# Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
5+
# Licensed under the MIT License (the "License"); you may not use this file except
6+
# in compliance with the License. You may obtain a copy of the License at
7+
#
8+
# http://opensource.org/licenses/MIT
9+
#
10+
# Unless required by applicable law or agreed to in writing, software distributed under
11+
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
12+
# either express or implied. See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# We undertake not to change the open source license (MIT license) applicable
16+
# to the current version of the project delivered to anyone in the future.
17+
1118

1219
import logging
1320
import time
@@ -41,7 +48,7 @@ def __init__(self, status: PollingStatus, data: Optional[Any] = None):
4148
self.data = data
4249

4350
def __str__(self):
44-
return f'stauts={self.status} data={self.data}'
51+
return f"stauts={self.status} data={self.data}"
4552

4653
@classmethod
4754
def doing(cls, *args, **kwargs):
@@ -73,7 +80,7 @@ class TaskPoller(ABC):
7380
:param metadata: metadata object of current poller
7481
"""
7582

76-
_registered_pollers: Dict[str, Type['TaskPoller']] = {}
83+
_registered_pollers: Dict[str, Type["TaskPoller"]] = {}
7784

7885
max_retries_on_error = 10
7986
overall_timeout_seconds = 3600 * 24 * 7
@@ -87,7 +94,7 @@ def __init_subclass__(cls, *args, **kwargs):
8794
cls._registered_pollers[cls.__name__] = cls
8895

8996
@classmethod
90-
def get_poller_cls(cls, name: str) -> Type['TaskPoller']:
97+
def get_poller_cls(cls, name: str) -> Type["TaskPoller"]:
9198
return cls._registered_pollers[name]
9299

93100
@classmethod
@@ -145,10 +152,10 @@ def exceeded_max_retries(self) -> bool:
145152
return (self.metadata.retries + 1) > self.max_retries_on_error
146153

147154
def __str__(self):
148-
return '<%s: params=%s>' % (self.__class__.__name__, self.params)
155+
return "<%s: params=%s>" % (self.__class__.__name__, self.params)
149156

150157
@classmethod
151-
def get_async_task(self) -> Any:
158+
def get_async_task(cls) -> Any:
152159
"""Return the async celery task object for polling in backend"""
153160
return check_status_until_finished
154161

@@ -182,10 +189,10 @@ def is_exception(self):
182189
return self.status.is_exception()
183190

184191
def to_dict(self):
185-
return {'status': self.status.value, 'message': self.message, 'data': self.data}
192+
return {"status": self.status.value, "message": self.message, "data": self.data}
186193

187194
def __str__(self):
188-
return '<%s: %s is_exception=%s>' % (self.__class__.__name__, self.to_dict(), self.is_exception)
195+
return "<%s: %s is_exception=%s>" % (self.__class__.__name__, self.to_dict(), self.is_exception)
189196

190197

191198
class CallbackHandler(ABC):
@@ -194,13 +201,13 @@ class CallbackHandler(ABC):
194201
:params: params of current polling result
195202
"""
196203

197-
_registered_handlers: Dict[str, Type['CallbackHandler']] = {}
204+
_registered_handlers: Dict[str, Type["CallbackHandler"]] = {}
198205

199206
def __init_subclass__(cls, *args, **kwargs):
200207
cls._registered_handlers[cls.__name__] = cls
201208

202209
@classmethod
203-
def get_handler_cls(cls, name: str) -> Type['CallbackHandler']:
210+
def get_handler_cls(cls, name: str) -> Type["CallbackHandler"]:
204211
return cls._registered_handlers[name]
205212

206213
@abstractmethod
@@ -220,7 +227,7 @@ def handle(self, result: CallbackResult, poller: TaskPoller):
220227
pass
221228

222229

223-
@shared_task(acks_late=True, name='poll_task.check_status_until_finished')
230+
@shared_task(acks_late=True, name="poll_task.check_status_until_finished")
224231
def check_status_until_finished(poller_name: str, handler_name: str, params: Dict, queue: Optional[str] = None):
225232
"""Main async task for polling
226233
@@ -232,9 +239,9 @@ def check_status_until_finished(poller_name: str, handler_name: str, params: Dic
232239
req = check_status_until_finished.request
233240
metadata = PollingMetadata(
234241
retries=req.retries,
235-
query_started_at=req.get('query_started_at', time.time()),
236-
queried_count=req.get('queried_count', 0),
237-
last_polling_data=req.get('last_polling_data'),
242+
query_started_at=req.get("query_started_at", time.time()),
243+
queried_count=req.get("queried_count", 0),
244+
last_polling_data=req.get("last_polling_data"),
238245
)
239246

240247
# Make handler and poller by name
@@ -250,18 +257,18 @@ def check_status_until_finished(poller_name: str, handler_name: str, params: Dic
250257
if next_metadata:
251258
# Start next polling
252259
countdown = poller.get_retry_delay()
253-
logger.debug('Will retry query status for %s after %s seconds. metadata=%s', poller, countdown, metadata)
260+
logger.debug("Will retry query status for %s after %s seconds. metadata=%s", poller, countdown, metadata)
254261
poller.get_async_task().subtask(
255262
args=(poller_name, handler_name, params),
256-
kwargs={'queue': queue},
263+
kwargs={"queue": queue},
257264
countdown=countdown,
258265
retries=next_metadata.retries,
259266
queue=queue,
260267
).apply_async(
261268
headers={
262-
'queried_count': next_metadata.queried_count,
263-
'query_started_at': next_metadata.query_started_at,
264-
'last_polling_data': next_metadata.last_polling_data,
269+
"queried_count": next_metadata.queried_count,
270+
"query_started_at": next_metadata.query_started_at,
271+
"last_polling_data": next_metadata.last_polling_data,
265272
}
266273
)
267274

@@ -280,7 +287,7 @@ def __init__(self, poller: TaskPoller, handler_cls: Type[CallbackHandler]):
280287
def run(self) -> Optional[PollingMetadata]:
281288
"""Start schedule process"""
282289
if self.poller.exceeded_timeout():
283-
logger.info('exceeded total timeout, ts_query_started=%s' % self.poller.metadata.query_started_at)
290+
logger.info("exceeded total timeout, ts_query_started=%s", self.poller.metadata.query_started_at)
284291
self._callback_timeout()
285292
return None
286293

@@ -314,10 +321,10 @@ def _safe_query(poller: TaskPoller) -> PollingResult:
314321
try:
315322
polling_result = poller.query()
316323
except Exception as e:
317-
logger.exception('Exception when query status, poll_class=%s' % poller)
324+
logger.exception("Exception when query status, poll_class=%s", poller)
318325
raise PollingQueryError(str(e))
319326

320-
logger.debug('Query status result, poll_class=%s, polling result: %s' % (poller, polling_result))
327+
logger.debug("Query status result, poll_class=%s, polling result: %s", poller, polling_result)
321328
return polling_result
322329

323330
def _callback(self, result: CallbackResult):
@@ -326,10 +333,10 @@ def _callback(self, result: CallbackResult):
326333

327334
def _callback_timeout(self):
328335
"""Callback handler with timeout result"""
329-
ret = CallbackResult(status=CallbackStatus.TIMEOUT, message='exceeded total timeout')
336+
ret = CallbackResult(status=CallbackStatus.TIMEOUT, message="exceeded total timeout")
330337
self.handler_cls().handle(ret, self.poller)
331338

332339
def _callback_exception(self, e: Exception):
333340
"""Callback handler when exceeds max retries"""
334-
ret = CallbackResult(status=CallbackStatus.EXCEPTION, message=f'exception: {e}')
341+
ret = CallbackResult(status=CallbackStatus.EXCEPTION, message=f"exception: {e}")
335342
self.handler_cls().handle(ret, self.poller)

0 commit comments

Comments
 (0)