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

ci(ruff): More code quality nits #295

Merged
merged 2 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ $ pipx install --suffix=@next unihan-etl --pip-args '\--pre' --force

<!-- Maintainers, insert changes / features for the next release here -->

### Internal

- ruff: Code quality tweaks (#295)

## unihan-etl 0.26.0 (2023-07-09)

### Features
Expand Down
21 changes: 8 additions & 13 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# flake8: NOQA E501
# flake8: NOQA: E501
import inspect
import os
import pathlib
import sys
import typing as t
from os.path import dirname, relpath
from os.path import relpath
from pathlib import Path

import unihan_etl
Expand All @@ -21,7 +21,7 @@

# package data
about: t.Dict[str, str] = {}
with open(src_root / "unihan_etl" / "__about__.py") as fp:
with (src_root / "unihan_etl" / "__about__.py").open() as fp:
exec(fp.read(), about)

extensions = [
Expand Down Expand Up @@ -181,9 +181,7 @@
}


def linkcode_resolve(
domain: str, info: t.Dict[str, str]
) -> t.Union[None, str]:
def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:
"""
Determine the URL corresponding to Python object

Expand All @@ -206,7 +204,7 @@ def linkcode_resolve(
for part in fullname.split("."):
try:
obj = getattr(obj, part)
except Exception:
except Exception: # ruff: noqa: PERF203
return None

# strip decorators, which would resolve to the source of the decorator
Expand All @@ -231,12 +229,9 @@ def linkcode_resolve(
except Exception:
lineno = None

if lineno:
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1)
else:
linespec = ""
linespec = "#L%d-L%d" % (lineno, lineno + len(source) - 1) if lineno else ""

fn = relpath(fn, start=dirname(unihan_etl.__file__))
fn = relpath(fn, start=pathlib.Path(unihan_etl.__file__).parent)

if "dev" in about["__version__"]:
return "{}/blob/master/{}/{}/{}{}".format(
Expand Down
11 changes: 5 additions & 6 deletions src/unihan_etl/constants.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#: Dictionary of tuples mapping locations of files to fields
from unihan_etl.types import ColumnDataTuple
import importlib.util

from appdirs import AppDirs as BaseAppDirs

from unihan_etl.__about__ import (
__author__,
__package_name__,
)
from unihan_etl._internal.app_dirs import AppDirs

from unihan_etl.types import ColumnDataTuple
from unihan_etl.util import get_fields

UNIHAN_MANIFEST = {
Expand Down Expand Up @@ -234,9 +236,6 @@
UNIHAN_FIELDS: "ColumnDataTuple" = tuple(get_fields(UNIHAN_MANIFEST))
#: Allowed export types
ALLOWED_EXPORT_TYPES = ["json", "csv"]
try:
import yaml # flake8: NOQA F401

if importlib.util.find_spec("yaml"):
ALLOWED_EXPORT_TYPES += ["yaml"]
except ImportError:
pass