entrylib-pages 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {entrylib_pages-0.1.0/src/entrylib_pages.egg-info → entrylib_pages-0.2.0}/PKG-INFO +14 -8
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/README.md +13 -6
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/pyproject.toml +2 -2
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages/__init__.py +18 -7
- entrylib_pages-0.2.0/src/entrylib_pages/format.py +114 -0
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages/page.py +11 -9
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages/paper.py +1 -1
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages/paper_page.py +2 -7
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages/refs.py +4 -5
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0/src/entrylib_pages.egg-info}/PKG-INFO +14 -8
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages.egg-info/SOURCES.txt +1 -1
- entrylib_pages-0.2.0/tests/test_preview.py +111 -0
- entrylib_pages-0.1.0/src/entrylib_pages.egg-info/requires.txt +0 -1
- entrylib_pages-0.1.0/tests/test_preview.py +0 -47
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/LICENSE +0 -0
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/setup.cfg +0 -0
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages/mathml.py +0 -0
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages/page_css.py +0 -0
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages/score_html.py +0 -0
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages/scoring.py +0 -0
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages/static/page.js +0 -0
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages/static/site.css +0 -0
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages/text.py +0 -0
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages.egg-info/dependency_links.txt +0 -0
- {entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: entrylib-pages
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: EntryLib's pages for a claimset: the paper view and the record, as entrylib.org shows them
|
|
5
5
|
Author: EntryLib
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -11,7 +11,6 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Requires-Python: >=3.10
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
-
Requires-Dist: claimset>=0.45.1
|
|
15
14
|
Dynamic: license-file
|
|
16
15
|
|
|
17
16
|
# EntryLib pages
|
|
@@ -37,8 +36,11 @@ what the author sees is what will be published.
|
|
|
37
36
|
[EntryLib's rubric](https://github.com/entrylib/rubric), not here), the claims by kind, conflicts of interest, and
|
|
38
37
|
the sections of the page.
|
|
39
38
|
|
|
40
|
-
The format, its validation and the plain-text reading view for models belong to the `claimset` package
|
|
41
|
-
is EntryLib's presentation of it, with the site's stylesheet and script
|
|
39
|
+
The format, its validation and the plain-text reading view for models belong to the `claimset` package, which
|
|
40
|
+
depends on this one; this package is EntryLib's presentation of it, with the site's stylesheet and script, and imports
|
|
41
|
+
no claimset code. What a page needs of the format (how values are written, the verifiability the platform computes,
|
|
42
|
+
subfield names) is given by the caller as one object, `claimset.pages.FORMAT`
|
|
43
|
+
([format.py](https://github.com/entrylib/pages/blob/main/src/entrylib_pages/format.py) describes it).
|
|
42
44
|
|
|
43
45
|
## Install
|
|
44
46
|
|
|
@@ -46,7 +48,8 @@ is EntryLib's presentation of it, with the site's stylesheet and script.
|
|
|
46
48
|
pip install entrylib-pages
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
It needs Python 3.10 or later and
|
|
51
|
+
It needs Python 3.10 or later and nothing else; `pip install claimset` installs it too. In Python, import it as
|
|
52
|
+
`entrylib_pages`.
|
|
50
53
|
|
|
51
54
|
## Use
|
|
52
55
|
|
|
@@ -63,16 +66,19 @@ From Python:
|
|
|
63
66
|
```python
|
|
64
67
|
import json
|
|
65
68
|
import entrylib_pages
|
|
69
|
+
from claimset.pages import FORMAT # what a page needs of the claimset format
|
|
66
70
|
|
|
67
71
|
doc = json.load(open("paper.claimset.json"))
|
|
68
|
-
html = entrylib_pages.preview_html(doc)
|
|
69
|
-
html = entrylib_pages.preview_html(doc, view="record")
|
|
72
|
+
html = entrylib_pages.preview_html(doc, fmt=FORMAT) # the paper view, as one self-contained page
|
|
73
|
+
html = entrylib_pages.preview_html(doc, fmt=FORMAT, view="record") # the record
|
|
70
74
|
```
|
|
71
75
|
|
|
72
|
-
- `entrylib_pages.preview_html(doc, scores=None, view="paper", note="", paper_href=…, record_href=…)`: the page,
|
|
76
|
+
- `entrylib_pages.preview_html(doc, fmt=None, scores=None, view="paper", note="", paper_href=…, record_href=…)`: the page,
|
|
73
77
|
with the site's stylesheets and script inlined. Figures the claimset names by relative path (`files/figures/a.png`)
|
|
74
78
|
are shown from beside the page, so write it in the folder that holds the claimset and its files; figures already
|
|
75
79
|
published on EntryLib are shown from there. `scores`: the rubric's, if the caller has them.
|
|
80
|
+
- `entrylib_pages.use(fmt)`: the format every page of the process is drawn with (the portal calls it once); `fmt`
|
|
81
|
+
given to `preview_html` overrides it.
|
|
76
82
|
- `entrylib_pages.stylesheet()`: the page view's stylesheet (`claimset.css`).
|
|
77
83
|
- `entrylib_pages.__version__`: the version of the pages.
|
|
78
84
|
|
|
@@ -21,8 +21,11 @@ what the author sees is what will be published.
|
|
|
21
21
|
[EntryLib's rubric](https://github.com/entrylib/rubric), not here), the claims by kind, conflicts of interest, and
|
|
22
22
|
the sections of the page.
|
|
23
23
|
|
|
24
|
-
The format, its validation and the plain-text reading view for models belong to the `claimset` package
|
|
25
|
-
is EntryLib's presentation of it, with the site's stylesheet and script
|
|
24
|
+
The format, its validation and the plain-text reading view for models belong to the `claimset` package, which
|
|
25
|
+
depends on this one; this package is EntryLib's presentation of it, with the site's stylesheet and script, and imports
|
|
26
|
+
no claimset code. What a page needs of the format (how values are written, the verifiability the platform computes,
|
|
27
|
+
subfield names) is given by the caller as one object, `claimset.pages.FORMAT`
|
|
28
|
+
([format.py](https://github.com/entrylib/pages/blob/main/src/entrylib_pages/format.py) describes it).
|
|
26
29
|
|
|
27
30
|
## Install
|
|
28
31
|
|
|
@@ -30,7 +33,8 @@ is EntryLib's presentation of it, with the site's stylesheet and script.
|
|
|
30
33
|
pip install entrylib-pages
|
|
31
34
|
```
|
|
32
35
|
|
|
33
|
-
It needs Python 3.10 or later and
|
|
36
|
+
It needs Python 3.10 or later and nothing else; `pip install claimset` installs it too. In Python, import it as
|
|
37
|
+
`entrylib_pages`.
|
|
34
38
|
|
|
35
39
|
## Use
|
|
36
40
|
|
|
@@ -47,16 +51,19 @@ From Python:
|
|
|
47
51
|
```python
|
|
48
52
|
import json
|
|
49
53
|
import entrylib_pages
|
|
54
|
+
from claimset.pages import FORMAT # what a page needs of the claimset format
|
|
50
55
|
|
|
51
56
|
doc = json.load(open("paper.claimset.json"))
|
|
52
|
-
html = entrylib_pages.preview_html(doc)
|
|
53
|
-
html = entrylib_pages.preview_html(doc, view="record")
|
|
57
|
+
html = entrylib_pages.preview_html(doc, fmt=FORMAT) # the paper view, as one self-contained page
|
|
58
|
+
html = entrylib_pages.preview_html(doc, fmt=FORMAT, view="record") # the record
|
|
54
59
|
```
|
|
55
60
|
|
|
56
|
-
- `entrylib_pages.preview_html(doc, scores=None, view="paper", note="", paper_href=…, record_href=…)`: the page,
|
|
61
|
+
- `entrylib_pages.preview_html(doc, fmt=None, scores=None, view="paper", note="", paper_href=…, record_href=…)`: the page,
|
|
57
62
|
with the site's stylesheets and script inlined. Figures the claimset names by relative path (`files/figures/a.png`)
|
|
58
63
|
are shown from beside the page, so write it in the folder that holds the claimset and its files; figures already
|
|
59
64
|
published on EntryLib are shown from there. `scores`: the rubric's, if the caller has them.
|
|
65
|
+
- `entrylib_pages.use(fmt)`: the format every page of the process is drawn with (the portal calls it once); `fmt`
|
|
66
|
+
given to `preview_html` overrides it.
|
|
60
67
|
- `entrylib_pages.stylesheet()`: the page view's stylesheet (`claimset.css`).
|
|
61
68
|
- `entrylib_pages.__version__`: the version of the pages.
|
|
62
69
|
|
|
@@ -4,12 +4,12 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "entrylib-pages"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.2.0"
|
|
8
8
|
description = "EntryLib's pages for a claimset: the paper view and the record, as entrylib.org shows them"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "Apache-2.0"
|
|
11
11
|
requires-python = ">=3.10"
|
|
12
|
-
dependencies = [
|
|
12
|
+
dependencies = []
|
|
13
13
|
authors = [{ name = "EntryLib" }]
|
|
14
14
|
classifiers = ["Programming Language :: Python :: 3", "Operating System :: OS Independent"]
|
|
15
15
|
|
|
@@ -4,16 +4,23 @@ The claimset format (the `claimset` package) defines what a paper says; this pac
|
|
|
4
4
|
portal draws its pages with it, and `claimset preview` draws the same page on the author's machine before
|
|
5
5
|
submitting, so that what the author sees is what will be published.
|
|
6
6
|
|
|
7
|
-
preview_html(doc, scores=None, view="paper", …) -> a self-contained HTML page of the claimset as it will look
|
|
8
|
-
|
|
7
|
+
preview_html(doc, fmt=…, scores=None, view="paper", …) -> a self-contained HTML page of the claimset as it will look
|
|
8
|
+
use(fmt) -> the claimset format every page of this process is drawn with
|
|
9
|
+
stylesheet() -> the page view's stylesheet (claimset.css)
|
|
10
|
+
|
|
11
|
+
It imports nothing but the standard library. What a page needs of the claimset format (how values are written, the
|
|
12
|
+
verifiability the platform computes, subfield names) is given by the caller: `claimset.pages.FORMAT`, see
|
|
13
|
+
entrylib_pages.format.
|
|
9
14
|
"""
|
|
10
15
|
|
|
11
16
|
import re
|
|
12
17
|
from importlib import resources
|
|
13
18
|
|
|
14
19
|
from . import page, paper_page
|
|
20
|
+
from .format import FormatError, use
|
|
15
21
|
|
|
16
|
-
|
|
22
|
+
__all__ = ["FormatError", "file_url", "preview_html", "stylesheet", "use"]
|
|
23
|
+
__version__ = "0.2.0"
|
|
17
24
|
|
|
18
25
|
#: EntryLib's address: figures already published there (a new version keeps them) are shown from it.
|
|
19
26
|
SITE = "https://entrylib.org"
|
|
@@ -48,14 +55,18 @@ def file_url(a):
|
|
|
48
55
|
return uri
|
|
49
56
|
|
|
50
57
|
|
|
51
|
-
def preview_html(doc, scores=None, view="paper", note="", paper_href="?view=paper",
|
|
58
|
+
def preview_html(doc, fmt=None, scores=None, view="paper", note="", paper_href="?view=paper",
|
|
59
|
+
record_href="?view=record"):
|
|
52
60
|
"""The claimset `doc` as EntryLib will show it, as one HTML document: its paper view (`view` "paper") or its record
|
|
53
61
|
("record"), with the site's stylesheets and script inlined; `paper_href` and `record_href` are the two views' addresses
|
|
54
62
|
(two files, when the page is opened from disk). Figures the package holds are shown by their relative
|
|
55
63
|
paths, so the page is written in the folder that holds the claimset and its files. `scores`: the rubric's, if
|
|
56
|
-
the caller has them (`claimset score`); without them the panel shows "–". `note`: HTML under the bar.
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
the caller has them (`claimset score`); without them the panel shows "–". `note`: HTML under the bar. `fmt`: the
|
|
65
|
+
claimset format to draw with (`claimset.pages.FORMAT`), unless `use` gave one."""
|
|
66
|
+
from .format import using
|
|
67
|
+
with using(fmt):
|
|
68
|
+
main = paper_page.preview_main(doc, base_url=SITE, bar=BAR, statement=note, scores=scores, view=view,
|
|
69
|
+
paper_href=paper_href, record_href=record_href, file_url=file_url)
|
|
59
70
|
title = page.esc((doc.get("paper") or {}).get("title") or "Preview")
|
|
60
71
|
return ("<!doctype html>\n<html lang=\"en\"><head><meta charset=\"utf-8\">"
|
|
61
72
|
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">"
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""What a page takes from the claimset format, given by the caller: this package imports no claimset code.
|
|
2
|
+
|
|
3
|
+
A page writes values (numbers, intervals, uncertainties, statistics) exactly as the claimset's reading view for models
|
|
4
|
+
does, shows the verifiability the platform computes for a claim whose file does not carry it (a paper not yet
|
|
5
|
+
published), and names a paper's subfield. Those are the format's: the `claimset` package defines them, and gives them
|
|
6
|
+
to a page as one object, `claimset.pages.FORMAT`. Whoever draws a page passes that object:
|
|
7
|
+
|
|
8
|
+
entrylib_pages.use(claimset.pages.FORMAT) # once, for a process that draws many pages (the portal)
|
|
9
|
+
entrylib_pages.preview_html(doc, fmt=claimset.pages.FORMAT) # for one page (`claimset preview`)
|
|
10
|
+
|
|
11
|
+
The object has these attributes (any object with them will do, a test's stand-in included):
|
|
12
|
+
|
|
13
|
+
number, interval, uncertainty, value, statistic, statistic_note the reading view's value writers
|
|
14
|
+
DIGITS the context variable the writers read for the site's rounding (a callable, or None)
|
|
15
|
+
verifiability(doc) -> {claim id: verifiability} what the platform computes where the file lacks it
|
|
16
|
+
subfield_name(subfield id) -> name or None an OpenAlex subfield's name (`openalex:subfields/1803`)
|
|
17
|
+
|
|
18
|
+
Within the page code the names below stand for the active object's, so the code reads as it did when it imported them
|
|
19
|
+
from `claimset.render`.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
import contextvars
|
|
23
|
+
from contextlib import contextmanager
|
|
24
|
+
|
|
25
|
+
NEEDED = ("number", "interval", "uncertainty", "value", "statistic", "statistic_note", "DIGITS", "verifiability",
|
|
26
|
+
"subfield_name")
|
|
27
|
+
|
|
28
|
+
_active = contextvars.ContextVar("entrylib_pages_format", default=None)
|
|
29
|
+
_default = None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class FormatError(RuntimeError):
|
|
33
|
+
"""No format given, or one that lacks what a page needs."""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _check(fmt):
|
|
37
|
+
missing = [n for n in NEEDED if not hasattr(fmt, n)]
|
|
38
|
+
if missing:
|
|
39
|
+
raise FormatError(f"the format given to entrylib_pages lacks {', '.join(missing)} (see entrylib_pages.format)")
|
|
40
|
+
return fmt
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def use(fmt):
|
|
44
|
+
"""The format every page of this process is drawn with, unless one is given for a page (`using`)."""
|
|
45
|
+
global _default
|
|
46
|
+
_default = _check(fmt)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@contextmanager
|
|
50
|
+
def using(fmt):
|
|
51
|
+
"""Draw with `fmt` inside the block (None: the one `use` set)."""
|
|
52
|
+
token = _active.set(_check(fmt) if fmt is not None else None)
|
|
53
|
+
try:
|
|
54
|
+
yield
|
|
55
|
+
finally:
|
|
56
|
+
_active.reset(token)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def current():
|
|
60
|
+
fmt = _active.get() or _default
|
|
61
|
+
if fmt is None:
|
|
62
|
+
raise FormatError("entrylib_pages draws a page with the claimset format, which it was not given: call "
|
|
63
|
+
"entrylib_pages.use(claimset.pages.FORMAT) once, or pass fmt=claimset.pages.FORMAT")
|
|
64
|
+
return fmt
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
# ---------- the reading view's value writers, as the page code calls them ----------
|
|
68
|
+
|
|
69
|
+
def number(*a, **k):
|
|
70
|
+
return current().number(*a, **k)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def interval(*a, **k):
|
|
74
|
+
return current().interval(*a, **k)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def uncertainty(*a, **k):
|
|
78
|
+
return current().uncertainty(*a, **k)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def value(*a, **k):
|
|
82
|
+
return current().value(*a, **k)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def statistic(*a, **k):
|
|
86
|
+
return current().statistic(*a, **k)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def statistic_note(*a, **k):
|
|
90
|
+
return current().statistic_note(*a, **k)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class _Digits:
|
|
94
|
+
"""The writers' rounding (their DIGITS context variable), reached through the active format."""
|
|
95
|
+
|
|
96
|
+
def get(self, *a):
|
|
97
|
+
return current().DIGITS.get(*a)
|
|
98
|
+
|
|
99
|
+
def set(self, v):
|
|
100
|
+
return current().DIGITS.set(v)
|
|
101
|
+
|
|
102
|
+
def reset(self, token):
|
|
103
|
+
return current().DIGITS.reset(token)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
DIGITS = _Digits()
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def verifiability(doc):
|
|
110
|
+
return current().verifiability(doc)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def subfield_name(sid):
|
|
114
|
+
return current().subfield_name(sid)
|
|
@@ -30,13 +30,13 @@ import html
|
|
|
30
30
|
import json
|
|
31
31
|
import re
|
|
32
32
|
|
|
33
|
-
from
|
|
34
|
-
from
|
|
35
|
-
from
|
|
36
|
-
from
|
|
37
|
-
from
|
|
38
|
-
from
|
|
39
|
-
from
|
|
33
|
+
from .format import DIGITS
|
|
34
|
+
from .format import interval as _interval
|
|
35
|
+
from .format import number as _num
|
|
36
|
+
from .format import statistic as _statistic
|
|
37
|
+
from .format import statistic_note as _stat_note
|
|
38
|
+
from .format import uncertainty as _uncertainty
|
|
39
|
+
from .format import value as _val
|
|
40
40
|
|
|
41
41
|
from . import refs as source_paper
|
|
42
42
|
from .mathml import to_mathml
|
|
@@ -326,9 +326,11 @@ class _Paper:
|
|
|
326
326
|
"""The platform's verifiability where the file lacks it (a submission being previewed)."""
|
|
327
327
|
if all("verifiability" in c for c in self.claims):
|
|
328
328
|
return {}
|
|
329
|
+
from . import format as fmt
|
|
329
330
|
try:
|
|
330
|
-
|
|
331
|
-
|
|
331
|
+
return fmt.verifiability(self.doc) or {}
|
|
332
|
+
except fmt.FormatError:
|
|
333
|
+
raise
|
|
332
334
|
except Exception: # noqa: BLE001 - a preview without lights is still a preview
|
|
333
335
|
return {}
|
|
334
336
|
|
|
@@ -5,27 +5,22 @@ draw the same page; the portal wraps it in its own chrome (header, footer, route
|
|
|
5
5
|
import json
|
|
6
6
|
import re
|
|
7
7
|
|
|
8
|
-
from claimset.subfields import SUBFIELDS
|
|
9
|
-
|
|
10
8
|
from . import page as pageview
|
|
11
9
|
from . import paper as paperview
|
|
10
|
+
from . import format as fmt
|
|
12
11
|
from . import refs, score_html
|
|
13
12
|
from . import text as textview
|
|
14
13
|
from .page import esc
|
|
15
14
|
from .text import html as plain_html
|
|
16
15
|
|
|
17
16
|
|
|
18
|
-
def _subfields():
|
|
19
|
-
return SUBFIELDS
|
|
20
|
-
|
|
21
|
-
|
|
22
17
|
def subfield_name(doc):
|
|
23
18
|
"""The name of the claimset's OpenAlex subfield (classification.subfield, `openalex:subfields/1803`), or None."""
|
|
24
19
|
c = doc["paper"].get("classification")
|
|
25
20
|
sub = c.get("subfield") if isinstance(c, dict) else None
|
|
26
21
|
if not isinstance(sub, str):
|
|
27
22
|
return None
|
|
28
|
-
return
|
|
23
|
+
return fmt.subfield_name(sub)
|
|
29
24
|
|
|
30
25
|
|
|
31
26
|
def _split_name(name):
|
|
@@ -4,17 +4,16 @@ or address of the published paper. Pure functions of the file; nothing here read
|
|
|
4
4
|
import re
|
|
5
5
|
import urllib.parse
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
_KEY_RE = re.compile(r"(\d{4})\.(\d{6,})$")
|
|
7
|
+
#: A claimset's identifier on EntryLib, provisional or as a DOI (claimset spec §7): what its addresses are made from.
|
|
8
|
+
ID_RE = re.compile(r"^(?:doi:10\.\d{4,9}/claimset\.|entrylib:)(\d{4})\.(\d{6,})$")
|
|
10
9
|
DOI = re.compile(r"^10\.\d{4,9}/\S+$")
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
def year_number(concept_id):
|
|
14
13
|
"""(year, number) of a claimset identifier, DOI or provisional."""
|
|
15
|
-
|
|
14
|
+
m = ID_RE.match(concept_id or "")
|
|
15
|
+
if not m:
|
|
16
16
|
raise ValueError(f"not a claimset identifier: {concept_id!r}")
|
|
17
|
-
m = _KEY_RE.search(concept_id)
|
|
18
17
|
return int(m.group(1)), int(m.group(2))
|
|
19
18
|
|
|
20
19
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: entrylib-pages
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: EntryLib's pages for a claimset: the paper view and the record, as entrylib.org shows them
|
|
5
5
|
Author: EntryLib
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -11,7 +11,6 @@ Classifier: Operating System :: OS Independent
|
|
|
11
11
|
Requires-Python: >=3.10
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
|
-
Requires-Dist: claimset>=0.45.1
|
|
15
14
|
Dynamic: license-file
|
|
16
15
|
|
|
17
16
|
# EntryLib pages
|
|
@@ -37,8 +36,11 @@ what the author sees is what will be published.
|
|
|
37
36
|
[EntryLib's rubric](https://github.com/entrylib/rubric), not here), the claims by kind, conflicts of interest, and
|
|
38
37
|
the sections of the page.
|
|
39
38
|
|
|
40
|
-
The format, its validation and the plain-text reading view for models belong to the `claimset` package
|
|
41
|
-
is EntryLib's presentation of it, with the site's stylesheet and script
|
|
39
|
+
The format, its validation and the plain-text reading view for models belong to the `claimset` package, which
|
|
40
|
+
depends on this one; this package is EntryLib's presentation of it, with the site's stylesheet and script, and imports
|
|
41
|
+
no claimset code. What a page needs of the format (how values are written, the verifiability the platform computes,
|
|
42
|
+
subfield names) is given by the caller as one object, `claimset.pages.FORMAT`
|
|
43
|
+
([format.py](https://github.com/entrylib/pages/blob/main/src/entrylib_pages/format.py) describes it).
|
|
42
44
|
|
|
43
45
|
## Install
|
|
44
46
|
|
|
@@ -46,7 +48,8 @@ is EntryLib's presentation of it, with the site's stylesheet and script.
|
|
|
46
48
|
pip install entrylib-pages
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
It needs Python 3.10 or later and
|
|
51
|
+
It needs Python 3.10 or later and nothing else; `pip install claimset` installs it too. In Python, import it as
|
|
52
|
+
`entrylib_pages`.
|
|
50
53
|
|
|
51
54
|
## Use
|
|
52
55
|
|
|
@@ -63,16 +66,19 @@ From Python:
|
|
|
63
66
|
```python
|
|
64
67
|
import json
|
|
65
68
|
import entrylib_pages
|
|
69
|
+
from claimset.pages import FORMAT # what a page needs of the claimset format
|
|
66
70
|
|
|
67
71
|
doc = json.load(open("paper.claimset.json"))
|
|
68
|
-
html = entrylib_pages.preview_html(doc)
|
|
69
|
-
html = entrylib_pages.preview_html(doc, view="record")
|
|
72
|
+
html = entrylib_pages.preview_html(doc, fmt=FORMAT) # the paper view, as one self-contained page
|
|
73
|
+
html = entrylib_pages.preview_html(doc, fmt=FORMAT, view="record") # the record
|
|
70
74
|
```
|
|
71
75
|
|
|
72
|
-
- `entrylib_pages.preview_html(doc, scores=None, view="paper", note="", paper_href=…, record_href=…)`: the page,
|
|
76
|
+
- `entrylib_pages.preview_html(doc, fmt=None, scores=None, view="paper", note="", paper_href=…, record_href=…)`: the page,
|
|
73
77
|
with the site's stylesheets and script inlined. Figures the claimset names by relative path (`files/figures/a.png`)
|
|
74
78
|
are shown from beside the page, so write it in the folder that holds the claimset and its files; figures already
|
|
75
79
|
published on EntryLib are shown from there. `scores`: the rubric's, if the caller has them.
|
|
80
|
+
- `entrylib_pages.use(fmt)`: the format every page of the process is drawn with (the portal calls it once); `fmt`
|
|
81
|
+
given to `preview_html` overrides it.
|
|
76
82
|
- `entrylib_pages.stylesheet()`: the page view's stylesheet (`claimset.css`).
|
|
77
83
|
- `entrylib_pages.__version__`: the version of the pages.
|
|
78
84
|
|
|
@@ -2,6 +2,7 @@ LICENSE
|
|
|
2
2
|
README.md
|
|
3
3
|
pyproject.toml
|
|
4
4
|
src/entrylib_pages/__init__.py
|
|
5
|
+
src/entrylib_pages/format.py
|
|
5
6
|
src/entrylib_pages/mathml.py
|
|
6
7
|
src/entrylib_pages/page.py
|
|
7
8
|
src/entrylib_pages/page_css.py
|
|
@@ -14,7 +15,6 @@ src/entrylib_pages/text.py
|
|
|
14
15
|
src/entrylib_pages.egg-info/PKG-INFO
|
|
15
16
|
src/entrylib_pages.egg-info/SOURCES.txt
|
|
16
17
|
src/entrylib_pages.egg-info/dependency_links.txt
|
|
17
|
-
src/entrylib_pages.egg-info/requires.txt
|
|
18
18
|
src/entrylib_pages.egg-info/top_level.txt
|
|
19
19
|
src/entrylib_pages/static/page.js
|
|
20
20
|
src/entrylib_pages/static/site.css
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""entrylib-pages: the claimset's page as EntryLib shows it, as one HTML document (preview_html), drawn with the claimset
|
|
2
|
+
format the caller gives (entrylib_pages.format). These tests give a stand-in format: the package needs nothing else."""
|
|
3
|
+
|
|
4
|
+
import contextvars
|
|
5
|
+
import json
|
|
6
|
+
import unittest
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
import entrylib_pages
|
|
10
|
+
from entrylib_pages import format as fmt
|
|
11
|
+
|
|
12
|
+
EXAMPLE = json.loads((Path(__file__).parent / "example.json").read_text(encoding="utf-8"))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class StandIn:
|
|
16
|
+
"""What a page takes from the claimset format, written plainly (claimset.pages.FORMAT is the real one)."""
|
|
17
|
+
DIGITS = contextvars.ContextVar("stand_in_digits", default=None)
|
|
18
|
+
|
|
19
|
+
def __init__(self):
|
|
20
|
+
self.asked = []
|
|
21
|
+
|
|
22
|
+
def number(self, v):
|
|
23
|
+
return str(v)
|
|
24
|
+
|
|
25
|
+
def interval(self, iv):
|
|
26
|
+
return f"[{iv.get('lower')}, {iv.get('upper')}]" if isinstance(iv, dict) else ""
|
|
27
|
+
|
|
28
|
+
def uncertainty(self, unc):
|
|
29
|
+
return ""
|
|
30
|
+
|
|
31
|
+
def value(self, v):
|
|
32
|
+
return str(v)
|
|
33
|
+
|
|
34
|
+
def statistic(self, st):
|
|
35
|
+
return str(st.get("value")) if isinstance(st, dict) else ""
|
|
36
|
+
|
|
37
|
+
def statistic_note(self, obj):
|
|
38
|
+
return ""
|
|
39
|
+
|
|
40
|
+
def verifiability(self, doc):
|
|
41
|
+
self.asked.append("verifiability")
|
|
42
|
+
return {c["id"]: "reproducible" for c in doc.get("claims") or [] if isinstance(c, dict)}
|
|
43
|
+
|
|
44
|
+
def subfield_name(self, sid):
|
|
45
|
+
return "Statistics and Probability" if sid.endswith("/2613") else None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class TestPreview(unittest.TestCase):
|
|
49
|
+
def setUp(self):
|
|
50
|
+
self.fmt = StandIn()
|
|
51
|
+
|
|
52
|
+
def test_the_paper_view_as_one_document(self):
|
|
53
|
+
html = entrylib_pages.preview_html(EXAMPLE, fmt=self.fmt)
|
|
54
|
+
self.assertTrue(html.startswith("<!doctype html>"))
|
|
55
|
+
self.assertIn("Preview, not submitted.", html)
|
|
56
|
+
self.assertIn('data-view="paper"', html)
|
|
57
|
+
self.assertIn('<article class="pv-claim"', html)
|
|
58
|
+
self.assertIn(".pv-toc", html) # the site's stylesheet, inlined
|
|
59
|
+
self.assertIn("<script>", html) # and its script
|
|
60
|
+
self.assertNotIn('href="/site.css', html) # nothing fetched from the site
|
|
61
|
+
|
|
62
|
+
def test_the_record_and_the_two_views_by_file(self):
|
|
63
|
+
html = entrylib_pages.preview_html(EXAMPLE, fmt=self.fmt, view="record", paper_href="p.html",
|
|
64
|
+
record_href="r.html")
|
|
65
|
+
self.assertIn('id="principal"', html)
|
|
66
|
+
self.assertIn('href="p.html"', html)
|
|
67
|
+
self.assertIn('href="r.html" aria-current="page"', html)
|
|
68
|
+
|
|
69
|
+
def test_what_the_format_gives_is_what_the_page_shows(self):
|
|
70
|
+
doc = json.loads(json.dumps(EXAMPLE))
|
|
71
|
+
for c in doc["claims"]:
|
|
72
|
+
c.pop("verifiability", None) # a file not yet published
|
|
73
|
+
doc["paper"]["classification"] = {"subfield": "openalex:subfields/2613"}
|
|
74
|
+
html = entrylib_pages.preview_html(doc, fmt=self.fmt)
|
|
75
|
+
self.assertIn("verifiability", self.fmt.asked) # the lights come from the format
|
|
76
|
+
self.assertIn("Statistics and Probability", html) # and the subfield's name
|
|
77
|
+
|
|
78
|
+
def test_without_a_format_it_says_which_to_give(self):
|
|
79
|
+
with self.assertRaises(entrylib_pages.FormatError) as e:
|
|
80
|
+
entrylib_pages.preview_html(EXAMPLE)
|
|
81
|
+
self.assertIn("claimset.pages.FORMAT", str(e.exception))
|
|
82
|
+
with self.assertRaises(entrylib_pages.FormatError):
|
|
83
|
+
entrylib_pages.preview_html(EXAMPLE, fmt=object()) # one that lacks what a page needs
|
|
84
|
+
|
|
85
|
+
def test_use_sets_the_format_for_every_page(self):
|
|
86
|
+
try:
|
|
87
|
+
entrylib_pages.use(self.fmt)
|
|
88
|
+
self.assertIn('data-view="paper"', entrylib_pages.preview_html(EXAMPLE))
|
|
89
|
+
finally:
|
|
90
|
+
fmt._default = None
|
|
91
|
+
|
|
92
|
+
def test_figures_by_relative_path_or_already_on_entrylib(self):
|
|
93
|
+
self.assertEqual(entrylib_pages.file_url({"uri": "files/figures/a.png"}), "files/figures/a.png")
|
|
94
|
+
published = "https://entrylib.org/p/2026.000009/v5/files/files/figures/a.png"
|
|
95
|
+
self.assertEqual(entrylib_pages.file_url({"uri": published}), published)
|
|
96
|
+
for uri in ("https://example.org/a.png", "../a.png", "/etc/a.png", "files/data.csv"):
|
|
97
|
+
self.assertIsNone(entrylib_pages.file_url({"uri": uri}), uri)
|
|
98
|
+
|
|
99
|
+
def test_a_note_under_the_bar(self):
|
|
100
|
+
html = entrylib_pages.preview_html(EXAMPLE, fmt=self.fmt, note="<p>Made by claimset preview.</p>")
|
|
101
|
+
self.assertIn("<p>Made by claimset preview.</p>", html)
|
|
102
|
+
|
|
103
|
+
def test_no_claimset_code_is_imported(self):
|
|
104
|
+
src = Path(entrylib_pages.__file__).parent
|
|
105
|
+
for f in src.glob("*.py"):
|
|
106
|
+
text = f.read_text(encoding="utf-8")
|
|
107
|
+
self.assertNotRegex(text, r"(?m)^\s*(from claimset|import claimset)", f.name)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
if __name__ == "__main__":
|
|
111
|
+
unittest.main()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
claimset>=0.45.1
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"""entrylib-pages: the claimset's page as EntryLib shows it, as one HTML document (preview_html)."""
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
import unittest
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
|
|
7
|
-
import claimset
|
|
8
|
-
|
|
9
|
-
import entrylib_pages
|
|
10
|
-
|
|
11
|
-
EXAMPLE = Path(claimset.__file__).parent / "data" / "examples" / "submission-native.json"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class TestPreview(unittest.TestCase):
|
|
15
|
-
def setUp(self):
|
|
16
|
-
self.doc = json.loads(EXAMPLE.read_text(encoding="utf-8"))
|
|
17
|
-
|
|
18
|
-
def test_the_paper_view_as_one_document(self):
|
|
19
|
-
html = entrylib_pages.preview_html(self.doc)
|
|
20
|
-
self.assertTrue(html.startswith("<!doctype html>"))
|
|
21
|
-
self.assertIn("Preview, not submitted.", html)
|
|
22
|
-
self.assertIn('data-view="paper"', html)
|
|
23
|
-
self.assertIn('<article class="pv-claim"', html)
|
|
24
|
-
self.assertIn(".pv-toc", html) # the site's stylesheet, inlined
|
|
25
|
-
self.assertIn("<script>", html) # and its script
|
|
26
|
-
self.assertNotIn('href="/site.css', html) # nothing fetched from the site
|
|
27
|
-
|
|
28
|
-
def test_the_record_and_the_two_views_by_file(self):
|
|
29
|
-
html = entrylib_pages.preview_html(self.doc, view="record", paper_href="p.html", record_href="r.html")
|
|
30
|
-
self.assertIn('id="principal"', html)
|
|
31
|
-
self.assertIn('href="p.html"', html)
|
|
32
|
-
self.assertIn('href="r.html" aria-current="page"', html)
|
|
33
|
-
|
|
34
|
-
def test_figures_by_relative_path_or_already_on_entrylib(self):
|
|
35
|
-
self.assertEqual(entrylib_pages.file_url({"uri": "files/figures/a.png"}), "files/figures/a.png")
|
|
36
|
-
published = "https://entrylib.org/p/2026.000009/v5/files/files/figures/a.png"
|
|
37
|
-
self.assertEqual(entrylib_pages.file_url({"uri": published}), published)
|
|
38
|
-
for uri in ("https://example.org/a.png", "../a.png", "/etc/a.png", "files/data.csv"):
|
|
39
|
-
self.assertIsNone(entrylib_pages.file_url({"uri": uri}), uri)
|
|
40
|
-
|
|
41
|
-
def test_a_note_under_the_bar(self):
|
|
42
|
-
html = entrylib_pages.preview_html(self.doc, note="<p>Made by claimset preview.</p>")
|
|
43
|
-
self.assertIn("<p>Made by claimset preview.</p>", html)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if __name__ == "__main__":
|
|
47
|
-
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{entrylib_pages-0.1.0 → entrylib_pages-0.2.0}/src/entrylib_pages.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|