Skip to content

Commit

Permalink
Ruff config
Browse files Browse the repository at this point in the history
Signed-off-by: zethson <lukas.heumos@posteo.net>
  • Loading branch information
Zethson committed Aug 6, 2024
1 parent 846901f commit fdb2ec9
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 94 deletions.
85 changes: 38 additions & 47 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,65 +1,56 @@
fail_fast: false
default_language_version:
python: python3
default_stages:
- commit
- push
minimum_pre_commit_version: 2.16.0
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
exclude: |
(?x)(
.github/workflows/latest-changes.jinja2
)
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black-jupyter
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.4
hooks:
- id: flake8
additional_dependencies:
- flake8-black==0.3.3
- flake8-typing-imports==1.10.0
language_version: python3
args:
- --max-line-length=88
- --ignore=E203,W503,BLK100,TYP001
- id: prettier
exclude: |
(?x)(
__init__.py
docs/changelog.md
)
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.6.2
hooks:
- id: prettier
- repo: https://github.com/kynan/nbstripout
rev: 0.3.9
rev: 0.6.1
hooks:
- id: nbstripout
exclude: |
(?x)(
docs/examples/|
docs/notes/
)
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.9
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.5
hooks:
- id: forbid-crlf
- id: remove-crlf
- repo: https://github.com/pycqa/isort
rev: 5.12.0
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --unsafe-fixes]
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black"]
- id: detect-private-key
- id: check-ast
- id: end-of-file-fixer
exclude: |
(?x)(
.github/workflows/latest-changes.jinja2
)
- id: mixed-line-ending
args: [--fix=lf]
- id: trailing-whitespace
- id: check-case-conflict
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.940
rev: v1.7.1
hooks:
- id: mypy
- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
hooks:
- id: pydocstyle
args: # google style + __init__, see http://www.pydocstyle.org/en/stable/error_codes.html
- --ignore=D100,D101,D102,D103,D104,D106,D107,D203,D204,D213,D215,D400,D401,D403,D404,D406,D407,D408,D409,D412,D413
args: [--no-strict-optional, --ignore-missing-imports]
additional_dependencies:
["types-pkg-resources", "types-requests", "types-attrs"]
exclude: |
(?x)(
test_notebooks.py
)
4 changes: 2 additions & 2 deletions lamin_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

__version__ = "0.13.2"

from ._core import colors # noqa
from ._core import colors
from ._logger import logger
from ._python_version import py_version_warning # noqa
from ._python_version import py_version_warning
6 changes: 2 additions & 4 deletions lamin_utils/_base62.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,11 @@ def _value(ch, charset):
try:
return charset.index(ch)
except ValueError:
raise ValueError("base62: Invalid character (%s)" % ch)
raise ValueError(f"base62: Invalid character ({ch})") from None


def _check_type(value, expected_type):
"""Checks if the input is in an appropriate type."""
if not isinstance(value, expected_type):
msg = "Expected {} object, not {}".format(
expected_type, value.__class__.__name__
)
msg = f"Expected {expected_type} object, not {value.__class__.__name__}"
raise TypeError(msg)
28 changes: 14 additions & 14 deletions lamin_utils/_core.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# ANSI color code: https://gist.github.com/iansan5653/c4a0b9f5c30d74258c5f132084b78db9
ANSI_COLORS = dict(
bold="\x1b[1m",
italic="\x1b[3m",
underline="\x1b[4m",
black="\x1b[1;90m",
red="\x1b[1;91m",
green="\x1b[1;92m",
yellow="\x1b[1;93m",
blue="\x1b[1;94m",
purple="\x1b[1;95m",
cyan="\x1b[1;96m",
white="\x1b[1;97m",
reset="\x1b[0m",
)
ANSI_COLORS = {
"bold": "\x1b[1m",
"italic": "\x1b[3m",
"underline": "\x1b[4m",
"black": "\x1b[1;90m",
"red": "\x1b[1;91m",
"green": "\x1b[1;92m",
"yellow": "\x1b[1;93m",
"blue": "\x1b[1;94m",
"purple": "\x1b[1;95m",
"cyan": "\x1b[1;96m",
"white": "\x1b[1;97m",
"reset": "\x1b[0m",
}


class colors:
Expand Down
11 changes: 6 additions & 5 deletions lamin_utils/_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _validate_logging(result: "InspectResult", field: Optional[str] = None):
success_msg = ""
if len(result.validated) > 0:
success_msg = (
f"{colors.green(f'{len(result.validated)} term{s}')} ({result.frac_validated:.2f}%)" # noqa
f"{colors.green(f'{len(result.validated)} term{s}')} ({result.frac_validated:.2f}%)"
f" {are} validated{field_msg}"
)
if result.frac_validated < 100:
Expand All @@ -105,7 +105,7 @@ def _validate_logging(result: "InspectResult", field: Optional[str] = None):
if len(result.non_validated) > 20:
print_values += ", ..."
warn_msg = (
f"{colors.yellow(f'{len(result.non_validated)} term{s}')} ({(100-result.frac_validated):.2f}%)" # noqa
f"{colors.yellow(f'{len(result.non_validated)} term{s}')} ({(100-result.frac_validated):.2f}%)"
f" {are} not validated{field_msg}: {colors.yellow(print_values)}"
)
if len(empty_warn_msg) > 0:
Expand Down Expand Up @@ -147,7 +147,8 @@ def inspect(
# empty DataFrame or input
if df.shape[0] == 0 or len(uniq_identifiers) == 0:
result = _validate_stats(
identifiers=identifiers, matches=[False] * len(identifiers) # type:ignore
identifiers=identifiers,
matches=[False] * len(identifiers), # type:ignore
)
if not mute:
_validate_logging(result=result, field=field)
Expand Down Expand Up @@ -194,7 +195,7 @@ def inspect(
info_msg = f"detected {labels}: {colors.yellow(print_values)}"
result._synonyms_mapper = synonyms_mapper

except Exception:
except Exception: # noqa: S110
pass
if not mute:
_validate_logging(result=result, field=field)
Expand Down Expand Up @@ -231,7 +232,7 @@ def __init__(

@property
def df(self) -> "pd.DataFrame":
"""A DataFrame indexed by values with a boolean `__validated__` column.""" # noqa
"""A DataFrame indexed by values with a boolean `__validated__` column."""
return self._df

@property
Expand Down
26 changes: 14 additions & 12 deletions lamin_utils/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Logging and Profiling."""

import logging

# import platform
Expand Down Expand Up @@ -122,38 +123,38 @@ def log( # type: ignore
super().log(level, msg, extra=extra)
return now

def critical(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore # noqa
def critical(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore
return self.log(CRITICAL, msg, time=time, deep=deep, extra=extra)

def error(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore # noqa
def error(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore
return self.log(ERROR, msg, time=time, deep=deep, extra=extra)

def warning(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore # noqa
def warning(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore
return self.log(WARNING, msg, time=time, deep=deep, extra=extra)

def important(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore # noqa
def important(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore
return self.log(IMPORTANT, msg, time=time, deep=deep, extra=extra)

def success(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore # noqa
def success(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore
return self.log(SUCCESS, msg, time=time, deep=deep, extra=extra)

def info(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore # noqa
def info(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore
return self.log(INFO, msg, time=time, deep=deep, extra=extra)

def save(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore # noqa
def save(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore
return self.log(SAVE, msg, time=time, deep=deep, extra=extra)

def hint(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore # noqa
def hint(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore
return self.log(HINT, msg, time=time, deep=deep, extra=extra)

def debug(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore # noqa
def debug(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore
return self.log(DEBUG, msg, time=time, deep=deep, extra=extra)

def print(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore # noqa
def print(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore
return self.log(PRINT, msg, time=time, deep=deep, extra=extra)

# backward compat
def download(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore # noqa
def download(self, msg, *, time=None, deep=None, extra=None) -> datetime: # type: ignore
return self.log(SAVE, msg, time=time, deep=deep, extra=extra)


Expand All @@ -178,7 +179,8 @@ def format(self, record: logging.LogRecord):
if record.time_passed: # type: ignore
if "{time_passed}" in record.msg:
record.msg = record.msg.replace(
"{time_passed}", record.time_passed # type: ignore
"{time_passed}",
record.time_passed, # type: ignore
)
else:
self._style._fmt += " ({time_passed})"
Expand Down
2 changes: 1 addition & 1 deletion lamin_utils/_standardize.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def standardize(
for k, v in mapper.items()
if k
not in set(
chain(*[v if isinstance(v, list) else [v] for v in result.values()]) # type: ignore # noqa
chain(*[v if isinstance(v, list) else [v] for v in result.values()]) # type: ignore
)
}
)
Expand Down
Loading

0 comments on commit fdb2ec9

Please sign in to comment.