Skip to content

Commit

Permalink
Lint and unit tests workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
themylogin committed Jan 23, 2025
1 parent b4cae3b commit 97d79fe
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 98 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: flake8

on:
pull_request:
types:
- 'synchronize'
- 'opened'

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Analyze the code with flake8
run: flake8 .
36 changes: 36 additions & 0 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
container:
image: ghcr.io/truenas/middleware:master

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Deploy
run: |
/usr/bin/install-dev-tools
- name: Test
run:
pytest-3 -v --disable-pytest-warnings tests/
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

30 changes: 0 additions & 30 deletions .travis/flake8.sh

This file was deleted.

6 changes: 5 additions & 1 deletion midcli/command/common_syntax/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ class ParseError(Exception):
json = jsonValue.setName("json")

baseValue = (oct | hex | json | string).setName("baseValue")
baseValueList = (baseValue + pp.OneOrMore((pp.Suppress(",") + baseValue).leaveWhitespace())).leaveWhitespace().setName("baseValueList")
baseValueList = (
(baseValue + pp.OneOrMore((pp.Suppress(",") + baseValue).leaveWhitespace())).
leaveWhitespace().
setName("baseValueList")
)

value = (baseValueList | baseValue).setName("value")

Expand Down
4 changes: 3 additions & 1 deletion midcli/command/generic_call/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def _call_args(self, args, kwargs):
if args_dict:
for i in range(0, max(args_dict.keys()) + 1):
if i not in args_dict:
raise CallArgsError(f"Missing positional argument {i + 1} ({self.method['accepts'][i]['_name_']})")
raise CallArgsError(
f"Missing positional argument {i + 1} ({self.method['accepts'][i]['_name_']})"
)

args.append(args_dict[i])

Expand Down
2 changes: 1 addition & 1 deletion midcli/command/override/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .utils import remove_fields, rows_processor

from truenas_api_client import ClientException, ValidationErrors
from truenas_api_client import ValidationErrors

from midcli.command.generic_call import GenericCallCommand
from midcli.command.query.command import QueryCommand
Expand Down
1 change: 0 additions & 1 deletion midcli/display_mode/mode/polymorphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ def display_object(self, object):

def display_scalar(self, scalar):
raise NotImplementedError

1 change: 0 additions & 1 deletion midcli/editor/edit_yaml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding=utf-8 -*-
import logging
import sys

from prompt_toolkit.application import get_app
import yaml
Expand Down
4 changes: 2 additions & 2 deletions midcli/gui/base/common/menu_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def _get_text_fragments(self) -> StyleAndTextTuples:

def handler(mouse_event: MouseEvent) -> None:
if (
self.handler is not None
and mouse_event.event_type == MouseEventType.MOUSE_UP
self.handler is not None and
mouse_event.event_type == MouseEventType.MOUSE_UP
):
self.handler()

Expand Down
4 changes: 2 additions & 2 deletions midcli/gui/base/list/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def __init__(self, context):
)
)
)
actions.append(f"<r> to refresh")
actions.append("<r> to refresh")
self.kb.add("r")(lambda event: event.app.exit(AppResult(app_factory=lambda: self.__class__(self.context))))
actions.append(f"<q> to quit")
actions.append("<q> to quit")
self.kb.add("q")(lambda event: event.app.exit(None))

help_label = Label("\n" + "\n".join(textwrap.wrap(f"Press {', '.join(actions)}.", width=60)))
Expand Down
2 changes: 1 addition & 1 deletion midcli/gui/base/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import itertools
import logging

from prompt_toolkit.filters import has_completions, has_focus
from prompt_toolkit.filters import has_focus
from prompt_toolkit.formatted_text import FormattedText
from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previous
from prompt_toolkit.key_binding.key_bindings import KeyBindings
Expand Down
2 changes: 1 addition & 1 deletion midcli/gui/network/interface/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _setup_app(self):

self.kb.add("a")(lambda event: event.app.exit(AppResult(app_factory=apply_app_factory)))
self.kb.add("p")(lambda event: event.app.exit(AppResult(app_factory=persist_app_factory)))

def apply_app_factory():
print("Applying network interface changes...")
with self.context.get_client() as c:
Expand Down
2 changes: 1 addition & 1 deletion midcli/menu/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def manage_local_administrator_password(context):
print("1) Administrative user (admin)")
print("2) Root user (not recommended)")
print()
number = input(f"Enter an option from 1-2: ")
number = input("Enter an option from 1-2: ")
try:
username = {"1": "admin", "2": "root"}[number]
except KeyError:
Expand Down
40 changes: 2 additions & 38 deletions midcli/utils/prompt_toolkit/widgets/base.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,33 @@
# -*- coding=utf-8 -*-
from functools import partial
import logging
from typing import Callable, Generic, List, Optional, Sequence, Tuple, TypeVar, Union
from typing import Generic, List, Optional, Sequence, Tuple, TypeVar

from prompt_toolkit.application.current import get_app
from prompt_toolkit.auto_suggest import AutoSuggest, DynamicAutoSuggest
from prompt_toolkit.buffer import Buffer, BufferAcceptHandler
from prompt_toolkit.completion import Completer, DynamicCompleter
from prompt_toolkit.document import Document
from prompt_toolkit.filters import (
Condition,
FilterOrBool,
has_focus,
is_done,
is_true,
to_filter,
)
from prompt_toolkit.formatted_text import (
AnyFormattedText,
StyleAndTextTuples,
Template,
to_formatted_text,
)
from prompt_toolkit.formatted_text.utils import fragment_list_to_text
from prompt_toolkit.history import History
from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previous
from prompt_toolkit.key_binding.key_bindings import KeyBindings
from prompt_toolkit.key_binding.key_processor import KeyPressEvent
from prompt_toolkit.keys import Keys
from prompt_toolkit.layout.containers import (
AnyContainer,
ConditionalContainer,
Container,
DynamicContainer,
Float,
FloatContainer,
HSplit,
VSplit,
Window,
WindowAlign,
)
from prompt_toolkit.layout.controls import (
BufferControl,
FormattedTextControl,
GetLinePrefixCallable,
)
from prompt_toolkit.layout.dimension import AnyDimension
from prompt_toolkit.layout.dimension import Dimension as D
from prompt_toolkit.layout.dimension import to_dimension
from prompt_toolkit.layout.margins import (
ConditionalMargin,
NumberedMargin,
ScrollbarMargin,
)
from prompt_toolkit.layout.processors import (
AppendAutoSuggestion,
BeforeInput,
ConditionalProcessor,
PasswordProcessor,
Processor,
)
from prompt_toolkit.lexers import DynamicLexer, Lexer
from prompt_toolkit.mouse_events import MouseEvent, MouseEventType
from prompt_toolkit.utils import get_cwidth
from prompt_toolkit.validation import DynamicValidator, Validator

from midcli.utils.lang import undefined

Expand Down Expand Up @@ -160,7 +124,7 @@ def _click(event: E) -> None:
def _find(event: E) -> None:
# We first check values after the selected value, then all values.
values = list(self.values)
for value in values[self._selected_index + 1 :] + values:
for value in values[self._selected_index + 1:] + values:
text = fragment_list_to_text(to_formatted_text(value[1])).lower()

if text.startswith(event.data.lower()):
Expand Down
8 changes: 4 additions & 4 deletions midcli/utils/pyparsing/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#
import json

import pyparsing as pp
from pyparsing import pyparsing_common as ppc

json_bnf = """
object
{ members }
Expand All @@ -35,9 +38,6 @@
null
"""

import pyparsing as pp
from pyparsing import pyparsing_common as ppc


def make_keyword(kwd_str, kwd_value):
return pp.Keyword(kwd_str).setParseAction(pp.replaceWith(kwd_value))
Expand All @@ -49,7 +49,7 @@ def make_keyword(kwd_str, kwd_value):

LBRACK, RBRACK, LBRACE, RBRACE, COLON = map(pp.Suppress, "[]{}:")

jsonString = pp.dblQuotedString().setParseAction(lambda s, l, t: json.loads(t[0]))
jsonString = pp.dblQuotedString().setParseAction(lambda _, __, t: json.loads(t[0]))
jsonNumber = ppc.number()

jsonObject = pp.Forward().setName("jsonObject")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import find_packages, setup

try:
import fastentrypoints
import fastentrypoints # noqa
except ImportError:
import sys
print("fastentrypoints module not found. entry points will be slower.", file=sys.stderr)
Expand Down
4 changes: 1 addition & 3 deletions tests/command/common_syntax/test_common_syntax_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
("1 null", CommonSyntaxCommandArguments([1, None], {})),
("1 [1, 2, 3]", CommonSyntaxCommandArguments([1, [1, 2, 3]], {})),
("1 1,2,3", CommonSyntaxCommandArguments([1, [1, 2, 3]], {})),
("1 1,2, 3", "Expected end of text, found '1'\n"
" 1 1,2, 3\n"
" ^"),
("1 1,2, 3", CommonSyntaxCommandArguments([1, [1, 2, 3]], {})),
("1 \"a,b\",\"c, d\"", CommonSyntaxCommandArguments([1, ["a,b", "c, d"]], {})),
("1 {\"key\": \"value\"} 2", CommonSyntaxCommandArguments([1, {"key": "value"}, 2], {})),
("1 {\"key\": [\"nested\", {\"value\": 2}]} 3", CommonSyntaxCommandArguments([1, {"key": ["nested", {"value": 2}]}, 3], {})),
Expand Down
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
exclude = integration_tests/*,tests/*
ignore = F403,F405,W504
max-line-length = 120

0 comments on commit 97d79fe

Please sign in to comment.