Replace or vendor jstyleson (unmaintained), and load extractors lazily

Aperta
#278 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Read extruct/__init__.py and trace its extractor imports and extract() entry point; the issue gives python -X importtime -c "import extruct.w3cmicrodata" as a baseline. Separately inspect extruct.jsonld and its jstyleson dependency. Done when extractor imports follow the requested syntaxes and the JSON-LD path no longer depends on the unmaintained package; the issue does not name tests.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

1. jstyleson is unmaintained and sits on the JSON-LD path. extruct.jsonld imports jstyleson, whose last release is 0.0.2 (June 2016), with no commits since 2021 and only an sdist. Its fix for modern setuptools (linjackson78/jstyleson#8) has been open since October 2024, and #241 shows pip install extruct failing because of it. In #241 you mentioned vendoring, replacing or forking it — is that still the plan? Every user of extract() depends on it, including those who only want JSON-LD, so it can't be avoided by choosing syntaxes. If it helps, its job (JSON with comments and trailing commas) is small enough to vendor in a few dozen lines, or could be handled by stripping comments before json.loads.

2. Load extractors lazily. extract() takes syntaxes=, but importing any part of the package loads every extractor, since extruct/__init__.py imports them all. With extruct 0.18.0 on Python 3.13, python -X importtime -c "import extruct.w3cmicrodata" (median of 3):

Module Cumulative import
extruct total ~155 ms
w3cmicrodata + jsonld themselves ~3 ms
mf2py (incl. bs4, soupsieve) ~70 ms
pyRdfa ~30 ms

Exposing the extractors through a module-level __getattr__ (PEP 562), and importing each one inside extract() only for the syntaxes requested, would keep the public API unchanged while letting syntaxes=["json-ld", "microdata"] skip mf2py and pyRdfa entirely.

Happy to help with a PR for either.

Lingua principale
Python
Stelle
986
Fork
127
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di scrapinghub/extruct

Tutte le issue di scrapinghub/extruct

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.