3333from pymatgen .io .validation .check_potcar import CheckPotcar
3434from pymatgen .io .validation .settings import IOValidationSettings
3535
36- from importlib .metadata import version
37- import requests
38-
39- from typing import TYPE_CHECKING
36+ from typing import TYPE_CHECKING , Any
4037
4138if TYPE_CHECKING :
4239 pass
4340
4441SETTINGS = IOValidationSettings ()
4542_vasp_defaults = loadfn (SETTINGS .VASP_DEFAULTS_FILENAME )
4643
47-
48- def is_package_is_up_to_date (package_name : str ):
49- """check if a package is up-to-date."""
50- try :
51- cur_version = version (package_name )
52- except Exception :
53- cur_version = "not installed"
54-
55- try :
56- response = requests .get (f"https://pypi.org/pypi/{ package_name } /json" )
57- latest_version = response .json ()["info" ]["version" ]
58- except Exception :
59- latest_version = "package does not exist"
60-
61- return cur_version == latest_version
62-
63-
6444# TODO: check for surface/slab calculations. Especially necessary for external calcs.
6545# TODO: implement check to make sure calcs are within some amount (e.g. 250 meV) of the convex hull in the MPDB
6646
@@ -78,6 +58,14 @@ class ValidationDoc(EmmetBaseModel):
7858 description = "Last updated date for this document" ,
7959 default_factory = datetime .utcnow ,
8060 )
61+ check_package_versions : bool = Field (
62+ False ,
63+ description = (
64+ "Whether to check if the currently installed versions "
65+ "of pymatgen and pymatgen-io-validation are the most "
66+ "up to date versions on PyPI."
67+ ),
68+ )
8169
8270 reasons : list [str ] = Field (None , description = "List of deprecation tags detailing why this task isn't valid" )
8371
@@ -88,22 +76,11 @@ class ValidationDoc(EmmetBaseModel):
8876 # " Useful for post-mortem analysis"
8977 # )
9078
91- def model_post_init (self , ctx ) :
92- """Warn the user if pymatgen / pymatgen-io-validation is not up-to-date."""
93- import warnings
79+ def model_post_init (self , context : Any ) -> None :
80+ if self . check_package_versions :
81+ from check_package_versions import package_version_check
9482
95- pymatgen_is_up_to_date = is_package_is_up_to_date ("pymatgen" )
96- if not pymatgen_is_up_to_date :
97- warnings .warn (
98- "We *STRONGLY* recommend you to update your `pymatgen` package, which is behind the most recent version. "
99- "Hence, if any pymatgen input sets have been updated, this validator will be outdated."
100- )
101- pymatgen_io_validation_is_up_to_date = is_package_is_up_to_date ("pymatgen-io-validation" )
102- if not pymatgen_io_validation_is_up_to_date :
103- warnings .warn (
104- "We *STRONGLY* recommend you to update your `pymatgen-io-validation` package, which is behind the most recent version. "
105- "Hence, if any checks in this package have been updated, the validator you use will be outdated."
106- )
83+ package_version_check ()
10784
10885 class Config : # noqa
10986 extra = "allow"
@@ -156,8 +133,6 @@ def from_task_doc(
156133 if orig_inputs ["kpoints" ] is not None :
157134 orig_inputs ["kpoints" ] = orig_inputs ["kpoints" ].as_dict ()
158135
159- calcs_reversed [0 ]["output" ]["ionic_steps" ]
160-
161136 potcars = calcs_reversed [0 ]["input" ]["potcar_spec" ]
162137
163138 calc_type = _get_calc_type (calcs_reversed , orig_inputs )
0 commit comments