Skip to content

Commit

Permalink
Migrate to Ruff (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
gouline authored Aug 13, 2024
1 parent cc6e8b1 commit 134ab8c
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 53 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,8 @@ jobs:
- name: Build
run: make build

- 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
- name: Lint check (ruff)
run: make check-lint

- name: Type check (mypy)
run: make check-type
Expand Down
29 changes: 8 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,21 @@ requirements:
-r requirements-test.txt
.PHONY: requirements

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

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

fix: fix-fmt fix-imports
fix:
ruff format .
ruff check --fix .
.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
check-lint:
ruff format --check .
ruff check .
.PHONY: check-lint

check-type:
mypy dbtmetabase
.PHONY: check-type

check: check-fmt check-imports check-lint-python check-type
check: check-lint check-type
.PHONY: check

test:
Expand Down
6 changes: 3 additions & 3 deletions dbtmetabase/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def cli(ctx: click.Context, config_path: str):

config_path_expanded = Path(config_path).expanduser()
if config_path_expanded.exists():
with open(config_path_expanded, "r", encoding="utf-8") as f:
with open(config_path_expanded, encoding="utf-8") as f:
config = yaml.safe_load(f).get("config", {})
# Propagate common configs to all commands
common = {k: v for k, v in config.items() if k not in group.commands}
Expand Down Expand Up @@ -197,7 +197,7 @@ def wrapper(
skip_verify=skip_verify,
cert=cert,
http_timeout=http_timeout,
http_headers={k: v for k, v in http_headers},
http_headers=dict(http_headers),
),
**kwargs,
)
Expand Down Expand Up @@ -410,4 +410,4 @@ def exposures(

if __name__ == "__main__":
# Executed when running locally via python3 -m dbtmetabase
cli() # pylint: disable=no-value-for-parameter
cli()
4 changes: 2 additions & 2 deletions dbtmetabase/_exposures.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def __format_exposure(

if native_query:
# Format query into markdown code block
native_query = "\n".join(l for l in native_query.split("\n") if l.strip())
native_query = "\n".join(x for x in native_query.split("\n") if x.strip())
native_query = f"#### Query\n\n```\n{native_query}\n```\n\n"

metadata = (
Expand Down Expand Up @@ -393,7 +393,7 @@ def __write_exposures(
path = path.joinpath(*group[:-1]) / f"{group[-1]}.yml"
path.parent.mkdir(parents=True, exist_ok=True)

exps_unwrapped = map(lambda x: x["body"], exps)
exps_unwrapped = (x["body"] for x in exps)
exps_sorted = sorted(exps_unwrapped, key=itemgetter("name"))

with open(path, "w", encoding="utf-8") as f:
Expand Down
25 changes: 14 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ requires = ["setuptools>=60", "setuptools-scm"]
[tool.setuptools_scm]
version_file = "dbtmetabase/_version.py"

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

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

[tool.mypy]
check_untyped_defs = true
ignore_missing_imports = true
python_version = "3.8"

[tool.pylint.master]
disable = ["R", "C", "W0511"]
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"A", # flake8-builtins
"B", # flake8-bugbear
"C4", # flake8-comprehensions
]
ignore = [
"E501", # line-too-long
"F403", # undefined-local-with-import-star
]
4 changes: 1 addition & 3 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
pip>=23.3.1
build>=1.0.3
twine>=4.0.2
black>=23.11.0
isort>=5.12.0
pylint>=3.0.2
ruff>=0.5.5
mypy>=1.7.1
pytest>=8.3.1
molot~=1.0.0
Expand Down
2 changes: 1 addition & 1 deletion sandbox/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def metabase_setup():
timeout=10,
).json()
for collection in collections:
if collection.get("is_sample") == True and collection.get("archived") == False:
if collection.get("is_sample") and not collection.get("archived"):
logging.info("Deleting Metabase sample collection %s", collection["id"])
requests.put(
url=f"{MB_API_URL}/collection/{collection['id']}",
Expand Down
2 changes: 1 addition & 1 deletion tests/_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ def __init__(
self,
manifest_path: Path = FIXTURES_PATH / "manifest-v12.json",
metabase_url: str = f"http://localhost:{SANDBOX_ENV['MB_PORT']}",
): # pylint: disable=super-init-not-called
):
self._manifest = MockManifest(path=manifest_path)
self._metabase = MockMetabase(url=metabase_url, record=RECORD)
3 changes: 0 additions & 3 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

@pytest.fixture(name="core")
def fixture_core() -> MockDbtMetabase:
# pylint: disable=protected-access
c = MockDbtMetabase()
c._ModelsMixin__SYNC_PERIOD = 1 # type: ignore
return c
Expand All @@ -24,7 +23,6 @@ def test_export(core: MockDbtMetabase):


def test_export_hidden_table(core: MockDbtMetabase):
# pylint: disable=protected-access
core._manifest.read_models()
model = core._manifest.find_model("stg_customers")
assert model is not None
Expand All @@ -44,7 +42,6 @@ def test_export_hidden_table(core: MockDbtMetabase):


def test_build_lookups(core: MockDbtMetabase):
# pylint: disable=protected-access,no-member
expected = {
"PUBLIC.CUSTOMERS": [
"CUSTOMER_ID",
Expand Down

0 comments on commit 134ab8c

Please sign in to comment.