Skip to content

Commit

Permalink
Replace webpub manifest parser with pydantic (PP-1367) (#2163)
Browse files Browse the repository at this point in the history
Replace our custom web manifest parser with Pydantic models.

I replace the validation we were doing via a patched json schema with the pydantic parser, since it gives better errors and more closely matches what we are expecting in Palace.
  • Loading branch information
jonathangreen authored Nov 20, 2024
1 parent 5a49b70 commit 71ef9d4
Show file tree
Hide file tree
Showing 36 changed files with 370 additions and 2,107 deletions.
8 changes: 1 addition & 7 deletions bin/opds2_import_monitor
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#!/usr/bin/env python
"""Update the circulation manager server with new books from OPDS 2.0 import collections."""
from webpub_manifest_parser.opds2 import OPDS2FeedParserFactory

from palace.manager.core.opds2_import import (
OPDS2Importer,
OPDS2ImportMonitor,
RWPMManifestParser,
)
from palace.manager.core.opds2_import import OPDS2Importer, OPDS2ImportMonitor
from palace.manager.scripts.opds_import import OPDSImportScript

import_script = OPDSImportScript(
importer_class=OPDS2Importer,
monitor_class=OPDS2ImportMonitor,
protocol=OPDS2Importer.NAME,
parser=RWPMManifestParser(OPDS2FeedParserFactory()),
)

import_script.run()
4 changes: 0 additions & 4 deletions bin/opds2_odl_import_monitor
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
OPDS 2.x + ODL collections."""


from webpub_manifest_parser.odl import ODLFeedParserFactory

from palace.manager.api.odl.importer import (
OPDS2WithODLImporter,
OPDS2WithODLImportMonitor,
)
from palace.manager.core.opds2_import import RWPMManifestParser
from palace.manager.scripts.monitor import RunCollectionMonitorScript

RunCollectionMonitorScript(
OPDS2WithODLImportMonitor,
import_class=OPDS2WithODLImporter,
parser=RWPMManifestParser(ODLFeedParserFactory()),
).run()
4 changes: 0 additions & 4 deletions bin/opds2_odl_schema_validate
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
OPDS import collections."""


from webpub_manifest_parser.odl import ODLFeedParserFactory

from palace.manager.api.odl.importer import OPDS2WithODLImporter
from palace.manager.core.opds2_import import RWPMManifestParser
from palace.manager.core.opds_schema import OPDS2WithODLSchemaValidation
from palace.manager.scripts.monitor import RunCollectionMonitorScript

import_script = RunCollectionMonitorScript(
OPDS2WithODLSchemaValidation,
import_class=OPDS2WithODLImporter,
parser=RWPMManifestParser(ODLFeedParserFactory()),
)

import_script.run()
9 changes: 1 addition & 8 deletions bin/opds2_reaper_monitor
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ from collections.abc import Generator
from typing import Any, cast

from sqlalchemy.orm import raiseload
from webpub_manifest_parser.opds2 import OPDS2FeedParserFactory

from palace.manager.core.coverage import CoverageFailure
from palace.manager.core.metadata_layer import TimestampData
from palace.manager.core.opds2_import import (
OPDS2API,
OPDS2Importer,
OPDS2ImportMonitor,
RWPMManifestParser,
)
from palace.manager.core.opds2_import import OPDS2API, OPDS2Importer, OPDS2ImportMonitor
from palace.manager.scripts.input import CollectionInputScript
from palace.manager.sqlalchemy.model.collection import Collection
from palace.manager.sqlalchemy.model.edition import Edition
Expand All @@ -28,7 +22,6 @@ def main():
importer_class=OPDS2Importer,
monitor_class=OPDS2ReaperMonitor,
protocol=OPDS2Importer.NAME,
parser=RWPMManifestParser(OPDS2FeedParserFactory()),
)

reaper_script.run()
Expand Down
6 changes: 1 addition & 5 deletions bin/opds2_schema_validate
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
"""Update the circulation manager server with new books from
OPDS import collections."""


from webpub_manifest_parser.opds2 import OPDS2FeedParserFactory

from palace.manager.core.opds2_import import OPDS2Importer, RWPMManifestParser
from palace.manager.core.opds2_import import OPDS2Importer
from palace.manager.core.opds_schema import OPDS2SchemaValidation
from palace.manager.scripts.opds_import import OPDSImportScript

import_script = OPDSImportScript(
importer_class=OPDS2Importer,
monitor_class=OPDS2SchemaValidation,
protocol=OPDS2Importer.NAME,
parser=RWPMManifestParser(OPDS2FeedParserFactory()),
)

import_script.run()
75 changes: 1 addition & 74 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ module = [
"palace.manager.api.opds_for_distributors",
"palace.manager.core.opds2_import",
"palace.manager.core.opds_import",
"palace.manager.core.opds_schema",
"palace.manager.core.selftest",
"palace.manager.feed.*",
"palace.manager.integration.*",
Expand Down Expand Up @@ -198,7 +199,6 @@ module = [
"unicodecsv",
"uwsgi",
"wcag_contrast_ratio",
"webpub_manifest_parser.*",
]

[tool.poetry]
Expand Down Expand Up @@ -243,7 +243,6 @@ multipledispatch = "^1.0"
nameparser = "^1.1" # nameparser is for author name manipulations
opensearch-dsl = "~1.0"
opensearch-py = "~1.1"
palace-webpub-manifest-parser = "^4.0.0"
pillow = "^11.0"
pycountry = "^24.6.1"
pycryptodome = "^3.18"
Expand Down
Loading

0 comments on commit 71ef9d4

Please sign in to comment.