Refactor, typing improvements, ci improvements
Some checks failed
/ pylint (push) Successful in 12s
/ typing-mypy (push) Failing after 10s

This commit is contained in:
Firq 2024-07-05 11:15:07 +02:00
parent d3e5d4ae56
commit e44fd8a7a5
Signed by: Firq
GPG key ID: 3ACC61C8CEC83C20
9 changed files with 141 additions and 107 deletions

View file

@ -6,7 +6,7 @@ on:
- '[0-9]+\.[0-9]+\.[0-9]' - '[0-9]+\.[0-9]+\.[0-9]'
jobs: jobs:
backend-pylint: lint-and-typing:
runs-on: docker runs-on: docker
container: nikolaik/python-nodejs:python3.11-nodejs21 container: nikolaik/python-nodejs:python3.11-nodejs21
steps: steps:
@ -15,15 +15,20 @@ jobs:
- name: Install packages - name: Install packages
run: | run: |
pip install -e . -q pip install -e . -q
pip install pylint~=2.17.7 mypy~=1.10.1 --disable-pip-version-check -q
mypy --install-types
python -m pip list --format=columns --disable-pip-version-check python -m pip list --format=columns --disable-pip-version-check
pip install pylint~=2.17.7 --disable-pip-version-check -q
- name: Run pylint - name: Run pylint
run: | run: |
pylint --version pylint --version
pylint **/*.py --exit-zero --rc-file pyproject.toml pylint **/*.py --exit-zero --rc-file pyproject.toml
- name: Run mypy
run: |
mypy --version
mypy .
build-artifacts: build-artifacts:
needs: ["backend-pylint"] needs: ["lint-and-typing"]
runs-on: docker runs-on: docker
container: nikolaik/python-nodejs:python3.11-nodejs21 container: nikolaik/python-nodejs:python3.11-nodejs21
steps: steps:

View file

@ -3,7 +3,7 @@ on:
branches: "**" branches: "**"
jobs: jobs:
backend-pylint: pylint:
runs-on: docker runs-on: docker
container: nikolaik/python-nodejs:python3.11-nodejs21 container: nikolaik/python-nodejs:python3.11-nodejs21
steps: steps:
@ -12,9 +12,26 @@ jobs:
- name: Install packages - name: Install packages
run: | run: |
pip install -e . -q pip install -e . -q
python -m pip list --format=columns --disable-pip-version-check
pip install pylint~=2.17.7 --disable-pip-version-check -q pip install pylint~=2.17.7 --disable-pip-version-check -q
python -m pip list --format=columns --disable-pip-version-check
- name: Run pylint - name: Run pylint
run: | run: |
pylint --version pylint --version
pylint **/*.py --exit-zero --rc-file pyproject.toml pylint **/*.py --exit-zero --rc-file pyproject.toml
typing-mypy:
runs-on: docker
container: nikolaik/python-nodejs:python3.11-nodejs21
steps:
- name: Checkout source code
uses: https://code.forgejo.org/actions/checkout@v3
- name: Install packages
run: |
pip install -e . -q
pip install mypy~=1.10.1 --disable-pip-version-check -q
mypy --install-types
python -m pip list --format=columns --disable-pip-version-check
- name: Run mypy
run: |
mypy --version
mypy .

View file

@ -1,10 +1,10 @@
from urllib.parse import urlparse from urllib.parse import urlparse
from getpass import getpass from getpass import getpass
from ...models.parser import Credentials from ...models import Credentials
from ...service import storage from ...service import storage
from ..utils import stack_formatter, status_formatter, generic_formatter, get_credential_parser
from ...service.communicate import DockgeConnection from ...service.communicate import DockgeConnection
from ..utils import stack_formatter, status_formatter, generic_formatter, get_credential_parser
class ExecutionCommands(): class ExecutionCommands():
@staticmethod @staticmethod

View file

@ -1,88 +1,90 @@
from typing import List
from ...models import Command
from .bindings import ExecutionCommands from .bindings import ExecutionCommands
command_mappings = [ mapping: List[Command] = [
{ Command(
"command": "host", cmd="host",
"description": "Sets and gets the URI of the dockge instance. Remove any unnecessary subdomains/protocols from the URI", description="Sets and gets the URI of the dockge instance. Remove any unnecessary subdomains/protocols from the URI",
"args": 1, args=1,
"optional": True, optional=True,
"binding": ExecutionCommands.host bind=ExecutionCommands.host
}, ),
{ Command(
"command": "login", cmd="login",
"description": "Logs into a given dockge account, either with an interactive dialogue or by passing --user and --password", description="Logs into a given dockge account, either with an interactive dialogue or by passing --user and --password",
"args": 2, args=2,
"optional": True, optional=True,
"binding": ExecutionCommands.login bind=ExecutionCommands.login
}, ),
{ Command(
"command": "logout", cmd="logout",
"description": "Removes the credentials from the local storage.", description="Removes the credentials from the local storage.",
"args": 0, args=0,
"optional": False, optional=False,
"binding": ExecutionCommands.logout bind=ExecutionCommands.logout
}, ),
{ Command(
"command": "list", cmd="list",
"description": "Lists all available stacks with their status", description="Lists all available stacks with their status",
"args": 0, args=0,
"optional": False, optional=False,
"binding": ExecutionCommands.list bind=ExecutionCommands.list
}, ),
{ Command(
"command": "status", cmd="status",
"description": "Returns the status of one stack", description="Returns the status of one stack",
"args": 1, args=1,
"optional": False, optional=False,
"binding": ExecutionCommands.status bind=ExecutionCommands.status
}, ),
{ Command(
"command": "restart", cmd="restart",
"description": "Restarts a given stack", description="Restarts a given stack",
"args": 1, args=1,
"optional": False, optional=False,
"binding": ExecutionCommands.restart bind=ExecutionCommands.restart
}, ),
{ Command(
"command": "start", cmd="start",
"description": "Starts a given stack", description="Starts a given stack",
"args": 1, args=1,
"optional": False, optional=False,
"binding": ExecutionCommands.start bind=ExecutionCommands.start
}, ),
{ Command(
"command": "stop", cmd="stop",
"description": "Stops a given stack", description="Stops a given stack",
"args": 1, args=1,
"optional": False, optional=False,
"binding": ExecutionCommands.stop bind=ExecutionCommands.stop
}, ),
{ Command(
"command": "down", cmd="down",
"description": "Stop & Downs a given stack", description="Stop & Downs a given stack",
"args": 1, args=1,
"optional": False, optional=False,
"binding": ExecutionCommands.down bind=ExecutionCommands.down
}, ),
{ Command(
"command": "update", cmd="update",
"description": "Updates a stack", description="Updates a stack",
"args": 1, args=1,
"optional": False, optional=False,
"binding": ExecutionCommands.update bind=ExecutionCommands.update
}, ),
{ Command(
"command": "exit", cmd="exit",
"description": "Exits the CLI - this will reset all settings, including credentials and host", description="Exits the CLI - this will reset all settings, including credentials and host",
"args": 0, args=0,
"optional": False, optional=False,
"binding": ExecutionCommands.exit bind=ExecutionCommands.exit
}, ),
{ Command(
"command": "help", cmd="help",
"description": "Displays helping hints for commands", description="Displays helping hints for commands",
"args": 1, args=1,
"optional": True, optional=True,
"binding": ExecutionCommands.help bind=ExecutionCommands.help
} )
] ]

View file

@ -1,17 +1,7 @@
from typing import List, Callable from ...models import Command
from pydantic import BaseModel from .descriptors import mapping
from .descriptors import command_mappings
class Command(BaseModel):
command: str
description: str
args: int
optional: bool
binding: Callable
commands: dict[str, Command] = {} commands: dict[str, Command] = {}
descriptors: List[dict[str, object]] = command_mappings
for descriptor in descriptors: for descriptor in mapping:
c = Command(**descriptor) # type: ignore commands.update({ descriptor.cmd: descriptor })
commands.update({ c.command: c })

View file

@ -2,7 +2,7 @@ import argparse
import sys import sys
from .. import __version__ from .. import __version__
from ..models.parser import Arguments from ..models import Arguments
from .commandprovider.factory import commands from .commandprovider.factory import commands
def parse_arguments(): def parse_arguments():

View file

@ -1 +1,3 @@
from .codes import StackStatus from .codes import StackStatus
from .commands import Command
from .parser import Arguments, Credentials

View file

@ -0,0 +1,9 @@
from typing import Callable
from pydantic import BaseModel
class Command(BaseModel):
cmd: str
bind: Callable
args: int
optional: bool
description: str

View file

@ -34,6 +34,15 @@ include = ["dockge_cli*"]
[tool.pylint."MAIN"] [tool.pylint."MAIN"]
disable = [ "line-too-long", "missing-module-docstring", "missing-function-docstring", "missing-class-docstring" ] disable = [ "line-too-long", "missing-module-docstring", "missing-function-docstring", "missing-class-docstring" ]
[tool.mypy]
python_version = "3.11"
warn_return_any = true
warn_unused_configs = true
[[tool.mypy.overrides]]
module = 'socketio.*'
ignore_missing_imports = true
[build-system] [build-system]
requires = ["setuptools >= 61.0"] requires = ["setuptools >= 61.0"]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"