Skip to content

Commit

Permalink
style fixes: fix remaining pycodestyle errors in pyglossary/
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Nov 15, 2023
1 parent e297acd commit 106c31f
Show file tree
Hide file tree
Showing 69 changed files with 326 additions and 341 deletions.
4 changes: 3 additions & 1 deletion pyglossary/apple_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"-webkit-column-rule-color": "column-rule-color", # key
"-webkit-column-rule-style": "column-rule-style", # key
"-webkit-column-rule-width": "column-rule-width", # key
"-webkit-ruby-position": "ruby-position", # key
"-webkit-ruby-position": "ruby-position", # key

# not so sure about this
"-webkit-padding-start": "padding-inline-start", # key
Expand Down Expand Up @@ -102,6 +102,7 @@
rb"(-(apple|webkit)-[a-z\-]+)",
)


def _subCSS(m: "re.Match") -> bytes:
b_key = m.group(0)
value = cssMapping.get(b_key.decode("ascii"))
Expand All @@ -110,6 +111,7 @@ def _subCSS(m: "re.Match") -> bytes:
return b_key
return value.encode("ascii")


def substituteAppleCSS(css: bytes) -> bytes:
css = cssKeyRemovePattern.sub(b"", css)
return cssParamPattern.sub(_subCSS, css)
3 changes: 0 additions & 3 deletions pyglossary/compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ def compress(glos: "GlossaryType", filename: str, compression: str) -> str:
log.error(
f"{e}\nFailed to compress file \"{filename}\"",
)
#else:
# if error:
# log.error(error)
else:
raise ValueError(f"unexpected {compression=}")

Expand Down
52 changes: 27 additions & 25 deletions pyglossary/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@


__all__ = [
'StdLogHandler',
'TRACE',
'VERSION',
'appResDir',
'cacheDir',
'checkCreateConfDir',
'confDir',
'confJsonFile',
'dataDir',
'format_exception',
'getDataDir',
'homeDir',
'homePage',
'isDebug',
'log',
'noColor',
'pip',
'pluginsDir',
'rootConfJsonFile',
'rootDir',
'sysName',
'tmpDir',
'trace',
'uiDir',
'userPluginsDir',
'StdLogHandler',
'TRACE',
'VERSION',
'appResDir',
'cacheDir',
'checkCreateConfDir',
'confDir',
'confJsonFile',
'dataDir',
'format_exception',
'getDataDir',
'homeDir',
'homePage',
'isDebug',
'log',
'noColor',
'pip',
'pluginsDir',
'rootConfJsonFile',
'rootDir',
'sysName',
'tmpDir',
'trace',
'uiDir',
'userPluginsDir',
]


Expand Down Expand Up @@ -329,9 +329,11 @@ def getDataDir() -> str:
logging.setLoggerClass(_MyLogger)
log = cast(_MyLogger, logging.getLogger("pyglossary"))


def isDebug() -> bool:
return log.getVerbosity() >= 4


if os.sep == "\\":
def _windows_show_exception(
_type: "type[BaseException]",
Expand Down
1 change: 1 addition & 0 deletions pyglossary/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"getMockLogger",
]


class MockLogHandler(logging.Handler):
def __init__(self) -> None:
logging.Handler.__init__(self)
Expand Down
2 changes: 2 additions & 0 deletions pyglossary/entry_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def fixStr(st: str) -> str:
entry.editFuncDefi(fixStr)
return entry


class StripFullHtml(EntryFilter):
name = "strip_full_html"
desc = "Replace a full HTML document with it's body"
Expand Down Expand Up @@ -476,6 +477,7 @@ def run(self, entry: "EntryType") -> "EntryType | None":
core.trace(log, f"MaxMemUsage: {usage:,}, {word=}")
return entry


entryFiltersRules = [
(None, True, TrimWhitespaces),
(None, True, NonEmptyWordFilter),
Expand Down
1 change: 1 addition & 0 deletions pyglossary/glossary_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
if TYPE_CHECKING:
from .ui_type import UIType


class GlossaryProgress:
def __init__(
self,
Expand Down
2 changes: 0 additions & 2 deletions pyglossary/glossary_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from .sort_keys import NamedSortKey



MultiStr: "TypeAlias" = "str | list[str]"

# 3 different types in order:
Expand Down Expand Up @@ -281,7 +280,6 @@ def removeHtmlTagsAll(self) -> None:
...



class GlossaryExtendedType(GlossaryType, typing.Protocol):
def progressInit(
self,
Expand Down
2 changes: 1 addition & 1 deletion pyglossary/langs/writing_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
),
WritingSystem(
name="Devanagari",
iso=[(315 , "Deva")],
iso=[(315, "Deva")],
unicode=["DEVANAGARI"],
titleTag="big",
comma=", ",
Expand Down
13 changes: 13 additions & 0 deletions pyglossary/lxml_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ def write_declaration(
doctype: "AnyStr | None" = ...,
) -> None:
...

def write_doctype(
self,
doctype: "AnyStr | None",
) -> None:
...

def write(
self,
*args: "AnyStr | Element",
Expand All @@ -58,13 +60,16 @@ def write(
method: _OutputMethodArg | None = ...,
) -> None:
...

def flush(self) -> None:
...

def method(
self,
method: "_OutputMethodArg | None",
) -> ContextManager[None]:
raise NotImplementedError

def element(
self,
tag: _TagName,
Expand All @@ -75,6 +80,7 @@ def element(
) -> ContextManager[None]:
raise NotImplementedError


class AsyncIncrementalFileWriter(typing.Protocol):
async def write_declaration(
self,
Expand All @@ -83,11 +89,13 @@ async def write_declaration(
doctype: "AnyStr | None" = ...,
) -> None:
...

async def write_doctype(
self,
doctype: "AnyStr | None",
) -> None:
...

async def write(
self,
*args: "AnyStr | Element | None",
Expand All @@ -96,13 +104,16 @@ async def write(
method: "_OutputMethodArg | None" = ...,
) -> None:
...

async def flush(self) -> None:
...

def method(
self,
method: "_OutputMethodArg | None",
) -> AsyncContextManager[None]:
raise NotImplementedError

def element(
self,
tag: _TagName,
Expand All @@ -113,6 +124,7 @@ def element(
) -> AsyncContextManager[None]:
raise NotImplementedError


class T_htmlfile( # type: ignore # noqa: PGH003
IncrementalFileWriter,
ContextManager[IncrementalFileWriter],
Expand All @@ -121,5 +133,6 @@ class T_htmlfile( # type: ignore # noqa: PGH003
):
pass


# typing.AsyncContextManager
# is generic version of contextlib.AbstractAsyncContextManager
3 changes: 2 additions & 1 deletion pyglossary/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _idzip(filename: "str | Path") -> bool:
except ModuleNotFoundError:
return False
filename = Path(filename)
destination = filename.parent/(filename.name + ".dz")
destination = filename.parent / (filename.name + ".dz")
try:
with open(filename, "rb") as inp_file, open(destination, "wb") as out_file:
inputInfo = os.fstat(inp_file.fileno())
Expand Down Expand Up @@ -99,6 +99,7 @@ def _dictzip(filename: str) -> bool:
log.error(f"dictzip error: {out}")
return True


def _nozip(filename: str) -> bool:
log.warning(
"Dictzip compression requires idzip module or dictzip utility,"
Expand Down
34 changes: 17 additions & 17 deletions pyglossary/plugin_lib/dictdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
# Copyright (C) 2002 John Goerzen <jgoerzen@complete.org>
# Copyright (C) 2020 Saeed Rasooli
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

import gzip
import os
Expand Down Expand Up @@ -97,8 +97,8 @@ def __init__(
mode: str = 'read',
quiet: int = 0,
) -> None:
#, url = 'unknown', shortname = 'unknown',
# longinfo = 'unknown', quiet = 0):
# url = 'unknown', shortname = 'unknown',
# longinfo = 'unknown', quiet = 0):
"""
Initialize a DictDB object.
Expand Down Expand Up @@ -167,10 +167,9 @@ def __init__(
else:
raise ValueError("mode must be 'read', 'write', or 'update'")

#self.writeentry(url_headword + "\n " + url, [url_headword])
#self.writeentry(short_headword + "\n " + shortname,
# [short_headword])
#self.writeentry(info_headword + "\n" + longinfo, [info_headword])
# self.writeentry(url_headword + "\n " + url, [url_headword])
# self.writeentry(short_headword + "\n " + shortname, [short_headword])
# self.writeentry(info_headword + "\n" + longinfo, [info_headword])

def __len__(self) -> int:
return len(self.indexEntries)
Expand Down Expand Up @@ -389,6 +388,7 @@ def getDef(self, word: str) -> "list[bytes]":
retval.append(self.dictFile.read(length))
return retval


# print("------------------------ ", __name__)
if __name__ == "__main__":
db = DictDB("test")
Expand Down
Loading

0 comments on commit 106c31f

Please sign in to comment.