Skip to content

Commit

Permalink
dvc: update precommit hooks (iterative#5716)
Browse files Browse the repository at this point in the history
* update pre-commit hooks

* fix mypy errors

1. Casting `columns` to the custom Column with collapse.
2. Ignoring typedef difference for RichTable._collapse_widths.
3. Suppressing error with conditional paramiko imports
   python/mypy#1153
  • Loading branch information
skshetry authored Mar 26, 2021
1 parent f8c5674 commit 0a2e9f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: isort
language_version: python3
repo: https://github.com/timothycrosley/isort
rev: 5.6.4
rev: 5.8.0
- hooks:
- id: flake8
language_version: python3
Expand All @@ -18,13 +18,13 @@ repos:
- flake8-debugger
- flake8-string-format
repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
rev: 3.9.0
- hooks:
- id: mypy
language_version: python3
files: ^dvc/
repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.790'
rev: 'v0.812'
- repo: local
hooks:
- id: pylint
Expand Down
2 changes: 1 addition & 1 deletion dvc/fs/ssh/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
try:
import paramiko
except ImportError:
paramiko = None
paramiko = None # type: ignore


logger = logging.getLogger(__name__)
Expand Down
18 changes: 10 additions & 8 deletions dvc/utils/table.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, List
from typing import TYPE_CHECKING, List, cast

from rich.style import StyleType
from rich.table import Column as RichColumn
Expand Down Expand Up @@ -66,19 +66,20 @@ def _calculate_column_widths(
"""
widths = super()._calculate_column_widths(console, max_width)
last_collapsed = -1
for i in range(len(self.columns) - 1, -1, -1):
if widths[i] == 1 and self.columns[i].collapse:
columns = cast(List[Column], self.columns)
for i in range(len(columns) - 1, -1, -1):
if widths[i] == 1 and columns[i].collapse:
if last_collapsed >= 0:
del widths[last_collapsed]
del self.columns[last_collapsed]
del columns[last_collapsed]
if self.box:
max_width += 1
for column in self.columns[last_collapsed:]:
for column in columns[last_collapsed:]:
column._index -= 1
last_collapsed = i
padding = self._get_padding_width(i)
if (
self.columns[i].overflow == "ellipsis"
columns[i].overflow == "ellipsis"
and (sum(widths) + padding) <= max_width
):
# Set content width to 1 (plus padding) if we can fit a
Expand All @@ -88,7 +89,7 @@ def _calculate_column_widths(
last_collapsed = -1
return widths

def _collapse_widths(
def _collapse_widths( # type: ignore[override]
self, widths: List[int], wrapable: List[bool], max_width: int,
) -> List[int]:
"""Collapse columns right-to-left if possible to fit table into
Expand All @@ -97,7 +98,8 @@ def _collapse_widths(
If table is still too wide after collapsing, rich's automatic overflow
handling will be used.
"""
collapsible = [column.collapse for column in self.columns]
columns = cast(List[Column], self.columns)
collapsible = [column.collapse for column in columns]
total_width = sum(widths)
excess_width = total_width - max_width
if any(collapsible):
Expand Down

0 comments on commit 0a2e9f9

Please sign in to comment.