refkit 0.0.5__cp311-abi3-win_amd64.whl

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.
refkit/__init__.py ADDED
@@ -0,0 +1,134 @@
1
+ """Citation parsing, rendering, and BibTeX editing."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from importlib.metadata import version as _metadata_version
6
+ from os import PathLike
7
+
8
+ from . import _native as _core
9
+
10
+ __version__ = _metadata_version("refkit")
11
+
12
+
13
+ def _ensure_native_version() -> None:
14
+ if _core.__version__ == __version__:
15
+ return
16
+ raise SystemError(
17
+ f"The installed refkit extension version ({_core.__version__}) is incompatible "
18
+ f"with refkit {__version__}. Reinstall refkit from one release."
19
+ )
20
+
21
+
22
+ _ensure_native_version()
23
+
24
+ BibDocument = _core.BibDocument
25
+ BibEntry = _core.BibEntry
26
+ BibEntryMap = _core.BibEntryMap
27
+ BibField = _core.BibField
28
+ BibFieldMap = _core.BibFieldMap
29
+ Citation = _core.Citation
30
+ CitationGroup = _core.CitationGroup
31
+ Cite = _core.Cite
32
+ Document = _core.Document
33
+ Entry = _core.Entry
34
+ Library = _core.Library
35
+ Locale = _core.Locale
36
+ MissingReferenceError = _core.MissingReferenceError
37
+ RefkitError = _core.RefkitError
38
+ Rendered = _core.Rendered
39
+ RenderedDocument = _core.RenderedDocument
40
+ Style = _core.Style
41
+ TidyError = _core.TidyError
42
+ TidyOptions = _core.TidyOptions
43
+ TidyResult = _core.TidyResult
44
+ TidySyntaxError = _core.TidySyntaxError
45
+ TidyWarning = _core.TidyWarning
46
+ build_info = _core.build_info
47
+ build_mode = _core.build_mode
48
+
49
+ __all__ = [
50
+ "BibDocument",
51
+ "BibEntry",
52
+ "BibEntryMap",
53
+ "BibField",
54
+ "BibFieldMap",
55
+ "Citation",
56
+ "Cite",
57
+ "CitationGroup",
58
+ "RefkitError",
59
+ "Document",
60
+ "Entry",
61
+ "Library",
62
+ "Locale",
63
+ "MissingReferenceError",
64
+ "Rendered",
65
+ "RenderedDocument",
66
+ "Style",
67
+ "TidyError",
68
+ "TidyOptions",
69
+ "TidyResult",
70
+ "TidySyntaxError",
71
+ "TidyWarning",
72
+ "build_info",
73
+ "build_mode",
74
+ "cite",
75
+ "full_bibliography",
76
+ "tidy_bibtex",
77
+ "tidy_file",
78
+ "__version__",
79
+ ]
80
+
81
+
82
+ def tidy_bibtex(
83
+ source: str,
84
+ *,
85
+ options: TidyOptions | None = None,
86
+ ) -> TidyResult:
87
+ """Format BibTeX text and return the formatted source plus warnings."""
88
+
89
+ return _core.tidy_bibtex(source, options=options)
90
+
91
+
92
+ def tidy_file(
93
+ path: str | PathLike[str],
94
+ *,
95
+ output: str | PathLike[str] | None = None,
96
+ options: TidyOptions | None = None,
97
+ ) -> TidyResult:
98
+ """Read a BibTeX file, format it, and write the result when `output` is set."""
99
+
100
+ result = BibDocument.read(path).tidy(options=options)
101
+ if output is not None:
102
+ _core._write_bibtex(output, result.bibtex)
103
+ return result
104
+
105
+
106
+ def cite(
107
+ source: str | PathLike[str],
108
+ citation: str | Cite | CitationGroup,
109
+ *,
110
+ style: str | Style = "apa",
111
+ locale: str | Locale | None = "en-US",
112
+ ) -> Rendered:
113
+ """Read `source` and render one citation."""
114
+
115
+ library = Library.read(source)
116
+ loaded_style = Style.load(style) if isinstance(style, str) else style
117
+ rendered = Document(library, loaded_style, locale=locale).render(
118
+ [Citation("citation", citation)]
119
+ )
120
+ return rendered["citation"]
121
+
122
+
123
+ def full_bibliography(
124
+ source: str | PathLike[str],
125
+ *,
126
+ style: str | Style = "apa",
127
+ locale: str | Locale | None = "en-US",
128
+ ) -> Rendered:
129
+ """Read `source` and render every entry as a bibliography."""
130
+
131
+ library = Library.read(source)
132
+ loaded_style = Style.load(style) if isinstance(style, str) else style
133
+ document = Document(library, loaded_style, locale=locale)
134
+ return document.full_bibliography()
refkit/__init__.pyi ADDED
@@ -0,0 +1,87 @@
1
+ from os import PathLike
2
+
3
+ from ._native import (
4
+ BibDocument,
5
+ BibEntry,
6
+ BibEntryMap,
7
+ BibField,
8
+ BibFieldMap,
9
+ Citation,
10
+ CitationGroup,
11
+ Cite,
12
+ Document,
13
+ Entry,
14
+ Library,
15
+ Locale,
16
+ MissingReferenceError,
17
+ RefkitError,
18
+ Rendered,
19
+ RenderedDocument,
20
+ Style,
21
+ TidyError,
22
+ TidyOptions,
23
+ TidyResult,
24
+ TidySyntaxError,
25
+ TidyWarning,
26
+ build_info,
27
+ build_mode,
28
+ )
29
+
30
+ __all__ = [
31
+ "BibDocument",
32
+ "BibEntry",
33
+ "BibEntryMap",
34
+ "BibField",
35
+ "BibFieldMap",
36
+ "Citation",
37
+ "Cite",
38
+ "CitationGroup",
39
+ "RefkitError",
40
+ "Document",
41
+ "Entry",
42
+ "Library",
43
+ "Locale",
44
+ "MissingReferenceError",
45
+ "Rendered",
46
+ "RenderedDocument",
47
+ "Style",
48
+ "TidyError",
49
+ "TidyOptions",
50
+ "TidyResult",
51
+ "TidySyntaxError",
52
+ "TidyWarning",
53
+ "build_info",
54
+ "build_mode",
55
+ "cite",
56
+ "full_bibliography",
57
+ "tidy_bibtex",
58
+ "tidy_file",
59
+ "__version__",
60
+ ]
61
+
62
+ __version__: str
63
+
64
+ def tidy_bibtex(
65
+ source: str,
66
+ *,
67
+ options: TidyOptions | None = None,
68
+ ) -> TidyResult: ...
69
+ def tidy_file(
70
+ path: str | PathLike[str],
71
+ *,
72
+ output: str | PathLike[str] | None = None,
73
+ options: TidyOptions | None = None,
74
+ ) -> TidyResult: ...
75
+ def cite(
76
+ source: str | PathLike[str],
77
+ citation: str | Cite | CitationGroup,
78
+ *,
79
+ style: str | Style = "apa",
80
+ locale: str | Locale | None = "en-US",
81
+ ) -> Rendered: ...
82
+ def full_bibliography(
83
+ source: str | PathLike[str],
84
+ *,
85
+ style: str | Style = "apa",
86
+ locale: str | Locale | None = "en-US",
87
+ ) -> Rendered: ...
refkit/_native.pyd ADDED
Binary file
refkit/_native.pyi ADDED
@@ -0,0 +1,352 @@
1
+ from collections.abc import Iterable
2
+ from os import PathLike
3
+ from typing import Literal, TypeAlias, TypedDict
4
+
5
+ class _ProjectionRow(TypedDict, total=False):
6
+ key: str
7
+ entry_type: str
8
+ type: str
9
+ title: str | None
10
+ date: str | None
11
+ doi: str | None
12
+ volume: str | None
13
+
14
+ class _TreeFormatting(TypedDict):
15
+ font_style: str
16
+ font_variant: str
17
+ font_weight: str
18
+ text_decoration: str
19
+ vertical_align: str
20
+
21
+ class _TreeText(TypedDict):
22
+ kind: Literal["Text"]
23
+ text: str
24
+ formatting: _TreeFormatting
25
+
26
+ class _TreeElement(TypedDict):
27
+ kind: Literal["Element"]
28
+ display: str | None
29
+ meta: str | None
30
+ children: list[_TreeNode]
31
+
32
+ class _TreeMarkup(TypedDict):
33
+ kind: Literal["Markup"]
34
+ value: str
35
+
36
+ class _TreeLink(TypedDict):
37
+ kind: Literal["Link"]
38
+ text: str
39
+ url: str
40
+ formatting: _TreeFormatting
41
+
42
+ class _TreeTransparent(TypedDict):
43
+ kind: Literal["Transparent"]
44
+ cite_idx: int
45
+ format: str
46
+
47
+ _TreeNode: TypeAlias = _TreeText | _TreeElement | _TreeMarkup | _TreeLink | _TreeTransparent
48
+
49
+ class _BibliographyEntry(TypedDict):
50
+ kind: Literal["bibliography-entry"]
51
+ key: str
52
+ first_field: _TreeNode | None
53
+ children: list[_TreeNode]
54
+
55
+ _RenderedTree: TypeAlias = list[_TreeNode | _BibliographyEntry]
56
+ _RawSpan: TypeAlias = list[int]
57
+
58
+ class _RawWhitespaceBlock(TypedDict):
59
+ kind: Literal["whitespace"]
60
+ span: _RawSpan
61
+
62
+ class _RawCommentBlock(TypedDict):
63
+ kind: Literal["comment"]
64
+ raw: str
65
+ span: _RawSpan
66
+
67
+ class _RawPreambleBlock(TypedDict):
68
+ kind: Literal["preamble"]
69
+ value: str
70
+ span: _RawSpan
71
+
72
+ class _RawStringBlock(TypedDict):
73
+ kind: Literal["string"]
74
+ key: str
75
+ value: str
76
+ span: _RawSpan
77
+
78
+ class _RawEntryBlock(TypedDict):
79
+ kind: Literal["entry"]
80
+ id: int
81
+ key: str
82
+ span: _RawSpan
83
+
84
+ class _RawFailedBlock(TypedDict):
85
+ kind: Literal["failed"]
86
+ raw: str
87
+ error: str
88
+ span: _RawSpan
89
+
90
+ class _RawOtherBlock(TypedDict):
91
+ kind: Literal["other"]
92
+ raw: str
93
+ span: _RawSpan
94
+
95
+ _RawBlock: TypeAlias = (
96
+ _RawWhitespaceBlock
97
+ | _RawCommentBlock
98
+ | _RawPreambleBlock
99
+ | _RawStringBlock
100
+ | _RawEntryBlock
101
+ | _RawFailedBlock
102
+ | _RawOtherBlock
103
+ )
104
+
105
+ __version__: str
106
+ build_info: str
107
+ build_mode: Literal["debug", "release"]
108
+ _tidy_option_names: list[str]
109
+ _RecoveryPolicy: TypeAlias = Literal["error", "report"]
110
+ _DuplicateRule: TypeAlias = Literal["doi", "key", "abstract", "citation"]
111
+ _MergeStrategy: TypeAlias = Literal["first", "last", "combine", "overwrite"]
112
+
113
+ class RefkitError(Exception): ...
114
+ class MissingReferenceError(RefkitError): ...
115
+ class TidyError(RefkitError): ...
116
+
117
+ class TidySyntaxError(TidyError):
118
+ line: int
119
+ column: int
120
+ byte: int
121
+ character: str | None
122
+ message: str
123
+
124
+ class TidyOptions:
125
+ def __init__(
126
+ self,
127
+ *,
128
+ omit: Iterable[str] | None = None,
129
+ curly: bool = False,
130
+ numeric: bool = False,
131
+ months: bool = False,
132
+ space: int = 2,
133
+ tab: bool = False,
134
+ align: bool | int | None = 14,
135
+ blank_lines: bool = False,
136
+ sort: bool | Iterable[str] | None = None,
137
+ duplicates: Iterable[_DuplicateRule] | None = None,
138
+ merge: _MergeStrategy | None = None,
139
+ strip_enclosing_braces: bool = False,
140
+ drop_all_caps: bool = False,
141
+ escape: bool = True,
142
+ sort_fields: bool | Iterable[str] | None = None,
143
+ strip_comments: bool = False,
144
+ trailing_commas: bool = False,
145
+ encode_urls: bool = False,
146
+ tidy_comments: bool = True,
147
+ remove_empty_fields: bool = False,
148
+ remove_duplicate_fields: bool = True,
149
+ generate_keys: bool | str | None = None,
150
+ max_authors: int | None = None,
151
+ lowercase: bool = True,
152
+ enclosing_braces: bool | Iterable[str] | None = None,
153
+ remove_braces: bool | Iterable[str] | None = None,
154
+ wrap: bool | int | None = None,
155
+ ) -> None: ...
156
+
157
+ class TidyWarning:
158
+ @property
159
+ def code(self) -> Literal["missing_key", "duplicate_entry"]: ...
160
+ @property
161
+ def rule(self) -> _DuplicateRule | None: ...
162
+ @property
163
+ def message(self) -> str: ...
164
+
165
+ class TidyResult:
166
+ @property
167
+ def bibtex(self) -> str: ...
168
+ @property
169
+ def warnings(self) -> list[TidyWarning]: ...
170
+ @property
171
+ def count(self) -> int: ...
172
+
173
+ def tidy_bibtex(source: str, *, options: TidyOptions | None = None) -> TidyResult: ...
174
+ def _write_bibtex(path: str | PathLike[str], source: str) -> None: ...
175
+
176
+ class Entry:
177
+ @property
178
+ def key(self) -> str: ...
179
+ @property
180
+ def entry_type(self) -> str: ...
181
+ @property
182
+ def title(self) -> str | None: ...
183
+ @property
184
+ def date(self) -> str | None: ...
185
+ @property
186
+ def parents(self) -> list[Entry]: ...
187
+ @property
188
+ def volume(self) -> str | None: ...
189
+ @property
190
+ def doi(self) -> str | None: ...
191
+
192
+ class Library:
193
+ @staticmethod
194
+ def read(path: str | PathLike[str], *, recovery: _RecoveryPolicy = "error") -> Library: ...
195
+ @staticmethod
196
+ def parse_bibtex(
197
+ source: str,
198
+ *,
199
+ recovery: _RecoveryPolicy = "error",
200
+ ) -> Library: ...
201
+ @staticmethod
202
+ def parse_yaml(source: str) -> Library: ...
203
+ @property
204
+ def diagnostics(self) -> list[str]: ...
205
+ def keys(self) -> list[str]: ...
206
+ def get_many(self, keys: Iterable[str]) -> list[Entry]: ...
207
+ def values(self) -> list[Entry]: ...
208
+ def get(self, key: str) -> Entry | None: ...
209
+ def is_empty(self) -> bool: ...
210
+ def select(self, selector: str) -> list[Entry]: ...
211
+ def project(
212
+ self, fields: Iterable[str] | None = None, *, keys: Iterable[str] | None = None
213
+ ) -> list[_ProjectionRow]: ...
214
+ def __len__(self) -> int: ...
215
+ def __bool__(self) -> bool: ...
216
+ def __contains__(self, key: str) -> bool: ...
217
+ def __getitem__(self, key: str) -> Entry: ...
218
+
219
+ class Style:
220
+ @staticmethod
221
+ def load(name: str) -> Style: ...
222
+ @staticmethod
223
+ def from_xml(xml: str) -> Style: ...
224
+ @staticmethod
225
+ def from_path(path: str | PathLike[str]) -> Style: ...
226
+ @property
227
+ def id(self) -> str: ...
228
+ @property
229
+ def title(self) -> str: ...
230
+
231
+ class Locale:
232
+ @staticmethod
233
+ def load(code: str) -> Locale: ...
234
+ @property
235
+ def code(self) -> str: ...
236
+
237
+ class Cite:
238
+ def __init__(
239
+ self, key: str, *, locator: str | None = None, label: str | None = None
240
+ ) -> None: ...
241
+ @property
242
+ def key(self) -> str: ...
243
+ @property
244
+ def locator(self) -> str | None: ...
245
+ @property
246
+ def label(self) -> str | None: ...
247
+
248
+ class CitationGroup:
249
+ def __init__(self, items: Iterable[str | Cite]) -> None: ...
250
+ @property
251
+ def items(self) -> list[Cite]: ...
252
+ def __len__(self) -> int: ...
253
+
254
+ class Citation:
255
+ def __init__(self, id: str, citation: str | Cite | CitationGroup) -> None: ...
256
+ @property
257
+ def id(self) -> str: ...
258
+ @property
259
+ def group(self) -> CitationGroup: ...
260
+
261
+ class Rendered:
262
+ @property
263
+ def text(self) -> str: ...
264
+ @property
265
+ def html(self) -> str: ...
266
+ @property
267
+ def tree(self) -> _RenderedTree: ...
268
+ def to_text(self) -> str: ...
269
+ def to_html(self) -> str: ...
270
+ def to_tree(self) -> _RenderedTree: ...
271
+
272
+ class RenderedDocument:
273
+ @property
274
+ def citation_order(self) -> list[str]: ...
275
+ @property
276
+ def citations(self) -> dict[str, Rendered]: ...
277
+ @property
278
+ def bibliography(self) -> Rendered: ...
279
+ def __getitem__(self, id: str) -> Rendered: ...
280
+
281
+ class Document:
282
+ def __init__(
283
+ self, library: Library, style: Style, *, locale: str | Locale | None = None
284
+ ) -> None: ...
285
+ def render(self, citations: Iterable[Citation]) -> RenderedDocument: ...
286
+ def cited_bibliography(self, citations: Iterable[Citation]) -> Rendered: ...
287
+ def full_bibliography(self) -> Rendered: ...
288
+
289
+ class BibField:
290
+ @property
291
+ def name(self) -> str: ...
292
+ @property
293
+ def value(self) -> str: ...
294
+ @value.setter
295
+ def value(self, value: str) -> None: ...
296
+ @property
297
+ def span(self) -> tuple[int, int]: ...
298
+
299
+ class BibFieldMap:
300
+ def unique_keys(self) -> list[str]: ...
301
+ def occurrence_keys(self) -> list[str]: ...
302
+ def occurrences(self) -> list[BibField]: ...
303
+ def get_all(self, key: str) -> list[BibField]: ...
304
+ def is_empty(self) -> bool: ...
305
+ def get_unique(self, key: str) -> BibField | None: ...
306
+ def __len__(self) -> int: ...
307
+ def __bool__(self) -> bool: ...
308
+ def __contains__(self, key: str) -> bool: ...
309
+ def __getitem__(self, key: str) -> BibField: ...
310
+
311
+ class BibEntry:
312
+ @property
313
+ def key(self) -> str: ...
314
+ @property
315
+ def kind(self) -> str: ...
316
+ @property
317
+ def fields(self) -> BibFieldMap: ...
318
+ @property
319
+ def span(self) -> tuple[int, int]: ...
320
+
321
+ class BibEntryMap:
322
+ def unique_keys(self) -> list[str]: ...
323
+ def occurrence_keys(self) -> list[str]: ...
324
+ def occurrences(self) -> list[BibEntry]: ...
325
+ def get_all(self, key: str) -> list[BibEntry]: ...
326
+ def is_empty(self) -> bool: ...
327
+ def get_unique(self, key: str) -> BibEntry | None: ...
328
+ def __len__(self) -> int: ...
329
+ def __bool__(self) -> bool: ...
330
+ def __contains__(self, key: str) -> bool: ...
331
+ def __getitem__(self, key: str) -> BibEntry: ...
332
+
333
+ class BibDocument:
334
+ @staticmethod
335
+ def read(path: str | PathLike[str]) -> BibDocument: ...
336
+ @staticmethod
337
+ def parse(source: str) -> BibDocument: ...
338
+ @property
339
+ def entries(self) -> BibEntryMap: ...
340
+ @property
341
+ def comments(self) -> list[str]: ...
342
+ @property
343
+ def preamble(self) -> str: ...
344
+ @property
345
+ def strings(self) -> dict[str, str]: ...
346
+ @property
347
+ def failed_blocks(self) -> list[_RawFailedBlock]: ...
348
+ @property
349
+ def blocks(self) -> list[_RawBlock]: ...
350
+ def to_bibtex(self) -> str: ...
351
+ def tidy(self, *, options: TidyOptions | None = None) -> TidyResult: ...
352
+ def write(self, path: str | PathLike[str]) -> None: ...