17
17
"""
18
18
19
19
import math
20
- import os . path
21
- from typing import TYPE_CHECKING , Dict , List , NamedTuple , Set
20
+ from pathlib import Path
21
+ from typing import Dict , List , NamedTuple , Set
22
22
23
23
from docutils .nodes import make_id
24
24
from pybtex .database import BibliographyData , BibliographyDataError
25
25
from pybtex .database .input .bibtex import Parser
26
26
from sphinx .util .logging import getLogger
27
27
28
- if TYPE_CHECKING :
29
- from sphinx .environment import BuildEnvironment
30
-
31
28
32
29
logger = getLogger (__name__ )
33
30
@@ -43,30 +40,25 @@ class BibData(NamedTuple):
43
40
"""Contains information about a collection of bib files."""
44
41
45
42
encoding : str #: Encoding of all bib files.
46
- bibfiles : Dict [str , BibFile ] #: Maps bib filename to information about it.
43
+ bibfiles : Dict [Path , BibFile ] #: Maps bib filename to information about it.
47
44
data : BibliographyData #: Data parsed from all bib files.
48
45
49
46
50
- def normpath_filename (env : "BuildEnvironment" , filename : str ) -> str :
51
- """Return normalised path to *filename* for the given environment *env*."""
52
- return os .path .normpath (env .relfn2path (filename .strip ())[1 ])
53
-
54
-
55
- def get_mtime (bibfilename : str ) -> float :
47
+ def get_mtime (bibfilename : Path ) -> float :
56
48
try :
57
- return os . path . getmtime ( bibfilename )
49
+ return bibfilename . lstat (). st_mtime
58
50
except OSError :
59
51
return - math .inf
60
52
61
53
62
- def parse_bibdata (bibfilenames : List [str ], encoding : str ) -> BibData :
54
+ def parse_bibdata (bibfilenames : List [Path ], encoding : str ) -> BibData :
63
55
"""Parse *bibfilenames* with given *encoding*, and return parsed data."""
64
56
parser = Parser (encoding )
65
- bibfiles : Dict [str , BibFile ] = {}
57
+ bibfiles : Dict [Path , BibFile ] = {}
66
58
keys : Dict [str , None ] = {}
67
59
for filename in bibfilenames :
68
60
logger .info ("parsing bibtex file {0}... " .format (filename ), nonl = True )
69
- if not os . path . isfile ( filename ):
61
+ if not filename . is_file ( ):
70
62
logger .warning (
71
63
"could not open bibtex file {0}." .format (filename ),
72
64
type = "bibtex" ,
@@ -91,7 +83,7 @@ def parse_bibdata(bibfilenames: List[str], encoding: str) -> BibData:
91
83
92
84
93
85
def is_bibdata_outdated (
94
- bibdata : BibData , bibfilenames : List [str ], encoding : str
86
+ bibdata : BibData , bibfilenames : List [Path ], encoding : str
95
87
) -> bool :
96
88
return (
97
89
bibdata .encoding != encoding
@@ -104,7 +96,7 @@ def is_bibdata_outdated(
104
96
105
97
106
98
def process_bibdata (
107
- bibdata : BibData , bibfilenames : List [str ], encoding : str
99
+ bibdata : BibData , bibfilenames : List [Path ], encoding : str
108
100
) -> BibData :
109
101
"""Parse *bibfilenames* and store parsed data in *bibdata*."""
110
102
logger .info ("checking bibtex cache... " , nonl = True )
0 commit comments