Skip to content

Commit

Permalink
better deprecation handle without breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Oct 17, 2024
1 parent fb3ba69 commit c18823c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/pymatgen/ext/cod.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,23 @@ def get_cod_ids(self, formula: str) -> list[int]:

return [int(entry["file"]) for entry in response.json()]

def get_structure_by_id(self, cod_id: int, **kwargs) -> Structure:
def get_structure_by_id(self, cod_id: int, timeout: int | None = None, **kwargs) -> Structure:
"""Query the COD for a structure by ID.
Args:
cod_id (int): COD ID.
timeout (int): DEPRECATED. request timeout in seconds.
kwargs: kwargs passed to Structure.from_str.
Returns:
A Structure.
"""
response = requests.get(f"{self.url}/cod/{cod_id}.cif", timeout=self.timeout)
# TODO: remove timeout arg and use class level timeout after 2025-10-17
if timeout is not None:
warnings.warn("separate timeout arg is deprecated, please use class level timeout", DeprecationWarning)
timeout = timeout or self.timeout

response = requests.get(f"{self.url}/cod/{cod_id}.cif", timeout=timeout)
return Structure.from_str(response.text, fmt="cif", **kwargs)

def get_structure_by_formula(
Expand Down
4 changes: 2 additions & 2 deletions tests/ext/test_cod.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from pymatgen.ext.cod import COD

# Sse a tighter timeout in CI
TIMEOUT = 10 if "CI" in os.environ else 60
# Set a tighter timeout in CI
TIMEOUT = 10 if os.getenv("CI") else 60


try:
Expand Down

0 comments on commit c18823c

Please sign in to comment.