Skip to content

Commit

Permalink
Merge branch 'ilius:master' into feature/webui-browse
Browse files Browse the repository at this point in the history
  • Loading branch information
glowinthedark authored Dec 19, 2024
2 parents bf21311 + 7990534 commit c4979bb
Show file tree
Hide file tree
Showing 66 changed files with 816 additions and 991 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ jobs:
python-idzip \
lxml==5.3 \
marisa-trie \
mistune
mistune \
polib
- name: Remove test cache
run: rm -rf /home/runner/.cache/pyglossary/test || true
- name: Run tests
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import-analyzer/
/.mypy_cache/
/plugins
/ui
.coverage
*.cover*
*,cover
htmlcov
*.htmlcov
vulture.*
imports_from_set.json
imports_set.json
Expand Down
1 change: 0 additions & 1 deletion doc/p/__index__.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
| Gettext Source (.po) | GettextPo | [gettext_po.md](./gettext_po.md) |
| HTML Directory | HtmlDir | [html_dir.md](./html_dir.md) |
| Glossary Info (.info) | Info | [info.md](./info.md) |
| IUPAC goldbook (.xml) | IUPACGoldbook | [iupac_goldbook.md](./iupac_goldbook.md) |
| JMDict (xml) | JMDict | [jmdict.md](./jmdict.md) |
| JMnedict | JMnedict | [jmnedict.md](./jmnedict.md) |
| JSON (.json) | Json | [json.md](./json.md) |
Expand Down
28 changes: 0 additions & 28 deletions doc/p/iupac_goldbook.md

This file was deleted.

1 change: 1 addition & 0 deletions doc/p/wiktextract.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
| example_padding | `10px 20px` | str | Padding for examples (css value) |
| audio | `True` | bool | Enable audio |
| audio_formats | `['ogg', 'mp3']` | list | List of audio formats to use |
| categories | `False` | bool | Enable categories |

### Dependencies for reading

Expand Down
28 changes: 7 additions & 21 deletions plugins-meta/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -1191,26 +1191,6 @@
"readOptions": {},
"writeOptions": {}
},
{
"module": "iupac_goldbook",
"lname": "iupac_goldbook",
"name": "IUPACGoldbook",
"description": "IUPAC goldbook (.xml)",
"extensions": [],
"singleFile": true,
"optionsProp": {},
"canRead": true,
"canWrite": false,
"readOptions": {},
"readDepends": {
"lxml": "lxml"
},
"readCompressions": [
"gz",
"bz2",
"lzma"
]
},
{
"module": "jmdict",
"lname": "jmdict",
Expand Down Expand Up @@ -1820,6 +1800,11 @@
"class": "ListOption",
"type": "list",
"comment": "List of audio formats to use"
},
"categories": {
"class": "BoolOption",
"type": "bool",
"comment": "Enable categories"
}
},
"canRead": true,
Expand All @@ -1833,7 +1818,8 @@
"audio_formats": [
"ogg",
"mp3"
]
],
"categories": false
},
"readDepends": {
"lxml": "lxml"
Expand Down
7 changes: 4 additions & 3 deletions pyglossary/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@

def exc_note(e: Exception, note: str) -> Exception:
try:
e.add_note(note) # # pyright: ignore[reportAttributeAccessIssue]
e.add_note(note) # pyright: ignore[reportAttributeAccessIssue]
except AttributeError:
e.msg += "\n" + note # # pyright: ignore[reportAttributeAccessIssue]
if hasattr(e, "msg"):
e.msg += "\n" + note # pyright: ignore[reportAttributeAccessIssue]
return e


Expand Down Expand Up @@ -55,7 +56,7 @@ def exc_note(e: Exception, note: str) -> Exception:
]


VERSION = "5.0.0"
VERSION = "5.0.1"

homePage = "https://github.com/ilius/pyglossary"

Expand Down
3 changes: 3 additions & 0 deletions pyglossary/ebook_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ def write_data_entry(self, entry: EntryType) -> None:
"text/css",
)

def get_prefix(self, word: str) -> str:
raise NotImplementedError

def write_groups(self) -> Generator[None, EntryType, None]:
# TODO: rtl=False option
# TODO: handle alternates better (now shows word1|word2... in title)
Expand Down
6 changes: 5 additions & 1 deletion pyglossary/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ def s_word(self) -> str:
def l_word(self) -> list[str]:
return [self._fname]

@property
def lb_word(self) -> list[bytes]:
return [self._fname.encode("trf-8")]

@property
def defi(self) -> str:
return f"File: {self._fname}"
Expand Down Expand Up @@ -194,7 +198,7 @@ def isData(cls) -> bool:

@staticmethod
def getRawEntrySortKey(
key: Callable[[bytes], Any],
key: Callable[[list[str]], Any],
) -> Callable[[RawEntryType], Any]:
def newKey(x: RawEntryType) -> Any: # noqa: ANN401
# x is rawEntry, so x[2:] is list[bytes]: list of words in bytes
Expand Down
61 changes: 59 additions & 2 deletions pyglossary/entry_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,51 @@
from __future__ import annotations

import typing
from typing import TYPE_CHECKING

# from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Callable

__all__ = ["BaseEntry", "MultiStr"]

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


class BaseEntry:
class BaseEntry: # noqa: PLR0904
__slots__: list[str] = [
"_word",
]

def __init__(self) -> None:
self._word: str | list[str]

def isData(self) -> bool: ...

def getFileName(self) -> str:
raise NotImplementedError

@property
def data(self) -> bytes:
raise NotImplementedError

def size(self) -> int:
raise NotImplementedError

def save(self, directory: str) -> str:
raise NotImplementedError

@property
def s_word(self) -> str:
raise NotImplementedError

@property
def l_word(self) -> list[str]:
raise NotImplementedError

@property
def lb_word(self) -> list[bytes]:
raise NotImplementedError

@property
def defi(self) -> str:
raise NotImplementedError
Expand All @@ -36,3 +61,35 @@ def b_word(self) -> bytes:
def b_defi(self) -> bytes:
"""Returns definition in bytes."""
return self.defi.encode("utf-8")

@property
def defiFormat(self) -> str:
# TODO: type: Literal["m", "h", "x", "b"]
...

@defiFormat.setter
def defiFormat(self, defiFormat: str) -> None:
# TODO: type: Literal["m", "h", "x", "b"]
...

def detectDefiFormat(self, default: str = "") -> str: ...

def addAlt(self, alt: str) -> None: ...

def editFuncWord(self, func: Callable[[str], str]) -> None: ...

def editFuncDefi(self, func: Callable[[str], str]) -> None: ...

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

def replaceInWord(self, source: str, target: str) -> None: ...

def replaceInDefi(self, source: str, target: str) -> None: ...

def replace(self, source: str, target: str) -> None: ...

def byteProgress(self) -> tuple[int, int] | None: ...

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

def stripFullHtml(self) -> str | None: ...
19 changes: 13 additions & 6 deletions pyglossary/glossary.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from __future__ import annotations

import warnings
from collections import OrderedDict as odict
from os.path import relpath
from time import perf_counter as now
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -49,8 +48,8 @@ def __init__(
ui: UIType | None = None, # noqa: F821
) -> None:
"""
info: OrderedDict or dict instance, or None
no need to copy OrderedDict instance before passing here
info: dict instance, or None
no need to copy dict instance before passing here
we will not reference to it.
"""
warnings.warn(
Expand All @@ -60,7 +59,7 @@ def __init__(
)
GlossaryCommon.__init__(self, ui=ui)
if info:
if not isinstance(info, dict | odict):
if not isinstance(info, dict):
raise TypeError(
"Glossary: `info` has invalid type"
", dict or OrderedDict expected",
Expand Down Expand Up @@ -164,15 +163,23 @@ def sortWords(
self._iter = self._loadedEntryGen()

@classmethod
def detectInputFormat(cls, *args, **kwargs) -> DetectedFormat | None: # pyright: ignore[reportIncompatibleMethodOverride]
def detectInputFormat( # type: ignore # pyright: ignore[reportIncompatibleMethodOverride]
cls,
*args,
**kwargs,
) -> DetectedFormat | None:
try:
return GlossaryCommon.detectInputFormat(*args, **kwargs)
except Error as e:
log.critical(str(e))
return None

@classmethod
def detectOutputFormat(cls, *args, **kwargs) -> DetectedFormat | None: # pyright: ignore[reportIncompatibleMethodOverride]
def detectOutputFormat( # type: ignore # pyright: ignore[reportIncompatibleMethodOverride]
cls,
*args,
**kwargs,
) -> DetectedFormat | None:
try:
return GlossaryCommon.detectOutputFormat(*args, **kwargs)
except Error as e:
Expand Down
9 changes: 4 additions & 5 deletions pyglossary/glossary_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from __future__ import annotations

import logging
from collections import OrderedDict as odict
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand All @@ -45,7 +44,7 @@

class GlossaryInfo:
def __init__(self) -> None:
self._info: dict[str, str] = odict()
self._info: dict[str, str] = {}

def infoKeys(self) -> list[str]:
return list(self._info)
Expand Down Expand Up @@ -80,10 +79,10 @@ def setInfo(self, key: str, value: str | None) -> None:
key = infoKeysAliasDict.get(key.lower(), key)
self._info[key] = value

def getExtraInfos(self, excludeKeys: list[str]) -> odict:
def getExtraInfos(self, excludeKeys: list[str]) -> dict[str, str]:
"""
excludeKeys: a list of (basic) info keys to be excluded
returns an OrderedDict including the rest of info keys,
returns a dict including the rest of info keys,
with associated values.
"""
excludeKeySet = set()
Expand All @@ -93,7 +92,7 @@ def getExtraInfos(self, excludeKeys: list[str]) -> odict:
if key2:
excludeKeySet.add(key2)

extra = odict()
extra = {}
for key, value in self._info.items():
if key in excludeKeySet:
continue
Expand Down
7 changes: 4 additions & 3 deletions pyglossary/glossary_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
)

if TYPE_CHECKING:
from collections import OrderedDict
from typing import TypeAlias

from .langs import Lang
Expand All @@ -38,7 +37,7 @@


class EntryType(typing.Protocol): # noqa: PLR0904
def __init__(self) -> None: ...
# def __init__(self) -> None: ...

def isData(self) -> bool: ...

Expand Down Expand Up @@ -157,7 +156,7 @@ def getInfo(self, key: str) -> str: ...

def setInfo(self, key: str, value: str) -> None: ...

def getExtraInfos(self, excludeKeys: list[str]) -> OrderedDict: ...
def getExtraInfos(self, excludeKeys: list[str]) -> dict[str, str]: ...

@property
def author(self) -> str: ...
Expand Down Expand Up @@ -225,6 +224,8 @@ def stripFullHtml(

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

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

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

def addCleanupPath(self, path: str) -> None: ...
Expand Down
Loading

0 comments on commit c4979bb

Please sign in to comment.