Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(lints): fix lints of isort #396

Merged
merged 3 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ repos:
language: python
types: [python]
pass_filenames: false
entry: isort --settings-path=pyproject.toml .
entry: isort --settings-path=pyproject.toml src
- id: black
name: black
language: python
types: [python]
pass_filenames: false
entry: black --config=pyproject.toml .
entry: black --config=pyproject.toml src
- id: flake8
name: flak8
language: python
types: [python]
pass_filenames: false
entry: pflake8 --config=pyproject.toml
entry: pflake8 --config=pyproject.toml src
- id: mypy
name: mypy
language: python
Expand Down
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ apigw-manager = "^1.0.3"

[tool.poetry.dev-dependencies]
# black
black = "^21.7b0"
black = "^22.3.0"
# isort
isort = "^5.9.2"
# flake8
Expand Down Expand Up @@ -49,17 +49,24 @@ force_grid_wrap = 0
use_parentheses = 'true'
line_length = 119
skip_glob = ["*/migrations/**", "*/sdk/**", "*/node_modules/**"]
known_local_folder =["bkuser_core", "bkuser_shell", "bkuser_global", "bkuser_sdk", "bklogin"]

[tool.flake8]
ignore = "C901,E203,W503"
max-line-length = 119
max-complexity = 8
format = "pylint"
show_source = "true"
statistics = "true"
count = "true"
exclude = "*migrations*,*.pyc,.git,__pycache__,*/node_modules/*,*/templates_module*,*/bin/*,*/config/*,*sdk*"

[tool.mypy]
ignore_missing_imports = true
follow_imports="skip"
show_error_codes = true
strict_optional=true
pretty=true

[[tool.mypy.overrides]]
module = [
Expand Down
3 changes: 2 additions & 1 deletion src/api/bkuser_core/apis/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"""
import datetime

from bkuser_core.apis.serializers import StringArrayField
from django.utils.translation import ugettext as _
from rest_framework import fields, serializers

from bkuser_core.apis.serializers import StringArrayField


class CustomFieldsModelSerializer(serializers.ModelSerializer):
"""
Expand Down
17 changes: 8 additions & 9 deletions src/api/bkuser_core/apis/v2/viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
from operator import or_
from typing import Any, Dict, List, Optional

from bkuser_core.audit.constants import OperationType
from bkuser_core.audit.utils import audit_general_log, create_general_log
from bkuser_core.bkiam.exceptions import IAMPermissionDenied
from bkuser_core.bkiam.filters import IAMFilter
from bkuser_core.bkiam.permissions import IAMPermission, IAMPermissionExtraInfo
from bkuser_core.common.cache import clear_cache_if_succeed
from bkuser_core.common.error_codes import error_codes
from django.conf import settings
from django.core.exceptions import FieldError, ObjectDoesNotExist
from django.db.models import ManyToOneRel, Q, QuerySet
Expand All @@ -32,10 +25,16 @@
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response

from bkuser_global.utils import force_str_2_bool

from .constants import LOOKUP_FIELD_NAME, LOOKUP_PARAM
from .serializers import AdvancedListSerializer, AdvancedRetrieveSerialzier, EmptySerializer, is_custom_fields_enabled
from bkuser_core.audit.constants import OperationType
from bkuser_core.audit.utils import audit_general_log, create_general_log
from bkuser_core.bkiam.exceptions import IAMPermissionDenied
from bkuser_core.bkiam.filters import IAMFilter
from bkuser_core.bkiam.permissions import IAMPermission, IAMPermissionExtraInfo
from bkuser_core.common.cache import clear_cache_if_succeed
from bkuser_core.common.error_codes import error_codes
from bkuser_global.utils import force_str_2_bool

logger = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion src/api/bkuser_core/audit/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import logging
from typing import TYPE_CHECKING

from django.dispatch import receiver

from bkuser_core.audit.constants import OperationType
from bkuser_core.audit.utils import create_general_log, create_profile_log
from bkuser_core.categories.signals import post_category_create
from bkuser_core.departments.signals import post_department_create
from bkuser_core.profiles.signals import post_field_create, post_profile_create, post_profile_update
from bkuser_core.user_settings.signals import post_setting_create, post_setting_update
from django.dispatch import receiver

if TYPE_CHECKING:
from bkuser_core.profiles.models import Profile
Expand Down
5 changes: 3 additions & 2 deletions src/api/bkuser_core/audit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
from dataclasses import dataclass
from typing import Optional

from django.db import models
from jsonfield import JSONField

from bkuser_core.audit.constants import LogInFailReason, OperationStatus
from bkuser_core.audit.managers import LogInManager, ResetPasswordManager
from bkuser_core.common.fields import EncryptField
from bkuser_core.common.models import TimestampedModel
from django.db import models
from jsonfield import JSONField


@dataclass
Expand Down
3 changes: 2 additions & 1 deletion src/api/bkuser_core/audit/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from bkuser_core.apis.v2.serializers import CustomFieldsMixin
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers

from bkuser_core.apis.v2.serializers import CustomFieldsMixin


class GeneralLogSerializer(CustomFieldsMixin, serializers.Serializer):
id = serializers.IntegerField(help_text=_("ID"))
Expand Down
2 changes: 1 addition & 1 deletion src/api/bkuser_core/audit/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from bkuser_core.apis.v2.constants import LOOKUP_FIELD_NAME
from django.conf.urls import url

from . import views
from bkuser_core.apis.v2.constants import LOOKUP_FIELD_NAME

PVAR_PROFILE_ID = r"(?P<%s>[a-z0-9-]+)" % LOOKUP_FIELD_NAME

Expand Down
8 changes: 5 additions & 3 deletions src/api/bkuser_core/audit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@
import logging
from typing import TYPE_CHECKING, Any, Dict, Optional

from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from bkuser_core.audit import models as log_models_module
from bkuser_core.audit.constants import OperationStatus, OperationType
from bkuser_core.audit.models import GeneralLog, ProfileRelatedLog
from bkuser_core.common.error_codes import CoreAPIError
from django.conf import settings
from django.utils.translation import ugettext_lazy as _

if TYPE_CHECKING:
from bkuser_core.profiles.models import Profile
from rest_framework.request import Request

from bkuser_core.profiles.models import Profile

logger = logging.getLogger(__name__)


Expand Down
3 changes: 1 addition & 2 deletions src/api/bkuser_core/audit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from bkuser_core.apis.v2.viewset import AdvancedListAPIView, AdvancedModelViewSet

from . import serializers as local_serializers
from .models import GeneralLog, LogIn, ResetPassword
from bkuser_core.apis.v2.viewset import AdvancedListAPIView, AdvancedModelViewSet


class GeneralLogViewSet(AdvancedModelViewSet, AdvancedListAPIView):
Expand Down
3 changes: 2 additions & 1 deletion src/api/bkuser_core/bkiam/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import logging
from collections import namedtuple

from bkuser_core.bkiam.helper import IAMHelper
from django.utils.translation import ugettext_lazy as _
from rest_framework import exceptions
from rest_framework.authentication import BasicAuthentication

from bkuser_core.bkiam.helper import IAMHelper

logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion src/api/bkuser_core/bkiam/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from operator import and_, or_
from typing import List

from bkuser_core.common.error_codes import error_codes
from django.conf import settings
from django.db.models import Q
from rest_framework import viewsets
Expand All @@ -32,6 +31,7 @@
IAMMethodSerializer,
IAMPageResponseSerializer,
)
from bkuser_core.common.error_codes import error_codes

logger = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion src/api/bkuser_core/bkiam/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
from typing import Any, Callable, Dict, List

import regex
from django.utils.translation import ugettext_lazy as _

from bkuser_core.categories.constants import CategoryType
from bkuser_core.categories.models import ProfileCategory, SyncTask
from bkuser_core.common.enum import AutoLowerEnum
from bkuser_core.departments.models import Department
from bkuser_core.profiles.models import DynamicFieldInfo, Profile
from django.utils.translation import ugettext_lazy as _


class IAMCallbackMethods(AutoLowerEnum):
Expand Down
6 changes: 3 additions & 3 deletions src/api/bkuser_core/bkiam/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
from dataclasses import dataclass
from typing import List

from bkuser_core.bkiam.constants import IAMAction, ResourceType
from bkuser_core.departments.models import Department
from bkuser_core.profiles.models import Profile
from django.conf import settings
from django.utils.translation import gettext as _
from rest_framework.permissions import BasePermission

from .base import IAMMiXin
from .helper import IAMHelper
from .utils import need_iam
from bkuser_core.bkiam.constants import IAMAction, ResourceType
from bkuser_core.departments.models import Department
from bkuser_core.profiles.models import Profile


@dataclass
Expand Down
7 changes: 3 additions & 4 deletions src/api/bkuser_core/bkiam/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from .base import BaseIAMViewSet
from .constants import ResourceType
from .serializers import DepartmentInstanceRespSLZ
from bkuser_core.categories.models import ProfileCategory
from bkuser_core.categories.serializers import CategorySerializer
from bkuser_core.departments.models import Department
from bkuser_core.departments.v2.serializers import DepartmentSerializer
from bkuser_core.profiles.models import DynamicFieldInfo
from bkuser_core.profiles.v2.serializers import DynamicFieldsSerializer

from .base import BaseIAMViewSet
from .constants import ResourceType
from .serializers import DepartmentInstanceRespSLZ


class DynamicFieldIAMViewSet(BaseIAMViewSet):
"""动态字段 IAM 回调"""
Expand Down
3 changes: 2 additions & 1 deletion src/api/bkuser_core/categories/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
from datetime import timedelta
from enum import auto

from bkuser_core.common.enum import AutoLowerEnum
from django.utils.translation import ugettext_lazy as _

from bkuser_core.common.enum import AutoLowerEnum

TIMEOUT_THRESHOLD = timedelta(hours=1)


Expand Down
5 changes: 3 additions & 2 deletions src/api/bkuser_core/categories/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
"""
import logging

from django.conf import settings
from django.dispatch import receiver

from bkuser_core.bkiam.constants import IAMAction, ResourceType
from bkuser_core.bkiam.helper import IAMHelper
from bkuser_core.categories.signals import post_category_create
from django.conf import settings
from django.dispatch import receiver

logger = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions src/api/bkuser_core/categories/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
import logging
from typing import TYPE_CHECKING, Dict

from bkuser_core.user_settings.loader import ConfigProvider

from .constants import CategoryType
from .plugins.constants import PLUGIN_NAME_SETTING_KEY
from bkuser_core.user_settings.loader import ConfigProvider

if TYPE_CHECKING:
from bkuser_core.categories.models import ProfileCategory # noqa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
"""
import logging

from django.core.management.base import BaseCommand

from bkuser_core.categories.constants import CategoryType
from bkuser_core.categories.models import ProfileCategory
from bkuser_core.categories.plugins.constants import PLUGIN_NAME_SETTING_KEY
from bkuser_core.user_settings.models import Setting, SettingMeta
from django.core.management.base import BaseCommand

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
"""
import logging

from django.core.management.base import BaseCommand

from bkuser_core.categories.models import ProfileCategory
from bkuser_core.categories.plugins.utils import make_periodic_sync_task
from django.core.management.base import BaseCommand

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import logging
import uuid

from django.core.management.base import BaseCommand

from bkuser_core.categories.models import ProfileCategory
from bkuser_core.categories.tasks import adapter_sync
from django.core.management.base import BaseCommand

logger = logging.getLogger(__name__)

Expand Down
11 changes: 6 additions & 5 deletions src/api/bkuser_core/categories/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
from typing import Dict, List
from uuid import UUID, uuid4

from django.db import models
from django.utils import timezone
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from django_celery_beat.models import PeriodicTask

from bkuser_core.audit.models import AuditObjMetaInfo
from bkuser_core.categories.constants import TIMEOUT_THRESHOLD, CategoryStatus, SyncStep, SyncTaskStatus, SyncTaskType
from bkuser_core.categories.db_managers import ProfileCategoryManager
Expand All @@ -21,11 +27,6 @@
from bkuser_core.profiles.constants import ProfileStatus
from bkuser_core.profiles.models import Profile
from bkuser_core.user_settings.models import Setting, SettingMeta
from django.db import models
from django.utils import timezone
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from django_celery_beat.models import PeriodicTask


class ProfileCategory(TimestampedModel):
Expand Down
Loading