Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isort linting #138

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@ jobs:
with:
options: "--check"
src: "."

isort:
runs-on: ubuntu-latest
name: isort linting
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install isort
run: pip install isort
- name: Run isort
run: isort --check-only .
11 changes: 3 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from __future__ import absolute_import
from __future__ import print_function
from __future__ import absolute_import, print_function

import io
import re
from glob import glob
from os.path import basename
from os.path import dirname
from os.path import join
from os.path import splitext
from os.path import basename, dirname, join, splitext

from setuptools import find_packages
from setuptools import setup
from setuptools import find_packages, setup


def read(*names, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions src/tirith/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
import json
import logging
import re
import yaml
from types import CodeType
from typing import Any, Dict, List, Optional, Tuple

from typing import Any, Dict, List, Tuple, Optional
import yaml

from tirith.providers.common import ProviderError

from ..providers import PROVIDERS_DICT
from .evaluators import EVALUATORS_DICT



logger = logging.getLogger(__name__)


Expand Down
8 changes: 4 additions & 4 deletions src/tirith/core/evaluators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
from .contained_in import ContainedIn
from .contains import Contains
from .equals import Equals
from .greater_than_equal_to import GreaterThanEqualTo
from .greater_than import GreaterThan
from .greater_than_equal_to import GreaterThanEqualTo
from .is_empty import IsEmpty
from .is_not_empty import IsNotEmpty
from .less_than_equal_to import LessThanEqualTo
from .less_than import LessThan
from .regex_match import RegexMatch
from .not_equals import NotEquals
from .less_than_equal_to import LessThanEqualTo
from .not_contained_in import NotContainedIn
from .not_contains import NotContains
from .not_equals import NotEquals
from .regex_match import RegexMatch

EVALUATORS_DICT: Dict[str, Type[BaseEvaluator]] = {
"ContainedIn": ContainedIn,
Expand Down
3 changes: 2 additions & 1 deletion src/tirith/core/evaluators/contained_in.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging

from .base_evaluator import BaseEvaluator
from tirith.utils import sort_collections


logger = logging.getLogger(__name__)


# Checks if :attr: `evaluator_input` is contained in :attr:`evaluator_data`.

# Args:
Expand Down
2 changes: 1 addition & 1 deletion src/tirith/core/evaluators/contains.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logging

from .base_evaluator import BaseEvaluator
from tirith.utils import sort_collections


logger = logging.getLogger(__name__)


# Checks if :attr: `evaluator_input` is contained in :attr:`evaluator_data`.

# Args:
Expand Down
3 changes: 2 additions & 1 deletion src/tirith/core/evaluators/equals.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging

from .base_evaluator import BaseEvaluator
from tirith.utils import sort_collections


logger = logging.getLogger(__name__)


# Checks if :attr:`value` is equal to :attr:`other`. Automatically casts values to the same type if possible.

# Args:
Expand Down
1 change: 0 additions & 1 deletion src/tirith/core/evaluators/greater_than.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .base_evaluator import BaseEvaluator


# Checks if :attr:`value` is more then :attr:`other`. Automatically casts values to the same type if possible.

# Args:
Expand Down
3 changes: 2 additions & 1 deletion src/tirith/core/evaluators/not_contained_in.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import logging

from .base_evaluator import BaseEvaluator
from tirith.utils import sort_collections



logger = logging.getLogger(__name__)


# Checks if :attr: `evaluator_input` is not contained in :attr:`evaluator_data`.

# Args:
Expand Down
3 changes: 2 additions & 1 deletion src/tirith/core/evaluators/not_contains.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import logging

from .base_evaluator import BaseEvaluator
from tirith.utils import sort_collections



logger = logging.getLogger(__name__)


# Checks if :attr: `evaluator_input` does not contain :attr:`evaluator_data`.

# Args:
Expand Down
3 changes: 2 additions & 1 deletion src/tirith/core/evaluators/not_equals.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging

from .base_evaluator import BaseEvaluator
from tirith.utils import sort_collections


logger = logging.getLogger(__name__)


# Checks if :attr:`value` is not equal to :attr:`other`. Automatically casts values to the same type if possible.

# Args:
Expand Down
3 changes: 2 additions & 1 deletion src/tirith/core/evaluators/regex_match.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .base_evaluator import BaseEvaluator
import re

from .base_evaluator import BaseEvaluator


class RegexMatch(BaseEvaluator):
def evaluate(self, evaluator_input, evaluator_data):
Expand Down
6 changes: 3 additions & 3 deletions src/tirith/providers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Callable, Dict

from .terraform_plan.handler import *
from .infracost import provide as infracost_provider
from .sg_workflow import provide as sg_wf_provider
from .terraform_plan import provide as terraform_provider
from .json import provide as json_provider
from .kubernetes import provide as kubernetes_provider
from .sg_workflow import provide as sg_wf_provider
from .terraform_plan import provide as terraform_provider
from .terraform_plan.handler import *

PROVIDERS_DICT: Dict[str, Callable] = {
"stackguardian/terraform_plan": terraform_provider,
Expand Down
5 changes: 3 additions & 2 deletions src/tirith/providers/json/handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Callable, Dict, List

import pydash

from typing import Callable, Dict, List
from ..common import create_result_dict, ProviderError
from ..common import ProviderError, create_result_dict


class PydashPathNotFound:
Expand Down
5 changes: 3 additions & 2 deletions src/tirith/providers/kubernetes/handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Callable, Dict, List

import pydash

from typing import Callable, Dict, List
from ..common import create_result_dict, ProviderError
from ..common import ProviderError, create_result_dict


class PydashPathNotFound:
Expand Down
1 change: 1 addition & 0 deletions src/tirith/providers/terraform_plan/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# input->(list ["a.b","c", "d"],value of resource)
# returns->[any, any, any]
from typing import Iterable, Tuple

import pydash

from ..common import ProviderError
Expand Down
2 changes: 1 addition & 1 deletion tests/core/evaluators/test_contained_in.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from tirith.core.evaluators import ContainedIn
from pytest import mark

from tirith.core.evaluators import ContainedIn

checks_passing = [
("a", ["a", "b", "c", "d"]),
Expand Down
2 changes: 1 addition & 1 deletion tests/core/evaluators/test_contains.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from tirith.core.evaluators import Contains
from pytest import mark

from tirith.core.evaluators import Contains

checks_passing = [
(["a", "b", "c", "d"], "a"),
Expand Down
3 changes: 2 additions & 1 deletion tests/core/evaluators/test_equals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tirith.core.evaluators import Equals
from pytest import mark

from tirith.core.evaluators import Equals

checks_passing = [({1, 2, 3, 4}, {1, 2, 3, 4}), ([2, 4, 3], [2, 3, 4])]

checks_failing = [({1, 2, 3, 4}, {2, 3, 4}), ({2, 3, 4}, [2, 3, 4])]
Expand Down
3 changes: 2 additions & 1 deletion tests/core/evaluators/test_greater_than.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tirith.core.evaluators import GreaterThan
from pytest import mark

from tirith.core.evaluators import GreaterThan

evaluator_input1 = 5
evaluator_data1 = 2

Expand Down
3 changes: 2 additions & 1 deletion tests/core/evaluators/test_greater_than_equal_to.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tirith.core.evaluators import GreaterThanEqualTo
from pytest import mark

from tirith.core.evaluators import GreaterThanEqualTo

evaluator_input1 = 27
evaluator_data1 = 26

Expand Down
3 changes: 2 additions & 1 deletion tests/core/evaluators/test_is_empty.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tirith.core.evaluators import IsEmpty
from pytest import mark

from tirith.core.evaluators import IsEmpty

checks_passing = ("", None, [], dict())
checks_failing = ("stackguardian", 1, [None], dict(a=1))

Expand Down
3 changes: 2 additions & 1 deletion tests/core/evaluators/test_is_not_empty.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tirith.core.evaluators import IsNotEmpty
from pytest import mark

from tirith.core.evaluators import IsNotEmpty

evaluator_input1 = "abc"
evaluator_input2 = ""

Expand Down
3 changes: 2 additions & 1 deletion tests/core/evaluators/test_less_than.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tirith.core.evaluators import LessThan
from pytest import mark

from tirith.core.evaluators import LessThan

evaluator_input1 = 5
evaluator_data1 = 10

Expand Down
3 changes: 2 additions & 1 deletion tests/core/evaluators/test_less_than_equal_to.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tirith.core.evaluators import LessThanEqualTo
from pytest import mark

from tirith.core.evaluators import LessThanEqualTo

evaluator_input1 = 26
evaluator_data1 = 27

Expand Down
2 changes: 1 addition & 1 deletion tests/core/evaluators/test_not_contained_in.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from tirith.core.evaluators import NotContainedIn
from pytest import mark

from tirith.core.evaluators import NotContainedIn

checks_failing = [
("a", ["a", "b", "c", "d"]),
Expand Down
2 changes: 1 addition & 1 deletion tests/core/evaluators/test_not_contains.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from tirith.core.evaluators import NotContains
from pytest import mark

from tirith.core.evaluators import NotContains

checks_failing = [
(["a", "b", "c", "d"], "a"),
Expand Down
3 changes: 2 additions & 1 deletion tests/core/evaluators/test_not_equals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tirith.core.evaluators import NotEquals
from pytest import mark

from tirith.core.evaluators import NotEquals

checks_failing = [({1, 2, 3, 4}, {1, 2, 3, 4}), ([2, 4, 3], [2, 3, 4])]

checks_passing = [({1, 2, 3, 4}, {2, 3, 4}), ({2, 3, 4}, [2, 3, 4])]
Expand Down
3 changes: 2 additions & 1 deletion tests/core/evaluators/test_regex_match.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tirith.core.evaluators import RegexMatch
from pytest import mark

from tirith.core.evaluators import RegexMatch

evaluator_data1 = "^(?=[a-zA-Z0-9._]{8,20}$)(?!.*[_.]{2})[^_.].*[^_.]$"
evaluator_input1 = "amitrakshar01"

Expand Down
1 change: 1 addition & 0 deletions tests/providers/infracost/tests_infracost.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os

import pytest

from tirith.providers.infracost import handler
Expand Down
2 changes: 2 additions & 0 deletions tests/providers/sg_workflow/tests_sg_workflow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os

import pytest

from tirith.providers.sg_workflow import handler
Expand All @@ -13,6 +14,7 @@ def load_terraform_plan_json(json_path):
input_data = load_terraform_plan_json("input.json")
import json
import os

import pytest

from tirith.providers.sg_workflow import handler
Expand Down
3 changes: 2 additions & 1 deletion tests/providers/terraform_plan/test_action.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tirith.providers.terraform_plan import handler
from utils import load_terraform_plan_json

from tirith.providers.terraform_plan import handler


def test_action_star_resource_type_should_include_every_resource_types():
provider_args_dict = {"operation_type": "action", "terraform_resource_type": "*"}
Expand Down
7 changes: 4 additions & 3 deletions tests/providers/terraform_plan/test_direct_references.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json
import os
import pytest
import shutil

from subprocess import Popen

import pytest
from utils import load_terraform_plan_json

from tirith.core.core import start_policy_evaluation_from_dict
from tirith.providers.terraform_plan import handler
from utils import load_terraform_plan_json


# TODO: Move these helper functions to a utils file
Expand Down
3 changes: 2 additions & 1 deletion tests/providers/terraform_plan/test_dot_star_attr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from tirith.providers.terraform_plan import handler
from pytest import mark

from tirith.providers.terraform_plan import handler

checks_passing = [
(
"a.*.b.c.*",
Expand Down
Loading
Loading