Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetretto committed Jan 26, 2024
2 parents 8c69096 + 44340e7 commit 57aaf0b
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 12 deletions.
10 changes: 6 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.4
rev: v0.1.9
hooks:
- id: ruff
args: [--fix]
Expand All @@ -19,10 +19,12 @@ repos:
hooks:
- id: check-yaml
- id: end-of-file-fixer
exclude: ^tests
- id: trailing-whitespace
exclude: ^tests

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
rev: v1.8.0
hooks:
- id: mypy

Expand All @@ -35,7 +37,7 @@ repos:
additional_dependencies: [tomli] # needed to read pyproject.toml below py3.11

- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.15.0
rev: v0.16.0
hooks:
- id: cython-lint
args: [--no-pycodestyle]
Expand All @@ -47,7 +49,7 @@ repos:
- id: blacken-docs

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.37.0
rev: v0.38.0
hooks:
- id: markdownlint
# MD013: line too long
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change log

## 2024.1.23
- Lazy import of optional libraries to speed up startup.

## 2023.9.25

- Improved pydantic2 support (@munrojm).
Expand Down
3 changes: 3 additions & 0 deletions docs/monty.functools.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ becomes
The decorated main accepts two new arguments:

> prof_file: Name of the output file with profiling data
> ```none
> If not given, a temporary file is created.
> ```
> sortby: Profiling data are sorted according to this value.
> ```none
> default is “time”. See sort_stats.
> ```
Expand Down
1 change: 1 addition & 0 deletions docs/monty.os.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ performing some tasks, and returns to the original working directory
afterwards. E.g.,

> with cd(“/my/path/”):
> ```none
> do_something()
> ```
Expand Down
2 changes: 2 additions & 0 deletions docs/monty.re.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ A powerful regular expression version of grep.
* **Returns**

> {key1: [[[matches…], lineno], [[matches…], lineno],
> ```none
> [[matches…], lineno], …],
> ```
> key2: …}
For reverse reads, the lineno is given as a -ve number. Please note
Expand Down
2 changes: 1 addition & 1 deletion monty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

__author__ = "Shyue Ping Ong"
__copyright__ = "Copyright 2014, The Materials Virtual Lab"
__version__ = "2023.11.3"
__version__ = "2024.1.23"
__maintainer__ = "Shyue Ping Ong"
__email__ = "ongsp@ucsd.edu"
__date__ = "Oct 12 2020"
4 changes: 4 additions & 0 deletions monty/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ def default(self, o) -> dict: # pylint: disable=E0202
try:
if pydantic is not None and isinstance(o, pydantic.BaseModel):
d = o.dict()
elif isinstance(o, Enum):
d = {"value": o.value}
elif (
dataclasses is not None
and (not issubclass(o.__class__, MSONable))
Expand Down Expand Up @@ -521,6 +523,8 @@ def process_decoded(self, d):
data = {k: v for k, v in d.items() if not k.startswith("@")}
if hasattr(cls_, "from_dict"):
return cls_.from_dict(data)
if issubclass(cls_, Enum):
return cls_(d["value"])
if pydantic is not None and issubclass(
cls_, pydantic.BaseModel
): # pylint: disable=E1101
Expand Down
2 changes: 1 addition & 1 deletion monty/pprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class DisplayEcoder(JSONEncoder):

def default(self, o):
"""
Try diffent ways of converting the present object for displaying
Try different ways of converting the present object for displaying
"""
try:
return o.as_dict()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ classifiers = [
dependencies = [

]
version = "2023.11.3"
version = "2024.1.23"

[tool.setuptools]
packages = ["monty"]
Expand Down
10 changes: 5 additions & 5 deletions requirements-optional.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
numpy==1.26.1
numpy==1.26.2
ruamel.yaml==0.18.5
msgpack==1.0.7
tqdm==4.66.1
pymongo==4.6.0
pandas==2.1.2
orjson==3.9.10
pymongo==4.6.1
pandas==2.1.3
orjson==3.9.12
types-orjson==3.6.2
types-requests==2.31.0.10
types-requests==2.31.0.20231231
11 changes: 11 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
test_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "test_files")


class A(Enum):
name_a = "value_a"
name_b = "value_b"


class GoodMSONClass(MSONable):
def __init__(self, a, b, c, d=1, *values, **kwargs):
self.a = a
Expand Down Expand Up @@ -803,3 +808,9 @@ def test_dataclass(self):
str_ = json.dumps(ndc, cls=MontyEncoder)
ndc2 = json.loads(str_, cls=MontyDecoder)
assert isinstance(ndc2, NestedDataClass)

def test_enum(self):
s = MontyEncoder().encode(A.name_a)
p = MontyDecoder().decode(s)
assert p.name == "name_a"
assert p.value == "value_a"

0 comments on commit 57aaf0b

Please sign in to comment.