Skip to content

Commit

Permalink
glossary_v2.py: fix lint errors and improve an exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Jan 5, 2025
1 parent 985316b commit fb5153e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions pyglossary/glossary_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def _createReader(
formatName: str,
options: dict[str, Any],
) -> Any: # noqa: ANN401
readerClass = self.plugins[formatName].readerClass
readerClass = PluginManager.plugins[formatName].readerClass
if readerClass is None:
raise ReadError("_createReader: readerClass is None")
reader = readerClass(self)
Expand Down Expand Up @@ -681,7 +681,7 @@ def _validateReadoptions(
formatName: str,
options: dict[str, Any],
) -> None:
validOptionKeys = set(self.formatsReadOptions[formatName])
validOptionKeys = set(PluginManager.formatsReadOptions[formatName])
for key in list(options):
if key not in validOptionKeys:
log.error(
Expand Down Expand Up @@ -762,7 +762,7 @@ def _read(
self._validateReadoptions(formatName, options)

filenameBase, ext = os.path.splitext(filenameUC)
if ext.lower() not in self.plugins[formatName].extensions:
if ext.lower() not in PluginManager.plugins[formatName].extensions:
filenameBase = filenameUC

self._filename = filenameBase
Expand Down Expand Up @@ -812,7 +812,7 @@ def _createWriter(
formatName: str,
options: dict[str, Any],
) -> Any: # noqa: ANN401
validOptions = self.formatsWriteOptions.get(formatName)
validOptions = PluginManager.formatsWriteOptions.get(formatName)
if validOptions is None:
raise WriteError(f"No write support for {formatName!r} format")
validOptionKeys = list(validOptions)
Expand All @@ -823,7 +823,7 @@ def _createWriter(
)
del options[key]

writerClass = self.plugins[formatName].writerClass
writerClass = PluginManager.plugins[formatName].writerClass
if writerClass is None:
raise WriteError("_createWriter: writerClass is None")
writer = writerClass(self)
Expand Down Expand Up @@ -890,7 +890,7 @@ def _writeEntries(
if self._config.get("save_info_json", False):
from pyglossary.info_writer import InfoWriter

infoWriter = InfoWriter(self)
infoWriter = InfoWriter(self) # pyright: ignore
infoWriter.setWriteOptions(options)
filenameNoExt, _, _, _ = splitFilenameExt(filename)
infoWriter.open(f"{filenameNoExt}.info")
Expand Down Expand Up @@ -926,7 +926,10 @@ def _write(
) -> str:
filename = os.path.abspath(filename)

if formatName not in self.plugins or not self.plugins[formatName].canWrite:
if formatName not in PluginManager.plugins:
raise WriteError(f"No plugin {formatName!r} was found")

if not PluginManager.plugins[formatName].canWrite:
raise WriteError(f"No Writer class found for plugin {formatName}")

if self._readers and sort:
Expand Down Expand Up @@ -1073,7 +1076,7 @@ def _resolveSortParams(
inputFilename=args.inputFilename,
)
elif not os.getenv("NO_SQLITE"):
self._data = self._newInMemorySqEntryList()
self._data = self._newInMemorySqEntryList() # pyright: ignore

self._data.setSortKey(
namedSortKey=namedSortKey,
Expand Down Expand Up @@ -1150,7 +1153,7 @@ def _convertPrepare(

direct, sort = self._resolveSortParams(
args=args,
plugin=self.plugins[outputFormat],
plugin=PluginManager.plugins[outputFormat],
)

showMemoryUsage()
Expand Down Expand Up @@ -1204,7 +1207,7 @@ def convertV2(self, args: ConvertArgs) -> str:
for key, value in args.infoOverride.items():
self.setInfo(key, value)

if compression and not self.plugins[outputFormat].singleFile:
if compression and not PluginManager.plugins[outputFormat].singleFile:
os.makedirs(outputFilename, mode=0o700, exist_ok=True)

writeOptions = args.writeOptions or {}
Expand Down

0 comments on commit fb5153e

Please sign in to comment.