Skip to content

Commit

Permalink
Ordering imports (#190)
Browse files Browse the repository at this point in the history
* Add isort and Makefile cleanup

* Fix isort version

* Enable isort in CI

* Fix issues that isort found
  • Loading branch information
gouline authored Dec 6, 2023
1 parent 848c81d commit 7b797ca
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
- name: Formatting check (black)
run: make check-fmt

- name: Imports ordering check (isort)
run: make check-imports

- name: Lint Python check (pylint)
run: make check-lint-python

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- name: Formatting check (black)
run: make check-fmt

- name: Imports ordering check (isort)
run: make check-imports

- name: Lint Python check (pylint)
run: make check-lint-python

Expand Down
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
build: clean
python3 setup.py sdist bdist_wheel
.PHONY: build

clean:
rm -rf build dist
.PHONY: clean

requirements:
pip3 install -r requirements.txt
pip3 install -r requirements-test.txt
python3 -m pip install \
-r requirements.txt \
-r requirements-test.txt
.PHONY: requirements

fmt:
fix-fmt:
black .
.PHONY: fix-fmt

fix-imports:
isort .
.PHONY: fix-imports

fix: fix-fmt fix-imports
.PHONY: fix

check-fmt:
black --check .
.PHONY: check-fmt

check-imports:
isort --check .
.PHONY: check-imports

check-lint-python:
pylint dbtmetabase
.PHONY: check-lint-python
Expand Down Expand Up @@ -44,5 +59,6 @@ dist-upload: check
.PHONY: dist-upload

dev-install: build
pip3 uninstall -y dbt-metabase && pip3 install dist/dbt_metabase-*-py3-none-any.whl
python3 -m pip uninstall -y dbt-metabase \
&& python3 -m pip install dist/dbt_metabase-*-py3-none-any.whl
.PHONY: dev-install
8 changes: 4 additions & 4 deletions dbtmetabase/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging
import functools
from pathlib import Path
from typing import Iterable, Optional, Callable, Any, Dict
import logging
import os
from pathlib import Path
from typing import Any, Callable, Dict, Iterable, Optional

import click
import yaml

from .logger import logging as package_logger
from .models.interface import MetabaseInterface, DbtInterface
from .models.interface import DbtInterface, MetabaseInterface
from .utils import get_version, load_config

__all__ = ["MetabaseInterface", "DbtInterface"]
Expand Down
3 changes: 1 addition & 2 deletions dbtmetabase/logger/logging.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import logging
from logging.handlers import RotatingFileHandler
from functools import lru_cache
from logging.handlers import RotatingFileHandler
from pathlib import Path
from typing import Optional, Union

from rich.logging import RichHandler


# Log File Format
LOG_FILE_FORMAT = "%(asctime)s — %(name)s — %(levelname)s — %(message)s"

Expand Down
3 changes: 2 additions & 1 deletion dbtmetabase/models/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from os.path import expandvars
from typing import Iterable, List, MutableMapping, Optional, Tuple, Union

from requests.adapters import HTTPAdapter

from ..metabase import MetabaseClient
from ..parsers.dbt import DbtReader
from ..parsers.dbt_folder import DbtFolderReader
Expand All @@ -12,7 +14,6 @@
NoMetabaseCredentialsSupplied,
)
from .metabase import MetabaseModel
from requests.adapters import HTTPAdapter


class MetabaseInterface:
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ write_to = "dbtmetabase/_version.py"

[tool.black]
line-length = 88
target-version = ['py36', 'py37', 'py38']
target-version = ["py36", "py37", "py38"]
include = '\.pyi?$'

[tool.isort]
profile = "black"
src_paths = ["dbtmetabase", "tests", "setup.py"]

[tool.mypy]
python_version = "3.8"
ignore_missing_imports = true
Expand Down
1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ types-requests
types-PyYAML
black>=22.8.0
restructuredtext-lint>=1.4.0
isort>=5.10.1
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/usr/bin/env python3

import sys
from setuptools import setup, find_packages

from setuptools import find_packages, setup

if sys.version_info < (3, 6):
raise ValueError("Requires Python 3.6+")


def requires_from_file(filename: str) -> list:
with open(filename, "r") as f:
with open(filename, "r", encoding="utf-8") as f:
return [x.strip() for x in f if x.strip()]


with open("README.rst", "r") as f:
with open("README.rst", "r", encoding="utf-8") as f:
readme = f.read()

setup(
Expand Down
5 changes: 1 addition & 4 deletions tests/test_dbt_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

from dbtmetabase.models.interface import DbtInterface
from dbtmetabase.models.metabase import ModelType, NullValue
from dbtmetabase.parsers.dbt_folder import (
MetabaseModel,
MetabaseColumn,
)
from dbtmetabase.parsers.dbt_folder import MetabaseColumn, MetabaseModel


class TestDbtFolderReader(unittest.TestCase):
Expand Down
7 changes: 2 additions & 5 deletions tests/test_metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
import logging
import os
import unittest

import yaml

from dbtmetabase.metabase import MetabaseClient
from dbtmetabase.models.metabase import (
MetabaseModel,
MetabaseColumn,
ModelType,
)
from dbtmetabase.models.metabase import MetabaseColumn, MetabaseModel, ModelType

MODELS = [
MetabaseModel(
Expand Down
6 changes: 1 addition & 5 deletions tests/utils_mb_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import os

from dbtmetabase.metabase import MetabaseClient
from dbtmetabase.models.metabase import (
MetabaseModel,
MetabaseColumn,
ModelType,
)
from dbtmetabase.models.metabase import MetabaseColumn, MetabaseModel, ModelType

mbc = MetabaseClient(
host="localhost:3000",
Expand Down

0 comments on commit 7b797ca

Please sign in to comment.