File tree 6 files changed +26
-11
lines changed
6 files changed +26
-11
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,6 @@ dependencies = [
62
62
" palettable>=3.3.3" ,
63
63
" pandas>=2" ,
64
64
" plotly>=4.5.0,<6.0.0" ,
65
- " pybtex>=0.24.0" ,
66
65
" requests>=2.32" ,
67
66
" ruamel.yaml>=0.17.0" ,
68
67
# scipy<1.14.1 is incompatible with NumPy 2.0 on Windows
@@ -110,6 +109,7 @@ optional = [
110
109
" matplotlib>=3.8" ,
111
110
" openbabel-wheel>=3.1.1.20" ,
112
111
" phonopy>=2.33.3" ,
112
+ " pybtex>=0.24.0" , # TODO: don't work on MacOS Python 3.13
113
113
" seekpath>=2.0.1" ,
114
114
]
115
115
# moyopy[interface] includes ase
Original file line number Diff line number Diff line change @@ -1357,8 +1357,8 @@ def get_bibtex_string(self) -> str:
1357
1357
"""
1358
1358
try :
1359
1359
from pybtex .database import BibliographyData , Entry
1360
- except ImportError :
1361
- raise RuntimeError ("Bibliographic data extraction requires pybtex." )
1360
+ except ImportError as exc :
1361
+ raise RuntimeError ("Bibliographic data extraction requires pybtex." ) from exc
1362
1362
1363
1363
bibtex_keys : dict [str , tuple [str , ...]] = {
1364
1364
"author" : ("_publ_author_name" , "_citation_author_name" ),
Original file line number Diff line number Diff line change 9
9
from io import StringIO
10
10
from typing import TYPE_CHECKING , NamedTuple
11
11
12
- from monty .dev import requires
13
12
from monty .json import MontyDecoder , MontyEncoder
14
13
15
14
from pymatgen .core .structure import Molecule , Structure
16
15
17
- try :
18
- from pybtex import errors
19
- from pybtex .database .input import bibtex
20
- except ImportError :
21
- pybtex = bibtex = errors = None
22
-
23
16
if TYPE_CHECKING :
24
17
from collections .abc import Sequence
25
18
from typing import Any
37
30
MAX_BIBTEX_CHARS : int = 20_000 # maximum number of characters for BibTeX reference
38
31
39
32
40
- @requires (bibtex is not None , "pybtex is not available" )
41
33
def is_valid_bibtex (reference : str ) -> bool :
42
34
"""Use pybtex to validate that a reference is in proper BibTeX format.
43
35
@@ -47,6 +39,12 @@ def is_valid_bibtex(reference: str) -> bool:
47
39
Returns:
48
40
bool: True if reference is valid BibTeX.
49
41
"""
42
+ try :
43
+ from pybtex import errors
44
+ from pybtex .database .input import bibtex
45
+ except ImportError as exc :
46
+ raise ImportError ("pybtex is not available" ) from exc
47
+
50
48
# str is necessary since pybtex seems to have an issue with unicode.
51
49
# The filter expression removes all non-ASCII characters.
52
50
str_io = StringIO (reference .encode ("ascii" , "ignore" ).decode ("ascii" ))
Original file line number Diff line number Diff line change 2
2
3
3
from unittest import TestCase
4
4
5
+ import pytest
5
6
from pytest import approx
6
7
7
8
from pymatgen .analysis .cost import CostAnalyzer , CostDBCSV , CostDBElements
8
9
from pymatgen .util .testing import TEST_FILES_DIR
9
10
11
+ try :
12
+ # Not using find_spec because it would error out during import
13
+ import pybtex .database # noqa: F401
14
+
15
+ except ImportError :
16
+ pytest .skip ("pybtex is not available" , allow_module_level = True )
17
+
10
18
TEST_DIR = f"{ TEST_FILES_DIR } /analysis/cost"
11
19
12
20
Original file line number Diff line number Diff line change 13
13
14
14
try :
15
15
import pybtex
16
+ import pybtex .database
16
17
except ImportError :
17
18
pybtex = None
18
19
@@ -165,6 +166,7 @@ def test_long_loop(self):
165
166
166
167
167
168
class TestCifIO (PymatgenTest ):
169
+ @pytest .mark .skipif (pybtex is None , reason = "pybtex not present" )
168
170
def test_cif_parser (self ):
169
171
parser = CifParser (f"{ TEST_FILES_DIR } /cif/LiFePO4.cif" )
170
172
for struct in parser .parse_structures ():
Original file line number Diff line number Diff line change 11
11
from pymatgen .core .structure import Molecule , Structure
12
12
from pymatgen .util .provenance import Author , HistoryNode , StructureNL
13
13
14
+ try :
15
+ # Not using find_spec because it would error out during import
16
+ import pybtex .database # noqa: F401
17
+
18
+ except ImportError :
19
+ pytest .skip ("pybtex is not available" , allow_module_level = True )
20
+
14
21
__author__ = "Anubhav Jain"
15
22
__credits__ = "Shyue Ping Ong"
16
23
__copyright__ = "Copyright 2012, The Materials Project"
You can’t perform that action at this time.
0 commit comments