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]'
jobs:
backend-pylint:
lint-and-typing:
runs-on: docker
container: nikolaik/python-nodejs:python3.11-nodejs21
steps:
@ -15,15 +15,20 @@ jobs:
- name: Install packages
run: |
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
pip install pylint~=2.17.7 --disable-pip-version-check -q
- name: Run pylint
run: |
pylint --version
pylint **/*.py --exit-zero --rc-file pyproject.toml
- name: Run mypy
run: |
mypy --version
mypy .
build-artifacts:
needs: ["backend-pylint"]
needs: ["lint-and-typing"]
runs-on: docker
container: nikolaik/python-nodejs:python3.11-nodejs21
steps:

View file

@ -3,7 +3,7 @@ on:
branches: "**"
jobs:
backend-pylint:
pylint:
runs-on: docker
container: nikolaik/python-nodejs:python3.11-nodejs21
steps:
@ -12,9 +12,26 @@ jobs:
- name: Install packages
run: |
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
python -m pip list --format=columns --disable-pip-version-check
- name: Run pylint
run: |
pylint --version
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 getpass import getpass
from ...models.parser import Credentials
from ...models import Credentials
from ...service import storage
from ..utils import stack_formatter, status_formatter, generic_formatter, get_credential_parser
from ...service.communicate import DockgeConnection
from ..utils import stack_formatter, status_formatter, generic_formatter, get_credential_parser
class ExecutionCommands():
@staticmethod

View file

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

View file

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

View file

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

View file

@ -1 +1,3 @@
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"]
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]
requires = ["setuptools >= 61.0"]
build-backend = "setuptools.build_meta"