Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

Commit

Permalink
Feature: isort invoke command (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
bossjones committed May 24, 2020
1 parent 84f9215 commit 04d29f1
Show file tree
Hide file tree
Showing 196 changed files with 1,219 additions and 1,505 deletions.
38 changes: 33 additions & 5 deletions lint-configs-python/python/pylintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@

[MASTER]
reports=no
output-format=colorized
# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
# number of processors available to use.
# NOTE: Use a conservative default here; 2 should speed up most setups and not hurt
# NOTE: any too bad. Override on command line as appropriate.
jobs=2

# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
# SOURCE: https://github.com/home-assistant/core/blob/dev/pylintrc
# load-plugins=pylint_strict_informational

# Pickle collected data for later comparisons. default yes
# persistent=no
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
# extension-pkg-whitelist=ciso8601

[MESSAGES CONTROL]
# source: https://github.com/home-assistant/home-assistant/blob/dev/pylintrc
Expand All @@ -24,7 +39,7 @@ output-format=colorized
# cyclic-import,
# abstract-class-little-used,
# abstract-class-not-used,
# unused-argument,
# unused-argument - generic callbacks and setup methods create a lot of warnings
# global-statement,
# redefined-variable-type,
# too-many-arguments,
Expand All @@ -35,9 +50,22 @@ output-format=colorized
# too-many-return-statements,
# too-many-statements,
# too-few-public-methods,
# abstract-method
# abstract-method,
# wrong-import-order - isort guards this

disable=C0103,C0330,E0211,E0213,W0221,E0239,E0603,E0604,E0611,E1002,E1101,E1103,F0220,F0401,I0011,R0201,R0801,R0924,W0142,W0201,W0212,W0232,W0613,W0633,W0703,W1001,W1202,C0330,I0011,C0111,W0232,W0622,W0621,C0122,W0120,E0632,R1705,C0411

[REPORTS]
# reports=no
# output-format=colorized

disable=C0103,C0330,E0211,E0213,W0221,E0239,E0603,E0604,E0611,E1002,E1101,E1103,F0220,F0401,I0011,R0201,R0801,R0924,W0142,W0201,W0212,W0232,W0613,W0633,W0703,W1001,W1202,C0330,I0011,C0111,W0232,W0622,W0621,C0122,W0120,E0632,R1705
# Set the output format. Available formats are text, parseable, colorized, json
# and msvs (visual studio). You can also give a reporter class, e.g.
# mypackage.mymodule.MyReporterClass.
output-format=text

# Tells whether to display a full report or only the messages.
reports=no

[BASIC]
# Good variable names which should always be accepted, separated by a comma
Expand Down
13 changes: 11 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ mock_use_standalone_module = False
# https://github.com/timothycrosley/isort
# https://github.com/timothycrosley/isort/wiki/isort-Settings
# splits long import on multiple lines indented by 4 spaces
multi_line_output = 4
# An integer that represents how you want imports to be displayed if they're long enough to span multiple lines. A full definition of all possible modes can be found here(https://github.com/timothycrosley/isort#multi-line-output-modes).
# NOTE: 3 means Vertical Hanging Indent
multi_line_output = 3
indent = " "
# by default isort don't check module indexes
not_skip = __init__.py
Expand All @@ -239,7 +241,14 @@ force_sort_within_sections = true
# typing is stdlib on py35 but 3rd party on py34, let it hang in between
known_inbetweens = typing
sections = FUTURE,STDLIB,INBETWEENS,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

# Will set isort to automatically add a trailing comma to the end of from imports.
include_trailing_comma = True
# Force from imports to be grid wrapped regardless of line length, where the value given is the number of imports allowed before wrapping occurs.
force_grid_wrap = 0
# If set to true - isort will combine as imports on the same line within for import statements. By default isort forces all as imports to display on their own lines.
combine_as_imports = True
# An integer that represents the longest line-length you want a single import to take. Defaults to 79.
line_length = 88

# for reformatting code with yapf
[yapf]
Expand Down
88 changes: 79 additions & 9 deletions tasks/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def coverage_clean(ctx, loc="local", verbose=0, cleanup=False):


@task
def pylint(ctx, loc="local", tests=False):
def pylint(ctx, loc="local", tests=False, everything=False):
"""
pylint ultron8 folder
Usage: inv ci.pylint
Expand All @@ -95,6 +95,8 @@ def pylint(ctx, loc="local", tests=False):
ctx.run(
"pylint --disable=all --enable=F,E --rcfile ./lint-configs-python/python/pylintrc tests"
)
elif everything:
ctx.run("pylint --rcfile ./lint-configs-python/python/pylintrc tests")
else:
ctx.run(
"pylint --disable=all --enable=F,E --rcfile ./lint-configs-python/python/pylintrc ultron8"
Expand Down Expand Up @@ -148,10 +150,17 @@ def black(ctx, loc="local", check=True, debug=False, verbose=0):
ctx.run(_cmd)


@task
def isort(ctx, loc="local", check=True, debug=False):
@task(incrementable=["verbose"])
def isort(
ctx, loc="local", check=False, dry_run=False, verbose=0, apply=False, diff=False
):
"""
isort ultron8 module
isort ultron8 module. Some of the arguments were taken from the starlette contrib scripts. Tries to align w/ black to prevent having to reformat multiple times.
To check mode only(does not make changes permenantly):
Usage: inv ci.isort --check -vvv
Simply display command we would run:
Usage: inv ci.isort --check --dry-run -vvv
"""
env = get_compose_env(ctx, loc=loc)

Expand All @@ -162,14 +171,33 @@ def isort(ctx, loc="local", check=True, debug=False):
for k, v in env.items():
ctx.config["run"]["env"][k] = v

_cmd = ""
_cmd = "isort --recursive"

if check:
_cmd = "isort --recursive --check-only --diff --verbose ultron8 tests"
else:
_cmd = "isort --recursive --diff --verbose ultron8 tests"
_cmd += " --check-only"

ctx.run(_cmd)
if diff:
_cmd += " --diff"

if verbose >= 2:
_cmd += " --verbose"

if apply:
_cmd += " --apply"

_cmd += " ultron8 tests"

if verbose >= 1:
msg = "{}".format(_cmd)
click.secho(msg, fg=COLOR_SUCCESS)

if dry_run:
click.secho(
"[isort] DRY RUN mode enabled, not executing command: {}".format(_cmd),
fg=COLOR_CAUTION,
)
else:
ctx.run(_cmd)


@task
Expand Down Expand Up @@ -516,6 +544,48 @@ def monkeytype(
ctx.run(_cmd_apply)


def autoflake(
ctx, loc="local", verbose=0, check=False, dry_run=False,
):
"""
Use autoflake to remove unused imports, recursively, remove unused variables, and exclude __init__.py
To run autoflake in check only mode:
Usage: inv ci.autoflake --check -vvv
To run autoflake in check only mode(dry-run):
Usage: inv ci.autoflake --check -vvv --dry-run
"""
env = get_compose_env(ctx, loc=loc)

# Only display result
ctx.config["run"]["echo"] = True

# Override run commands' env variables one key at a time
for k, v in env.items():
ctx.config["run"]["env"][k] = v

_cmd = "autoflake"
_cmd += " --remove-all-unused-imports --recursive --remove-unused-variables"

if check:
_cmd += " --check"

_cmd += " ultron8"
_cmd += " --exclude=__init__.py"

if verbose >= 1:
msg = "{}".format(_cmd)
click.secho(msg, fg=COLOR_SUCCESS)

if dry_run:
click.secho(
"[autoflake] DRY RUN mode enabled, not executing command: {}".format(_cmd),
fg=COLOR_CAUTION,
)
else:
ctx.run(_cmd)


@task(
pre=[call(clean, loc="local"), call(verify_python_version, loc="local"),],
incrementable=["verbose"],
Expand Down
8 changes: 4 additions & 4 deletions tests/api/api_v1/test_endpoint_loggers.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging

from typing import Dict

import pytest
import requests
from starlette.testclient import TestClient

from tests.utils.utils import get_server_api
from ultron8.api import settings
import pytest

from typing import Dict
from ultron8.api.models.loggers import LoggerModel
from starlette.testclient import TestClient

logger = logging.getLogger(__name__)

Expand Down
11 changes: 5 additions & 6 deletions tests/api/api_v1/test_endpoint_version.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import logging

import requests
from typing import Dict

from tests.utils.utils import get_server_api
from ultron8.api import settings
import pytest
import requests
from starlette.testclient import TestClient

from typing import Dict

from tests.utils.utils import get_server_api
from ultron8 import __version__
from starlette.testclient import TestClient
from ultron8.api import settings

logger = logging.getLogger(__name__)

Expand Down
8 changes: 4 additions & 4 deletions tests/api/api_v1/test_login.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import logging

from typing import Dict

import pytest
import requests
from starlette.testclient import TestClient

from tests.utils.utils import get_server_api
from ultron8.api import settings
import pytest

from typing import Dict
from starlette.testclient import TestClient

logger = logging.getLogger(__name__)

Expand Down
28 changes: 12 additions & 16 deletions tests/api/api_v1/test_users.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import logging

import requests

from tests.utils.user import user_authentication_headers
from tests.utils.utils import get_server_api
from tests.utils.utils import random_lower_string, random_email
from ultron8.api import crud
from ultron8.api import settings

from ultron8.api.models.user import UserCreate
from ultron8.api.models.user import UserUpdate
import pytest
from ultron8.api.factories.users import _MakeRandomNormalUserFactory
from ultron8.api.api_v1.endpoints import users
from fastapi.encoders import jsonable_encoder
from sqlalchemy.orm import Session
from typing import Callable, Dict, Iterator

from typing import Callable, Iterator, Dict
from _pytest.fixtures import SubRequest
from _pytest.monkeypatch import MonkeyPatch
from fastapi.encoders import jsonable_encoder
import pytest
from pytest_mock.plugin import MockFixture
import requests
from sqlalchemy.orm import Session
from sqlalchemy.orm.session import Session
from starlette.testclient import TestClient

from tests.utils.user import user_authentication_headers
from tests.utils.utils import get_server_api, random_email, random_lower_string
from ultron8.api import crud, settings
from ultron8.api.api_v1.endpoints import users
from ultron8.api.factories.users import _MakeRandomNormalUserFactory
from ultron8.api.models.user import UserCreate, UserUpdate

logger = logging.getLogger(__name__)


Expand Down
29 changes: 11 additions & 18 deletions tests/api/crud/test_action.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import pytest
from fastapi.encoders import jsonable_encoder

from tests.utils.utils import random_lower_string
from ultron8.api import crud

from ultron8.api.models.action import RunnerTypeModel
from ultron8.api.models.action import ActionBase
from ultron8.api.models.action import ActionBaseInDB
from ultron8.api.models.action import ActionCreate
from ultron8.api.models.action import ActionUpdate

from ultron8.api.models.packs import PacksBase
from ultron8.api.models.packs import PacksBaseInDB
from ultron8.api.models.packs import PacksCreate
from ultron8.api.models.packs import PacksUpdate

from freezegun import freeze_time


import pytest
from sqlalchemy.orm import Session
from sqlalchemy.orm.session import Session

from tests.utils.utils import random_lower_string
from ultron8.api import crud
from ultron8.api.models.action import (
ActionBase,
ActionBaseInDB,
ActionCreate,
ActionUpdate,
RunnerTypeModel,
)
from ultron8.api.models.packs import PacksBase, PacksBaseInDB, PacksCreate, PacksUpdate

# def test_create_action():
# email = random_lower_string()
Expand Down
9 changes: 4 additions & 5 deletions tests/api/crud/test_item.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from sqlalchemy.orm import Session
from sqlalchemy.orm.session import Session

from tests.utils.user import create_random_user
from tests.utils.utils import random_lower_string
from ultron8.api import crud

from ultron8.api.models.item import ItemCreate
from ultron8.api.models.item import ItemUpdate
from sqlalchemy.orm import Session
from sqlalchemy.orm.session import Session
from ultron8.api.models.item import ItemCreate, ItemUpdate


def test_create_item(db: Session) -> None:
Expand Down
13 changes: 4 additions & 9 deletions tests/api/crud/test_packs.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import pytest
from fastapi.encoders import jsonable_encoder
from freezegun import freeze_time
import pytest
from sqlalchemy.orm.session import Session

from tests.utils.utils import random_lower_string
from ultron8.api import crud

from ultron8.api.models.packs import PacksBase
from ultron8.api.models.packs import PacksBaseInDB
from ultron8.api.models.packs import PacksCreate
from ultron8.api.models.packs import PacksUpdate

from freezegun import freeze_time
from sqlalchemy.orm.session import Session
from ultron8.api.models.packs import PacksBase, PacksBaseInDB, PacksCreate, PacksUpdate

# pack_linux = Packs(
# name="linux",
Expand Down

0 comments on commit 04d29f1

Please sign in to comment.