Skip to content

Commit 858d41f

Browse files
Move PyPI version check to module init; add setting to enable this (disabled by default, causes 0.3 s slowdown in tests); correct typo in check
1 parent 9304346 commit 858d41f

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

pymatgen/io/validation/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@
55
"""
66

77
from pymatgen.io.validation.validation import ValidationDoc # noqa: F401
8+
9+
from pymatgen.io.validation.settings import IOValidationSettings as _settings
10+
11+
if _settings().CHECK_PYPI_AT_LOAD:
12+
# Only check version at module load time, if specified in module settings.
13+
from pymatgen.io.validation.check_package_versions import package_version_check
14+
package_version_check()

pymatgen/io/validation/check_package_versions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def package_version_check() -> None:
1111

1212
packages = {
1313
"pymatgen": "Hence, if any pymatgen input sets have been updated, this validator will be outdated.",
14-
"pymagen-io-validation": "Hence, if any checks in this package have been updated, the validator you use will be outdated.",
14+
"pymatgen-io-validation": "Hence, if any checks in this package have been updated, the validator you use will be outdated.",
1515
}
1616

1717
for package, context_msg in packages.items():

pymatgen/io/validation/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ class IOValidationSettings(BaseSettings):
2626

2727
config_file: str = Field(DEFAULT_CONFIG_FILE_PATH, description="File to load alternative defaults from")
2828

29+
CHECK_PYPI_AT_LOAD : bool = Field(
30+
False, description = (
31+
"Whether to do a version check when this module is loaded. "
32+
"Helps user ensure most recent parameter checks are used."
33+
)
34+
)
35+
2936
VASP_KPTS_TOLERANCE: float = Field(
3037
0.9,
3138
description="Relative tolerance for kpt density to still be a valid task document",

pymatgen/io/validation/validation.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ class ValidationDoc(EmmetBaseModel):
6161
description="Last updated date for this document",
6262
default_factory=datetime.utcnow,
6363
)
64-
check_package_versions: bool = Field(
65-
False,
66-
description=(
67-
"Whether to check if the currently installed versions "
68-
"of pymatgen and pymatgen-io-validation are the most "
69-
"up to date versions on PyPI."
70-
),
71-
)
7264

7365
reasons: list[str] = Field(None, description="List of deprecation tags detailing why this task isn't valid")
7466

@@ -91,11 +83,6 @@ def model_post_init(self, context: Any) -> None:
9183

9284
self.valid = len(self.reasons) == 0
9385

94-
if self.check_package_versions:
95-
from check_package_versions import package_version_check
96-
97-
package_version_check()
98-
9986
class Config: # noqa
10087
extra = "allow"
10188

0 commit comments

Comments
 (0)