Skip to content

Commit

Permalink
Merge pull request #88 from xiaoruiDong/minor_fixes
Browse files Browse the repository at this point in the history
Python version supports
  • Loading branch information
xiaoruiDong authored Mar 20, 2024
2 parents 603849f + c146c97 commit 66c1b5d
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]

runs-on: ${{ matrix.os }}
Expand All @@ -62,7 +62,7 @@ jobs:
run: python -m pip install --no-deps -vv ./

- name: Install Pytest
run: mamba install -y pytest pytest-cov pytest-check
run: mamba install -y pytest pytest-cov # temporarily remove "pytest-check"

- name: Mamba info
run: |
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[pytest]
required_plugins =
pytest-cov
pytest-check
; pytest-check
filterwarnings =
ignore:.*escape seq.*:DeprecationWarning
addopts =
Expand Down
7 changes: 6 additions & 1 deletion rdmc/external/logparser/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from functools import cached_property, lru_cache
from functools import lru_cache
try:
from functools import cached_property
except:
from rdmc.external.logparser.utils import cached_property

import re
from typing import Optional

Expand Down
56 changes: 56 additions & 0 deletions rdmc/external/logparser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
A module contains functions to read Gaussian output file.
"""

from typing import List
from collections import defaultdict
import re

Expand Down Expand Up @@ -138,3 +139,58 @@ def scheme_to_dict(scheme_str: str) -> dict:
schemes['LOT']['freq'] = schemes['LOT']['LOT']

return schemes

########################################################################################################
# cached_property copied from Python lib/functools
# To be removed after dropping the support of Py3.7
########################################################################################################

_NOT_FOUND = object()


class cached_property:
def __init__(self, func):
self.func = func
self.attrname = None
self.__doc__ = func.__doc__

def __set_name__(self, owner, name):
if self.attrname is None:
self.attrname = name
elif name != self.attrname:
raise TypeError(
"Cannot assign the same cached_property to two different names "
f"({self.attrname!r} and {name!r})."
)

def __get__(self, instance, owner=None):
if instance is None:
return self
if self.attrname is None:
raise TypeError(
"Cannot use cached_property instance without calling __set_name__ on it."
)
try:
cache = instance.__dict__
except (
AttributeError
): # not all objects have __dict__ (e.g. class defines slots)
msg = (
f"No '__dict__' attribute on {type(instance).__name__!r} "
f"instance to cache {self.attrname!r} property."
)
raise TypeError(msg) from None
val = cache.get(self.attrname, _NOT_FOUND)
if val is _NOT_FOUND:
val = self.func(instance)
try:
cache[self.attrname] = val
except TypeError:
msg = (
f"The '__dict__' attribute on {type(instance).__name__!r} instance "
f"does not support item assignment for caching {self.attrname!r} property."
)
raise TypeError(msg) from None
return val

__class_getitem__ = classmethod(type(List[int]))
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@
],
keywords="chemistry, RDKit, molecule, conformer, reaction, cheminformatics",
license="MIT License",
python_requires='>=3.6',
python_requires='>=3.7',
platforms=["Any."],
)

0 comments on commit 66c1b5d

Please sign in to comment.