Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support python3.13 #4100

Draft
wants to merge 57 commits into
base: master
Choose a base branch
from

Conversation

DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Oct 10, 2024

Summary

  • Support python 3.13, to close Python 3.13 support #4284
  • Make pybtex optional dependency (doesn't work on MacOS Python 3.13)
  • Need to fix the EOS test failure on Ubuntu 3.13 (seemingly related to numerical precision but cannot recreate locally)
  • Revert all platforms tested on Python 3.13 (c9cc898)

Optional dependencies that miss Python 3.13 support:

  • openff-toolkit (conda source)
  • chgnet

@DanielYang59
Copy link
Contributor Author

might close this one now as too many packages don't support python 3.13, feel free to take over this

@DanielYang59 DanielYang59 force-pushed the support-python313 branch 2 times, most recently from 38a70c4 to d1694e3 Compare November 19, 2024 13:43
try:
AFLOW_PROTOTYPE_LIBRARY = loadfn(f"{MODULE_DIR}/aflow_prototypes.json")
except RuntimeError as exc:
raise ImportError("pybtex is needed to load AFLOW library") from exc
Copy link
Contributor Author

@DanielYang59 DanielYang59 Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this would be breaking, this just re-raise the exception from requires to provide more context, otherwise the error message when pybtex is not available would be:

tests/analysis/test_prototypes.py:6: in <module>
    from pymatgen.analysis.prototypes import AflowPrototypeMatcher
src/pymatgen/analysis/prototypes.py:28: in <module>
    AFLOW_PROTOTYPE_LIBRARY = loadfn(f"{MODULE_DIR}/aflow_prototypes.json")
venv312/lib/python3.12/site-packages/monty/serialization.py:79: in loadfn
    return json.load(fp, *args, **kwargs)
../../opt/miniconda3/envs/pmg/lib/python3.12/json/__init__.py:293: in load
    return loads(fp.read(),
../../opt/miniconda3/envs/pmg/lib/python3.12/json/__init__.py:359: in loads
    return cls(**kw).decode(s)
venv312/lib/python3.12/site-packages/monty/json.py:879: in decode
    return self.process_decoded(d)
venv312/lib/python3.12/site-packages/monty/json.py:857: in process_decoded
    return [self.process_decoded(x) for x in d]
venv312/lib/python3.12/site-packages/monty/json.py:853: in process_decoded
    self.process_decoded(k): self.process_decoded(v) for k, v in d.items()
venv312/lib/python3.12/site-packages/monty/json.py:777: in process_decoded
    return cls_.from_dict(data)
src/pymatgen/util/provenance.py:340: in from_dict
    return cls(
src/pymatgen/util/provenance.py:229: in __init__
    if references and not is_valid_bibtex(references):
venv312/lib/python3.12/site-packages/monty/dev.py:167: in decorated
    raise self.err_cls(self.message)
E   RuntimeError: pybtex is not available

Before adding the requires decorator to is_valid_bibtex:

tests/analysis/test_prototypes.py:6: in <module>
    from pymatgen.analysis.prototypes import AflowPrototypeMatcher
src/pymatgen/analysis/prototypes.py:29: in <module>
    AFLOW_PROTOTYPE_LIBRARY = loadfn(f"{MODULE_DIR}/aflow_prototypes.json")
venv312/lib/python3.12/site-packages/monty/serialization.py:79: in loadfn
    return json.load(fp, *args, **kwargs)
../../opt/miniconda3/envs/pmg/lib/python3.12/json/__init__.py:293: in load
    return loads(fp.read(),
../../opt/miniconda3/envs/pmg/lib/python3.12/json/__init__.py:359: in loads
    return cls(**kw).decode(s)
venv312/lib/python3.12/site-packages/monty/json.py:879: in decode
    return self.process_decoded(d)
venv312/lib/python3.12/site-packages/monty/json.py:857: in process_decoded
    return [self.process_decoded(x) for x in d]
venv312/lib/python3.12/site-packages/monty/json.py:853: in process_decoded
    self.process_decoded(k): self.process_decoded(v) for k, v in d.items()
venv312/lib/python3.12/site-packages/monty/json.py:777: in process_decoded
    return cls_.from_dict(data)
src/pymatgen/util/provenance.py:340: in from_dict
    return cls(
src/pymatgen/util/provenance.py:229: in __init__
    if references and not is_valid_bibtex(references):
src/pymatgen/util/provenance.py:53: in is_valid_bibtex
    parser = bibtex.Parser()
E   AttributeError: 'NoneType' object has no attribute 'Parser'

Update: I just realized pybtex is not an optional dependency, need to put more thoughts into this:

pymatgen/pyproject.toml

Lines 56 to 64 in 5b997f7

dependencies = [
"joblib>=1",
"matplotlib>=3.8",
"monty>=2025.1.9",
"networkx>=2.7", # PR4116
"palettable>=3.3.3",
"pandas>=2",
"plotly>=4.5.0,<6.0.0",
"pybtex>=0.24.0",

Copy link
Contributor Author

@DanielYang59 DanielYang59 Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, pybtex is installed successfully in MacOS CI but some or all parts of pybtex is still not available, need to look into the reason later as I don't have a MacOS machine at hand right now


Update:

On MacOS, from pybtex.database.input import bibtex gives:

Traceback (most recent call last):
  File "/Users/yang/developer/pymatgen/debug/test_pybtex_install.py", line 8, in <module>
    from pybtex.database.input import bibtex
  File "/Users/yang/developer/pymatgen/venv313/lib/python3.13/site-packages/pybtex/database/__init__.py", line 44, in <module>
    from pybtex.plugin import find_plugin
  File "/Users/yang/developer/pymatgen/venv313/lib/python3.13/site-packages/pybtex/plugin/__init__.py", line 26, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

Which is an already fixed issue from pybtex's side but they haven't got a release with this patch yet. In fact they haven't released any issue since Jan 2021

@DanielYang59 DanielYang59 force-pushed the support-python313 branch 2 times, most recently from a9cf179 to 0b25745 Compare February 9, 2025 14:03
@DanielYang59
Copy link
Contributor Author

Also cannot recreate the Windows fatal exception: access violation failure on my Windows machine (pytest-dev/pytest#7634)

@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Feb 14, 2025

I'm pretty much stuck with the Windows runner failure, help needed

shyuep pushed a commit that referenced this pull request Feb 18, 2025
* add types for analysis.eos

* add requires decorator to is_valid_bibtex

* revert adding requires

* fix typo in core.structure.rotate_sites

* skip prototype test if pybtex is not available

* remove import guard from cherry pick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python 3.13 support
2 participants