From fb156029a68c583598e346861b565b866a0a74de Mon Sep 17 00:00:00 2001 From: Zhi Ming Xu Date: Tue, 10 Jun 2025 18:10:48 -0400 Subject: [PATCH 1/7] skpkg: migrate src folder --- .pre-commit-config.yaml | 14 ++++++++++++++ src/diffpy/__init__.py | 14 ++------------ src/diffpy/morph/__init__.py | 12 ++++-------- src/diffpy/morph/functions.py | 31 +++++++++++++++++++++++++++++++ src/diffpy/morph/version.py | 6 +++--- 5 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 src/diffpy/morph/functions.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 194374f9..0e4a84d1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -50,3 +50,17 @@ repos: - id: codespell additional_dependencies: - tomli + # prettier - multi formatter for .json, .yml, and .md files + - repo: https://github.com/pre-commit/mirrors-prettier + rev: f12edd9c7be1c20cfa42420fd0e6df71e42b51ea # frozen: v4.0.0-alpha.8 + hooks: + - id: prettier + additional_dependencies: + - "prettier@^3.2.4" + # docformatter - PEP 257 compliant docstring formatter + - repo: https://github.com/s-weigand/docformatter + rev: 5757c5190d95e5449f102ace83df92e7d3b06c6c + hooks: + - id: docformatter + additional_dependencies: [tomli] + args: [--in-place, --config, ./pyproject.toml] diff --git a/src/diffpy/__init__.py b/src/diffpy/__init__.py index a14a0c96..d8e13db0 100644 --- a/src/diffpy/__init__.py +++ b/src/diffpy/__init__.py @@ -1,24 +1,14 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2024 The Trustees of Columbia University in the City of New York. +# (c) 2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # # File coded by: Billinge Group members and community contributors. # # See GitHub contributions for a more detailed list of contributors. -# https://github.com/diffpy/diffpy.pdfmorph/graphs/contributors +# https://github.com/diffpy/diffpy.morph/graphs/contributors # # See LICENSE.rst for license information. # ############################################################################## -"""morph - tools for manipulating and comparing PDF data. - -""" - - -from pkgutil import extend_path - -__path__ = extend_path(__path__, __name__) - -# End of file diff --git a/src/diffpy/morph/__init__.py b/src/diffpy/morph/__init__.py index c87d5b6c..52d9ee8e 100644 --- a/src/diffpy/morph/__init__.py +++ b/src/diffpy/morph/__init__.py @@ -1,10 +1,10 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2024 The Trustees of Columbia University in the City of New York. +# (c) 2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # -# File coded by: Billinge Group members and community contributors. +# File coded by: Sangjoon Lee, Simon Billinge, Billinge Group members. # # See GitHub contributions for a more detailed list of contributors. # https://github.com/diffpy/diffpy.morph/graphs/contributors @@ -12,16 +12,12 @@ # See LICENSE.rst for license information. # ############################################################################## -"""Tools for manipulating and comparing PDF profiles.""" - -# key used when saving multiple morphs -__save_morph_as__ = "save_morph_as" +"""Python package for manipulating and comparing PDF profiles.""" # package version -from diffpy.morph.version import __version__ +from diffpy.morph.version import __version__ # noqa # silence the pyflakes syntax checker assert __version__ or True - # End of file diff --git a/src/diffpy/morph/functions.py b/src/diffpy/morph/functions.py new file mode 100644 index 00000000..e7e2c8e4 --- /dev/null +++ b/src/diffpy/morph/functions.py @@ -0,0 +1,31 @@ +import numpy as np + + +def dot_product(a, b): + """Compute the dot product of two vectors of any size. + + Ensure that the inputs, a and b, are of the same size. + The supported types are "array_like" objects, which can + be converted to a NumPy array. Examples include lists and tuples. + + Parameters + ---------- + a : array_like + The first input vector. + b : array_like + The second input vector. + + Returns + ------- + float + The dot product of the two vectors. + + Examples + -------- + Compute the dot product of two lists: + >>> a = [1, 2, 3] + >>> b = [4, 5, 6] + >>> dot_product(a, b) + 32.0 + """ + return float(np.dot(a, b)) diff --git a/src/diffpy/morph/version.py b/src/diffpy/morph/version.py index effe3cd5..f40af37f 100644 --- a/src/diffpy/morph/version.py +++ b/src/diffpy/morph/version.py @@ -1,13 +1,13 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2024 The Trustees of Columbia University in the City of New York. +# (c) 2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # -# File coded by: Billinge Group members and community contributors. +# File coded by: Sangjoon Lee, Simon Billinge, Billinge Group members. # # See GitHub contributions for a more detailed list of contributors. -# https://github.com/diffpy/diffpy.pdfmorph/graphs/contributors +# https://github.com/diffpy/diffpy.morph/graphs/contributors # noqa: E501 # # See LICENSE.rst for license information. # From 88d6b233f8598618e6f4508a03201c1fbe3bb484 Mon Sep 17 00:00:00 2001 From: Zhi Ming Xu Date: Tue, 10 Jun 2025 18:12:01 -0400 Subject: [PATCH 2/7] skpkg: migrate tests folder --- tests/test_functions.py | 40 ++++++++++++++++++++++++++++++++++++++++ tests/test_version.py | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/test_functions.py diff --git a/tests/test_functions.py b/tests/test_functions.py new file mode 100644 index 00000000..e7ee91b1 --- /dev/null +++ b/tests/test_functions.py @@ -0,0 +1,40 @@ +import numpy as np +import pytest + +from diffpy.morph import functions # noqa + + +def test_dot_product_2D_list(): + a = [1, 2] + b = [3, 4] + expected = 11.0 + actual = functions.dot_product(a, b) + assert actual == expected + + +def test_dot_product_3D_list(): + a = [1, 2, 3] + b = [4, 5, 6] + expected = 32.0 + actual = functions.dot_product(a, b) + assert actual == expected + + +@pytest.mark.parametrize( + "a, b, expected", + [ + # Test whether the dot product function works with 2D and 3D vectors + # C1: lists, expect correct float output + ([1, 2], [3, 4], 11.0), + ([1, 2, 3], [4, 5, 6], 32.0), + # C2: tuples, expect correct float output + ((1, 2), (3, 4), 11.0), + ((1, 2, 3), (4, 5, 6), 32.0), + # C3: numpy arrays, expect correct float output + (np.array([1, 2]), np.array([3, 4]), 11.0), + (np.array([1, 2, 3]), np.array([4, 5, 6]), 32.0), + ], +) +def test_dot_product(a, b, expected): + actual = functions.dot_product(a, b) + assert actual == expected diff --git a/tests/test_version.py b/tests/test_version.py index 38aa5669..68915adc 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,6 +1,6 @@ """Unit tests for __version__.py.""" -import diffpy.morph +import diffpy.morph # noqa def test_package_version(): From 52a9c0a37516c9fc0c084b8455b3ac8d2dec3a19 Mon Sep 17 00:00:00 2001 From: Zhi Ming Xu Date: Tue, 10 Jun 2025 18:14:10 -0400 Subject: [PATCH 3/7] skpkg: list dependencies in requirements folder --- requirements/build.txt | 2 -- requirements/conda.txt | 4 ---- requirements/docs.txt | 1 + requirements/pip.txt | 4 ---- requirements/test.txt | 2 +- 5 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 requirements/build.txt diff --git a/requirements/build.txt b/requirements/build.txt deleted file mode 100644 index f72d870d..00000000 --- a/requirements/build.txt +++ /dev/null @@ -1,2 +0,0 @@ -python -setuptools diff --git a/requirements/conda.txt b/requirements/conda.txt index e67cf6e2..24ce15ab 100644 --- a/requirements/conda.txt +++ b/requirements/conda.txt @@ -1,5 +1 @@ numpy -scipy -diffpy.utils -matplotlib-base -bg-mpl-stylesheets diff --git a/requirements/docs.txt b/requirements/docs.txt index ab17b1c8..5f34c6ed 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -1,4 +1,5 @@ sphinx sphinx_rtd_theme +sphinx-copybutton doctr m2r diff --git a/requirements/pip.txt b/requirements/pip.txt index a8bb45b4..24ce15ab 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -1,5 +1 @@ numpy -scipy -diffpy.utils -matplotlib -bg-mpl-stylesheets diff --git a/requirements/test.txt b/requirements/test.txt index f33bd0e3..a7277865 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -2,5 +2,5 @@ flake8 pytest codecov coverage -pytest-env pytest-cov +pytest-env From a36ba7a79905848e02e3ee176afce68163c35933 Mon Sep 17 00:00:00 2001 From: Zhi Ming Xu Date: Tue, 10 Jun 2025 18:16:29 -0400 Subject: [PATCH 4/7] skpkg: add CI and issue/PR templates --- .github/workflows/tests-on-pr.yml | 5 +---- .gitignore | 8 +------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/tests-on-pr.yml b/.github/workflows/tests-on-pr.yml index 8d0a909f..9d7879ea 100644 --- a/.github/workflows/tests-on-pr.yml +++ b/.github/workflows/tests-on-pr.yml @@ -1,15 +1,12 @@ name: Tests on PR on: - push: - branches: - - main pull_request: workflow_dispatch: jobs: tests-on-pr: - uses: Billingegroup/release-scripts/.github/workflows/_tests-on-pr.yml@v0 + uses: scikit-package/release-scripts/.github/workflows/_tests-on-pr.yml@v0 with: project: diffpy.morph c_extension: false diff --git a/.gitignore b/.gitignore index a25212ea..099e2948 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ __pycache__/ .Python env/ build/ +_build/ develop-eggs/ dist/ downloads/ @@ -90,10 +91,3 @@ target/ # Ipython Notebook .ipynb_checkpoints - -# version information -setup.cfg -/src/diffpy/*/version.cfg - -# Rever -rever/ From 4ab91128ad914192f0193f9036825fd30939deee Mon Sep 17 00:00:00 2001 From: Zhi Ming Xu Date: Tue, 10 Jun 2025 18:17:42 -0400 Subject: [PATCH 5/7] skpkg: add pyproject.toml --- pyproject.toml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f007f315..48c643f9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,9 +32,6 @@ classifiers = [ 'Topic :: Scientific/Engineering :: Chemistry', ] -[project.scripts] -"diffpy.morph" = "diffpy.morph.morphapp:main" - [project.urls] Homepage = "https://github.com/diffpy/diffpy.morph/" Issues = "https://github.com/diffpy/diffpy.morph/issues/" @@ -57,7 +54,7 @@ dependencies = {file = ["requirements/pip.txt"]} [tool.codespell] exclude-file = ".codespell/ignore_lines.txt" ignore-words = ".codespell/ignore_words.txt" -skip = "*.cif,*.dat,*agr" +skip = "*.cif,*.dat" [tool.black] line-length = 79 From dfc7e555a60126430a3cd963e6a5aade8415d80a Mon Sep 17 00:00:00 2001 From: Zhi Ming Xu Date: Tue, 10 Jun 2025 18:33:50 -0400 Subject: [PATCH 6/7] fix: revert necessary files that were modified --- pyproject.toml | 5 ++++- requirements/conda.txt | 4 ++++ requirements/pip.txt | 4 ++++ src/diffpy/__init__.py | 10 +++++++++ src/diffpy/morph/__init__.py | 3 +++ src/diffpy/morph/functions.py | 31 --------------------------- tests/test_functions.py | 40 ----------------------------------- 7 files changed, 25 insertions(+), 72 deletions(-) delete mode 100644 src/diffpy/morph/functions.py delete mode 100644 tests/test_functions.py diff --git a/pyproject.toml b/pyproject.toml index 48c643f9..f007f315 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,9 @@ classifiers = [ 'Topic :: Scientific/Engineering :: Chemistry', ] +[project.scripts] +"diffpy.morph" = "diffpy.morph.morphapp:main" + [project.urls] Homepage = "https://github.com/diffpy/diffpy.morph/" Issues = "https://github.com/diffpy/diffpy.morph/issues/" @@ -54,7 +57,7 @@ dependencies = {file = ["requirements/pip.txt"]} [tool.codespell] exclude-file = ".codespell/ignore_lines.txt" ignore-words = ".codespell/ignore_words.txt" -skip = "*.cif,*.dat" +skip = "*.cif,*.dat,*agr" [tool.black] line-length = 79 diff --git a/requirements/conda.txt b/requirements/conda.txt index 24ce15ab..e67cf6e2 100644 --- a/requirements/conda.txt +++ b/requirements/conda.txt @@ -1 +1,5 @@ numpy +scipy +diffpy.utils +matplotlib-base +bg-mpl-stylesheets diff --git a/requirements/pip.txt b/requirements/pip.txt index 24ce15ab..a8bb45b4 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -1 +1,5 @@ numpy +scipy +diffpy.utils +matplotlib +bg-mpl-stylesheets diff --git a/src/diffpy/__init__.py b/src/diffpy/__init__.py index d8e13db0..20e647e9 100644 --- a/src/diffpy/__init__.py +++ b/src/diffpy/__init__.py @@ -12,3 +12,13 @@ # See LICENSE.rst for license information. # ############################################################################## + +"""morph - tools for manipulating and comparing PDF data. +""" + + +from pkgutil import extend_path + +__path__ = extend_path(__path__, __name__) + +# End of file diff --git a/src/diffpy/morph/__init__.py b/src/diffpy/morph/__init__.py index 52d9ee8e..48455828 100644 --- a/src/diffpy/morph/__init__.py +++ b/src/diffpy/morph/__init__.py @@ -14,6 +14,9 @@ ############################################################################## """Python package for manipulating and comparing PDF profiles.""" +# key used when saving multiple morphs +__save_morph_as__ = "save_morph_as" + # package version from diffpy.morph.version import __version__ # noqa diff --git a/src/diffpy/morph/functions.py b/src/diffpy/morph/functions.py deleted file mode 100644 index e7e2c8e4..00000000 --- a/src/diffpy/morph/functions.py +++ /dev/null @@ -1,31 +0,0 @@ -import numpy as np - - -def dot_product(a, b): - """Compute the dot product of two vectors of any size. - - Ensure that the inputs, a and b, are of the same size. - The supported types are "array_like" objects, which can - be converted to a NumPy array. Examples include lists and tuples. - - Parameters - ---------- - a : array_like - The first input vector. - b : array_like - The second input vector. - - Returns - ------- - float - The dot product of the two vectors. - - Examples - -------- - Compute the dot product of two lists: - >>> a = [1, 2, 3] - >>> b = [4, 5, 6] - >>> dot_product(a, b) - 32.0 - """ - return float(np.dot(a, b)) diff --git a/tests/test_functions.py b/tests/test_functions.py deleted file mode 100644 index e7ee91b1..00000000 --- a/tests/test_functions.py +++ /dev/null @@ -1,40 +0,0 @@ -import numpy as np -import pytest - -from diffpy.morph import functions # noqa - - -def test_dot_product_2D_list(): - a = [1, 2] - b = [3, 4] - expected = 11.0 - actual = functions.dot_product(a, b) - assert actual == expected - - -def test_dot_product_3D_list(): - a = [1, 2, 3] - b = [4, 5, 6] - expected = 32.0 - actual = functions.dot_product(a, b) - assert actual == expected - - -@pytest.mark.parametrize( - "a, b, expected", - [ - # Test whether the dot product function works with 2D and 3D vectors - # C1: lists, expect correct float output - ([1, 2], [3, 4], 11.0), - ([1, 2, 3], [4, 5, 6], 32.0), - # C2: tuples, expect correct float output - ((1, 2), (3, 4), 11.0), - ((1, 2, 3), (4, 5, 6), 32.0), - # C3: numpy arrays, expect correct float output - (np.array([1, 2]), np.array([3, 4]), 11.0), - (np.array([1, 2, 3]), np.array([4, 5, 6]), 32.0), - ], -) -def test_dot_product(a, b, expected): - actual = functions.dot_product(a, b) - assert actual == expected From b3b186682e885f1c524a9b8b024f07eb865ae4ed Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Jun 2025 22:35:38 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit hooks --- src/diffpy/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/diffpy/__init__.py b/src/diffpy/__init__.py index 20e647e9..a1bb822e 100644 --- a/src/diffpy/__init__.py +++ b/src/diffpy/__init__.py @@ -12,7 +12,6 @@ # See LICENSE.rst for license information. # ############################################################################## - """morph - tools for manipulating and comparing PDF data. """