Skip to content

Commit

Permalink
Merge branch 'master' of github.com:materialsvirtuallab/monty
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed Oct 21, 2024
2 parents 7c38a27 + 55e8078 commit 090c1e5
Show file tree
Hide file tree
Showing 30 changed files with 526 additions and 320 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.x"

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ on: [push, pull_request, workflow_call]
jobs:
build:
strategy:
fail-fast: false
max-parallel: 20
matrix:
os: [ubuntu-latest, macos-14, windows-latest]
python-version: ["3.9", "3.x"]
python-version: ["3.9", "3.12"]

runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repos:
rev: v2.3.0
hooks:
- id: codespell
stages: [commit, commit-msg]
stages: [pre-commit, commit-msg]
exclude_types: [html]
additional_dependencies: [tomli] # needed to read pyproject.toml below py3.11

Expand Down
6 changes: 3 additions & 3 deletions docs/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rexml (3.2.8)
strscan (>= 3.0.9)
rexml (3.3.6)
strscan
rouge (3.26.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
Expand All @@ -251,7 +251,7 @@ GEM
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (1.8.0)
webrick (1.8.1)
webrick (1.8.2)

PLATFORMS
arm64-darwin-22
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change log

## 2024.7.29
- Fix line ending in reverse_readfile/readline in Windows (@DanielYang59)
- Add missing functools.wraps decorator to deprecated decorator and handle dataclass properly (@DanielYang59)
- Add pint Quantity support to JSON (@rkingsbury)

## 2024.7.12
- Make cached_class decorated classes picklable (@janosh)
- deprecated decorator allow replacement as string (@DanielYang59)
Expand Down
38 changes: 23 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,37 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
]
dependencies = [

"ruamel.yaml",
"numpy<2.0.0",
]
version = "2024.7.12"
version = "2024.7.30"

[project.optional-dependencies]
ci = [
"pytest>=8",
"pytest-cov>=4",
"coverage",
"numpy<2.0.0",
"ruamel.yaml",
"msgpack",
"tqdm",
"pymongo",
"pandas",
"orjson",
"types-orjson",
"types-requests",
"torch"
"coverage",
"monty[optional]",
"pytest>=8",
"pytest-cov>=4",
"types-requests",
]
# dev is for "dev" module, not for development
dev = ["ipython"]
docs = [
"sphinx",
"sphinx_rtd_theme",
]
json = [
"bson",
"orjson>=3.6.1",
"pandas",
"pydantic",
"pint",
"torch",
]
multiprocessing = ["tqdm"]
optional = ["monty[dev,json,multiprocessing,serialization]"]
serialization = ["msgpack"]
task = ["requests", "invoke"]

[tool.setuptools.packages.find]
where = ["src"]
Expand Down Expand Up @@ -100,3 +107,4 @@ lint.select = [
]

lint.isort.required-imports = ["from __future__ import annotations"]
lint.isort.known-first-party = ["monty"]
9 changes: 8 additions & 1 deletion src/monty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@

from __future__ import annotations

from importlib.metadata import PackageNotFoundError, version

__author__ = "Shyue Ping Ong"
__copyright__ = "Copyright 2014, The Materials Virtual Lab"
__version__ = "2024.7.12"
__maintainer__ = "Shyue Ping Ong"
__email__ = "[email protected]"
__date__ = "Oct 12 2020"

try:
__version__ = version("monty")
except PackageNotFoundError: # pragma: no cover
# package is not installed
pass
20 changes: 15 additions & 5 deletions src/monty/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import subprocess
import sys
import warnings
from dataclasses import is_dataclass
from datetime import datetime
from typing import TYPE_CHECKING

Expand Down Expand Up @@ -121,6 +122,7 @@ def craft_message(
return msg

def deprecated_function_decorator(old: Callable) -> Callable:
@functools.wraps(old)
def wrapped(*args, **kwargs):
msg = craft_message(old, replacement, message, _deadline)
warnings.warn(msg, category=category, stacklevel=2)
Expand All @@ -129,14 +131,23 @@ def wrapped(*args, **kwargs):
return wrapped

def deprecated_class_decorator(cls: Type) -> Type:
original_init = cls.__init__
# Modify __post_init__ for dataclass
if is_dataclass(cls) and hasattr(cls, "__post_init__"):
original_init = cls.__post_init__
else:
original_init = cls.__init__

@functools.wraps(original_init)
def new_init(self, *args, **kwargs):
msg = craft_message(cls, replacement, message, _deadline)
warnings.warn(msg, category=category, stacklevel=2)
original_init(self, *args, **kwargs)

cls.__init__ = new_init
if is_dataclass(cls) and hasattr(cls, "__post_init__"):
cls.__post_init__ = new_init
else:
cls.__init__ = new_init

return cls

# Convert deadline to datetime type
Expand Down Expand Up @@ -220,9 +231,8 @@ def install_excepthook(hook_type: str = "color", **kwargs) -> int:
"""
try:
from IPython.core import ultratb # pylint: disable=import-outside-toplevel
except ImportError:
warnings.warn("Cannot install excepthook, IPyhon.core.ultratb not available")
return 1
except ImportError as exc:
raise ImportError("Cannot install excepthook, IPython not installed") from exc

# Select the hook.
hook = dict(
Expand Down
4 changes: 2 additions & 2 deletions src/monty/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self, func: Callable) -> None:
func: Function to decorate.
"""
self.__func = func
wraps(self.__func)(self) # type: ignore
wraps(self.__func)(self) # type: ignore[arg-type]

def __get__(self, inst: Any, inst_cls) -> Any:
if inst is None:
Expand All @@ -95,7 +95,7 @@ def __get__(self, inst: Any, inst_cls) -> Any:
f"'{inst_cls.__name__}' object has no attribute '__dict__'"
)

name = self.__name__ # type: ignore # pylint: disable=E1101
name = self.__name__ # type: ignore[attr-defined] # pylint: disable=E1101
if name.startswith("__") and not name.endswith("__"):
name = f"_{inst_cls.__name__}{name}"

Expand Down
Loading

0 comments on commit 090c1e5

Please sign in to comment.