Browse Source

restructure checks code

shut-new-model
Niklas Rosenstein 9 months ago
parent
commit
2614d2201f
No known key found for this signature in database GPG Key ID: 6D269B33D25F6C6
6 changed files with 48 additions and 29 deletions
  1. + 0
    - 2
      src/shut/__init__.py
  2. + 2
    - 1
      src/shut/checks/__init__.py
  3. + 41
    - 0
      src/shut/checks/basic.py
  4. + 0
    - 19
      src/shut/checks/core.py
  5. + 4
    - 6
      src/shut/checks/package.py
  6. + 1
    - 1
      src/shut/commands/pkg/checks.py

+ 0
- 2
src/shut/__init__.py

@ -21,5 +21,3 @@
__author__ = 'Niklas Rosenstein <rosensteinniklas@gmail.com>'
__version__ = '0.1.0'
from . import impl

src/shut/impl/__init__.py → src/shut/checks/__init__.py

@ -19,4 +19,5 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from . import setuptools
from . import basic, package
from .core import CheckStatus, get_checks

+ 41
- 0
src/shut/checks/basic.py

@ -0,0 +1,41 @@
# -*- coding: utf8 -*-
# Copyright (c) 2020 Niklas Rosenstein
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from .core import CheckResult, CheckStatus, Checker, check, register_checker
from shut.model import MonorepoModel, PackageModel, Project
from typing import Iterable, Optional, Union
class BasicChecker(Checker):
@check('unknown-config')
def _check_unknown_keys(
self,
project: 'Project',
obj: Union['MonorepoModel', 'PackageModel'],
) -> Iterable[CheckResult]:
yield CheckResult(
CheckStatus.WARNING if obj.unknown_keys else CheckStatus.PASSED,
', '.join(map(str, obj.unknown_keys)) if obj.unknown_keys else None)
register_checker(BasicChecker, MonorepoModel)
register_checker(BasicChecker, PackageModel)

src/shut/model/checks.py → src/shut/checks/core.py

@ -92,22 +92,3 @@ def get_checks(project: 'Project', obj: T) -> Iterable[Check]:
for checker in registry.get(type(obj), []):
yield from checker().get_checks(project, obj)
class BasicChecker(Checker):
@check('unknown-config')
def _check_unknown_keys(
self,
project: 'Project',
obj: Union['MonorepoModel', 'PackageModel'],
) -> Iterable[CheckResult]:
yield CheckResult(
CheckStatus.WARNING if obj.unknown_keys else CheckStatus.PASSED,
', '.join(map(str, obj.unknown_keys)) if obj.unknown_keys else None)
from shut.model import MonorepoModel, PackageModel, Project
register_checker(BasicChecker, MonorepoModel)
register_checker(BasicChecker, PackageModel)

src/shut/impl/setuptools.py → src/shut/checks/package.py

@ -21,16 +21,14 @@
from shore.util.classifiers import get_classifiers
from shut.model import Project
from shut.model.checks import CheckResult, CheckStatus, Checker, check, register_checker
from shut.model.monorepo import MonorepoModel
from shut.model.package import PackageModel
from .core import CheckResult, CheckStatus, Checker, check, register_checker
from shut.model import MonorepoModel, PackageModel, Project
from typing import Iterable, Optional
import os
class SetuptoolsChecker(Checker[PackageModel]):
class PackageChecker(Checker[PackageModel]):
@check('readme')
def _check_readme(self, project: Project, package: PackageModel) -> Iterable[CheckResult]:
@ -102,4 +100,4 @@ class SetuptoolsChecker(Checker[PackageModel]):
'file "py.typed" exists but $.typed is not set')
register_checker(SetuptoolsChecker, PackageModel)
register_checker(PackageChecker, PackageModel)

+ 1
- 1
src/shut/commands/pkg/checks.py

@ -19,9 +19,9 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from shut.checks import CheckStatus, get_checks
from shut.commands.pkg import pkg, project
from shut.model import PackageModel, Project
from shut.model.checks import CheckStatus, get_checks
from nr.stream import Stream
from termcolor import colored

Loading…
Cancel
Save