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

Add dependency on packaging for version parsing #341

Merged
merged 2 commits into from
Jul 25, 2024

Conversation

berquist
Copy link
Contributor

@berquist berquist commented Jul 7, 2024

Description

Running

python -m venv ./venv
source ./venv/bin/activate
python -m pip install -e .

inside of QCEngine, followed by

"""qcengine_example.py: Example of running a Q-Chem calculation through QCEngine."""

import qcengine as qcng
import qcelemental as qcel

mol = qcel.models.Molecule.from_data("""
O  0.0  0.000  -0.129
H  0.0 -1.494  1.027
H  0.0  1.494  1.027
""")

inp = qcel.models.AtomicInput(
    molecule=mol,
    driver="energy",
    model={"method": "hf", "basis": "sto-3g"},
)
ret = qcng.compute(
    inp,
    "qchem",
    local_options={"ncores": 1},
)

with open("qcengine_example.json", "w", encoding="utf-8") as handle:
    handle.write(ret.json())

produces an output with the error

QCEngine Execution Error:
Traceback (most recent call last):
  File "/home/eric/development/forks/MolSSI/QCEngine/qcengine/util.py", line 117, in compute_wrapper
    yield metadata
  File "/home/eric/development/forks/MolSSI/QCEngine/qcengine/compute.py", line 108, in compute
    output_data = executor.compute(input_data, config)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/eric/development/forks/MolSSI/QCEngine/qcen
gine/programs/qchem.py", line 106, in compute
    if parse_version(self.get_version()) < parse_version(qceng_ver):
                     ^^^^^^^^^^^^^^^^^^
  File "/home/eric/development/forks/MolSSI/QCEngine/qcengine/programs/qchem.py", line 89, in get_version
    self.version_cache[which_prog] = safe_version(mobj.group(1))
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/eric/development/forks/MolSSI/QCEngine/venv/lib/python3.12/site
-packages/qcelemental/util/importing.py", line 134, in safe_version
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

which means setuptools needs to be a runtime dependency. This bit of setuptools has been transitioned to packaging long ago and isn't even the build backend for qcel.

QCEngine tests against NWChem look clean.

Changelog description

Use packaging instead of setuptools to provide version parsing

Status

  • Code base linted
  • Ready to go

@loriab
Copy link
Collaborator

loriab commented Jul 25, 2024

Yes, it's about time to get rid of those warnings (and, apparently, errors). I kept looking for an official replacement for safe_version, but this'll do fine. Thanks for fixing! In case packaging proves disruptive, can do like jupytext:

def parse_version(version, custom_error=ImportError):
    try:
        from pkg_resources import parse_version as parse
    except ImportError:
        try:
            from packaging.version import parse
        except ImportError:
            raise custom_error("Please install either pkg_resources or packaging")

    print(version)
    return parse(version)

@loriab loriab merged commit 859c083 into MolSSI:master Jul 25, 2024
17 checks passed
@loriab loriab mentioned this pull request Sep 24, 2024
2 tasks
@berquist berquist deleted the packaging-version branch January 1, 2025 18:57
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.

2 participants