Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/devel' into PR
Browse files Browse the repository at this point in the history
  • Loading branch information
thangckt committed May 27, 2024
2 parents aeb569c + 1d87e82 commit a57f6d7
Show file tree
Hide file tree
Showing 193 changed files with 2,074 additions and 1,404 deletions.
4 changes: 4 additions & 0 deletions .git_archival.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node: $Format:%H$
node-date: $Format:%cI$
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
ref-names: $Format:%D$
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git_archival.txt export-subst
23 changes: 23 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Python package

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies
run: uv pip install --system .[amber,ase,pymatgen,benchmark] rdkit openbabel-wheel
- name: Run benchmarks
uses: CodSpeedHQ/action@v2
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: pytest benchmark/ --codspeed
19 changes: 19 additions & 0 deletions .github/workflows/pyright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on:
- push
- pull_request

name: Type checker
jobs:
pyright:
name: pyright
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: pip install uv
- run: uv pip install --system -e .[amber,ase,pymatgen] rdkit openbabel-wheel
- uses: jakebailey/pyright-action@v2
with:
version: 1.1.363
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
# install rdkit and openbabel
- name: Install rdkit
run: python -m pip install rdkit openbabel-wheel
- run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies
run: python -m pip install .[amber,ase,pymatgen] coverage ./tests/plugin
run: uv pip install --system .[amber,ase,pymatgen] coverage ./tests/plugin rdkit openbabel-wheel
- name: Test
run: cd tests && coverage run --source=../dpdata -m unittest && cd .. && coverage combine tests/.coverage && coverage report
- name: Run codecov
Expand Down
35 changes: 18 additions & 17 deletions .github/workflows/test_import.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
name: test Python import

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
architecture: 'x64'
- run: python -m pip install .
- run: python -c 'import dpdata'
name: test Python import

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
architecture: 'x64'
- run: python -m pip install uv
- run: python -m uv pip install --system .
- run: python -c 'import dpdata'
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
# there are many log files in tests
# TODO: seperate py files and log files
Expand All @@ -16,10 +16,12 @@ repos:
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: mixed-line-ending
args: ["--fix=lf"]
# Python
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.5
rev: v0.4.4
hooks:
- id: ruff
args: ["--fix"]
Expand Down
Empty file added benchmark/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions benchmark/test_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import annotations

import subprocess
import sys

import pytest


@pytest.mark.benchmark
def test_import():
"""Test import dpdata."""
subprocess.check_output(
[sys.executable, "-c", "'from dpdata import LabeledSystem'"]
).decode("ascii")


@pytest.mark.benchmark
def test_cli():
"""Test dpdata command."""
subprocess.check_output([sys.executable, "-m", "dpdata", "-h"]).decode("ascii")
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
from __future__ import annotations

import os
import subprocess as sp
import sys
Expand Down Expand Up @@ -207,3 +209,4 @@ def setup(app):
# jupyterlite
jupyterlite_contents = "./nb"
jupyterlite_bind_ipynb_suffix = False
jupyterlite_silence = False
6 changes: 3 additions & 3 deletions docs/credits.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Authors
=======

Authors
=======

.. git-shortlog-authors::
3 changes: 2 additions & 1 deletion docs/environment.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: dpdata
channels:
- https://repo.mamba.pm/emscripten-forge
- https://repo.mamba.pm/conda-forge
- conda-forge
dependencies:
- xeus-python
- numpy
- scipy
- monty
Expand Down
36 changes: 20 additions & 16 deletions docs/make_format.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from __future__ import annotations

import csv
import os
import sys
from collections import defaultdict
from inspect import Parameter, Signature, cleandoc, signature
from typing import Literal

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal

from numpydoc.docscrape import Parameter as numpydoc_Parameter
from numpydoc.docscrape_sphinx import SphinxDocString
Expand Down Expand Up @@ -134,13 +141,13 @@ def generate_sub_format_pages(formats: dict):
for format, alias in formats.items():
# format: Format, alias: list[str]
buff = []
buff.append(".. _%s:" % format.__name__)
buff.append(f".. _{format.__name__}:")
buff.append("")
for aa in alias:
buff.append("%s format" % aa)
buff.append(f"{aa} format")
buff.append("=" * len(buff[-1]))
buff.append("")
buff.append("Class: %s" % get_cls_link(format))
buff.append(f"Class: {get_cls_link(format)}")
buff.append("")

docstring = format.__doc__
Expand All @@ -158,10 +165,10 @@ def generate_sub_format_pages(formats: dict):
buff.append(f".. _{format.__name__}_{method}:")
buff.append("")
if method.startswith("from_"):
buff.append("Convert from this format to %s" % method_classes[method])
buff.append(f"Convert from this format to {method_classes[method]}")
buff.append("`" * len(buff[-1]))
elif method.startswith("to_"):
buff.append("Convert from %s to this format" % method_classes[method])
buff.append(f"Convert from {method_classes[method]} to this format")
buff.append("`" * len(buff[-1]))
buff.append("")
method_obj = getattr(format, method)
Expand Down Expand Up @@ -224,10 +231,7 @@ def generate_sub_format_pages(formats: dict):
buff.append(""" :noindex:""")
buff.append("")
if docstring is None or method not in format.__dict__:
docstring = (
""" Convert this format to :class:`%s`."""
% (method_classes[method])
)
docstring = f""" Convert this format to :class:`{method_classes[method]}`."""
doc_obj = SphinxDocString(docstring)
if len(doc_obj["Parameters"]) > 0:
doc_obj["Parameters"] = [
Expand Down Expand Up @@ -295,7 +299,7 @@ def generate_sub_format_pages(formats: dict):
)
):
docstring = (
"Convert :class:`%s` to this format." % (method_classes[method])
f"Convert :class:`{method_classes[method]}` to this format."
)
doc_obj = SphinxDocString(docstring)
if len(doc_obj["Parameters"]) > 0:
Expand Down Expand Up @@ -324,7 +328,7 @@ def generate_sub_format_pages(formats: dict):
buff.append("")
buff.append("")

with open("formats/%s.rst" % format.__name__, "w") as rstfile:
with open(f"formats/{format.__name__}.rst", "w") as rstfile:
rstfile.write("\n".join(buff))


Expand All @@ -342,8 +346,8 @@ def generate_sub_format_pages(formats: dict):
for kk, vv in formats.items():
writer.writerow(
{
"Format": ":ref:`%s`" % kk.__name__,
"Alias": "\n".join("``%s``" % vvv for vvv in vv),
"Format": f":ref:`{kk.__name__}`",
"Alias": "\n".join(f"``{vvv}``" for vvv in vv),
"Supported Conversions": "\n".join(
method_links[mtd].format(kk.__name__, mtd)
for mtd in check_supported(kk)
Expand All @@ -364,7 +368,7 @@ def generate_sub_format_pages(formats: dict):
writer.writerow(
{
"Class": get_cls_link(kk),
"Alias": "\n".join("``%s``" % vvv for vvv in vv),
"Alias": "\n".join(f"``{vvv}``" for vvv in vv),
}
)

Expand All @@ -381,7 +385,7 @@ def generate_sub_format_pages(formats: dict):
writer.writerow(
{
"Class": get_cls_link(kk),
"Alias": "\n".join("``%s``" % vvv for vvv in vv),
"Alias": "\n".join(f"``{vvv}``" for vvv in vv),
}
)
generate_sub_format_pages(formats)
2 changes: 2 additions & 0 deletions docs/nb/try_dpdata.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"metadata": {},
"outputs": [],
"source": [
"from __future__ import annotations\n",
"\n",
"import dpdata"
]
},
Expand Down
3 changes: 2 additions & 1 deletion docs/rtd_environment.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: dpdata
channels:
- https://repo.mamba.pm/conda-forge
- conda-forge
dependencies:
- mamba
- pip:
- ..[docs]
2 changes: 2 additions & 0 deletions dpdata/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from __future__ import annotations

__version__ = "unknown"
26 changes: 2 additions & 24 deletions dpdata/__init__.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
# monty needs lzma
# See https://github.com/pandas-dev/pandas/pull/27882
try:
import lzma # noqa: F401
except ImportError:

class fakemodule:
pass

import sys

sys.modules["lzma"] = fakemodule
from __future__ import annotations

from . import lammps, md, vasp
from .bond_order_system import BondOrderSystem
from .system import LabeledSystem, MultiSystems, System

try:
from ._version import version as __version__
except ImportError:
from .__about__ import __version__

# BondOrder System has dependency on rdkit
try:
# prevent conflict with dpdata.rdkit
import rdkit as _ # noqa: F401

USE_RDKIT = True
except ModuleNotFoundError:
USE_RDKIT = False

if USE_RDKIT:
from .bond_order_system import BondOrderSystem

__all__ = [
"__version__",
"lammps",
Expand Down
6 changes: 6 additions & 0 deletions dpdata/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from __future__ import annotations

from dpdata.cli import dpdata_cli

if __name__ == "__main__":
dpdata_cli()
6 changes: 4 additions & 2 deletions dpdata/abacus/md.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os
import warnings

Expand Down Expand Up @@ -28,7 +30,7 @@ def get_path_out(fname, inlines):
for line in inlines:
if len(line) > 0 and "suffix" in line and "suffix" == line.split()[0]:
suffix = line.split()[1]
path_out = os.path.join(fname, "OUT.%s/" % suffix)
path_out = os.path.join(fname, f"OUT.{suffix}/")
break
return path_out

Expand Down Expand Up @@ -189,7 +191,7 @@ def get_frame(fname):
unconv_stru += "%d " % i
ndump = len(energy)
if unconv_stru != "":
warnings.warn("Structure %s are unconverged and not collected!" % unconv_stru)
warnings.warn(f"Structure {unconv_stru} are unconverged and not collected!")

for iframe in range(ndump):
stress[iframe] *= np.linalg.det(cells[iframe, :, :].reshape([3, 3]))
Expand Down
4 changes: 3 additions & 1 deletion dpdata/abacus/relax.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import os

import numpy as np
Expand Down Expand Up @@ -183,7 +185,7 @@ def get_frame(fname):
)

logf = get_log_file(fname, inlines)
assert os.path.isfile(logf), "Error: can not find %s" % logf
assert os.path.isfile(logf), f"Error: can not find {logf}"
with open(logf) as f1:
lines = f1.readlines()

Expand Down
Loading

0 comments on commit a57f6d7

Please sign in to comment.