Skip to content

Commit

Permalink
feat: updat ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
nannan00 committed Nov 13, 2023
1 parent feda50f commit a527a64
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 390 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/bk-user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ jobs:
run: |
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-login/bklogin
ln -s $(pwd)/src/idp-plugins/idp_plugins $(pwd)/src/bk-user/bkuser
- name: Format with black
- name: Format & Lint with ruff
run: |
pip install black==23.7.0 click==8.1.6
black src/bk-user --config=src/bk-user/pyproject.toml
- name: Lint with ruff
run: |
pip install ruff==0.0.277
pip install ruff==0.1.4
ruff format src/bk-user --config=src/bk-user/pyproject.toml
ruff src/bk-user --config=src/bk-user/pyproject.toml
ruff format src/bk-login --config=src/bk-login/pyproject.toml
ruff src/bk-login --config=src/bk-login/pyproject.toml
ruff format src/idp-plugins --config=src/idp-plugins/pyproject.toml
ruff src/idp-plugins --config=src/idp-plugins/pyproject.toml
- name: Lint with mypy
run: |
pip install mypy==1.6.1 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 types-pytz==2023.3.0.0 types-urllib3==1.26.25.14
mypy src/bk-user --config-file=src/bk-user/pyproject.toml
mypy src/bk-login --config-file=src/bk-login/pyproject.toml
mypy src/idp-plugins --config-file=src/idp-plugins/pyproject.toml
test:
strategy:
fail-fast: false
Expand Down
22 changes: 11 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ repos:
entry: bash -c "if [[ -d pre_commit_hooks ]]; then pre_commit_hooks/ip.sh $@; fi"
- repo: local
hooks:
- id: black
name: black
- id: format
name: ruff-formatter
language: python
types: [python]
entry: black --config=src/bk-user/pyproject.toml
entry: ruff format --config=src/bk-user/pyproject.toml --force-exclude
files: src/bk-user/
- id: ruff
name: ruff
Expand All @@ -74,11 +74,11 @@ repos:
entry: bash -c "cd src/bk-user && lint-imports"
- repo: local
hooks:
- id: black
name: black
- id: format
name: ruff-formatter
language: python
types: [python]
entry: black --config=src/bk-login/pyproject.toml
entry: ruff format --config=src/bk-login/pyproject.toml --force-exclude
files: src/bk-login/
- id: ruff
name: ruff
Expand All @@ -99,18 +99,18 @@ repos:
entry: bash -c "cd src/bk-login && lint-imports"
- repo: local
hooks:
- id: black
name: black
- id: format
name: ruff-formatter
language: python
types: [python]
entry: black --config=src/idp-plugins/pyproject.toml
files: src/idp-plugins/
entry: ruff format --config=src/bk-plugins/pyproject.toml --force-exclude
files: src/bk-plugins/
- id: ruff
name: ruff
language: python
types: [python]
entry: ruff --config=src/idp-plugins/pyproject.toml --force-exclude --fix
files: src/bk-login/
files: src/idp-plugins/
- id: mypy
name: mypy
language: python
Expand Down
127 changes: 20 additions & 107 deletions src/bk-login/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 1 addition & 10 deletions src/bk-login/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,13 @@ pydantic = "2.3.0"
blue-krill = "2.0.2"

[tool.poetry.group.dev.dependencies]
ruff = "^0.0.290"
black = "^23.9.1"
ruff = "^0.1.4"
mypy = "^1.5.1"
types-requests = "^2.31.0.2"
pytest = "^7.4.2"
pytest-django = "^4.5.2"
import-linter = "^1.11.1"

[tool.black]
line-length = 119
force-exclude = '''
/(
migrations
)/
'''

[tool.mypy]
ignore_missing_imports = true
show_error_codes = true
Expand Down
4 changes: 3 additions & 1 deletion src/bk-user/bkuser/apis/web/tenant/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def validate_id(self, id: str) -> str:
raise ValidationError(_("租户 ID {} 已被使用").format(id))

if not re.fullmatch(TENANT_ID_REGEX, id):
raise ValidationError(_("{} 不符合 租户ID 的命名规范: 由3-32位字母、数字、连接符(-)字符组成,以字母开头").format(id)) # noqa: E501
raise ValidationError(
_("{} 不符合 租户ID 的命名规范: 由3-32位字母、数字、连接符(-)字符组成,以字母开头").format(id)
) # noqa: E501

return id

Expand Down
3 changes: 2 additions & 1 deletion src/bk-user/bkuser/apps/data_source/initializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def __init__(self, data_source: DataSource):
return

self.password_provider = PasswordProvider(
self.plugin_cfg.password_rule, self.plugin_cfg.password_initial # type: ignore
self.plugin_cfg.password_rule, # type: ignore
self.plugin_cfg.password_initial, # type: ignore
)

def initialize(self, users: Optional[List[DataSourceUser]] = None) -> Tuple[List[DataSourceUser], Dict[int, str]]:
Expand Down
4 changes: 3 additions & 1 deletion src/bk-user/bkuser/biz/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
def validate_data_source_user_username(value):
if not re.fullmatch(DATA_SOURCE_USERNAME_REGEX, value):
raise ValidationError(
_("{} 不符合 用户名 的命名规范: 由3-32位字母、数字、下划线(_)、点(.)、连接符(-)字符组成,以字母或数字开头及结尾").format(value), # noqa: E501
_(
"{} 不符合 用户名 的命名规范: 由3-32位字母、数字、下划线(_)、点(.)、连接符(-)字符组成,以字母或数字开头及结尾" # noqa: E501
).format(value),
)
4 changes: 3 additions & 1 deletion src/bk-user/bkuser/plugins/general/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ def fetch_first_item(url: str, headers: Dict[str, str], params: Dict[str, Any],
resp_data = resp.json()
except JSONDecodeError: # noqa: PERF203
raise RespDataFormatError(
_("数据源 API {} 参数 {} 返回非 Json 格式,响应内容 {}").format(url, stringify_params(params), resp.content) # noqa: E501
_("数据源 API {} 参数 {} 返回非 Json 格式,响应内容 {}").format(
url, stringify_params(params), resp.content
) # noqa: E501
)

results = resp_data.get("results", [])
Expand Down
4 changes: 3 additions & 1 deletion src/bk-user/bkuser/plugins/local/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def _validate_and_prepare(self): # noqa: C901
# 6. 检查用户名是否合法
if not USERNAME_REGEX.fullmatch(username):
raise InvalidUsername(
_("用户名 {} 不符合命名规范: 由3-32位字母、数字、下划线(_)、点(.)、连接符(-)字符组成,以字母或数字开头").format(username) # noqa: E501
_(
"用户名 {} 不符合命名规范: 由3-32位字母、数字、下划线(_)、点(.)、连接符(-)字符组成,以字母或数字开头" # noqa: E501
).format(username)
)

# 7. 检查用户不能是自己的 leader
Expand Down
Loading

0 comments on commit a527a64

Please sign in to comment.