Refactor, typing improvements, ci improvements
This commit is contained in:
parent
d3e5d4ae56
commit
e44fd8a7a5
9 changed files with 141 additions and 107 deletions
|
@ -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:
|
||||
|
|
|
@ -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 .
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
)
|
||||
]
|
||||
|
|
|
@ -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 })
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
from .codes import StackStatus
|
||||
from .commands import Command
|
||||
from .parser import Arguments, Credentials
|
||||
|
|
9
dockge_cli/models/commands.py
Normal file
9
dockge_cli/models/commands.py
Normal 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
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue