From 77b52a3fdfdb69a1fbd35d23aae5e05878de7018 Mon Sep 17 00:00:00 2001 From: Dasun Abeykoon Date: Fri, 27 Jun 2025 16:19:13 -0700 Subject: [PATCH 1/9] skpkg: migrate src folder --- .pre-commit-config.yaml | 38 ++++++++++++++++++++--------- src/diffpy/__init__.py | 11 +-------- src/diffpy/nmf_mapping/__init__.py | 5 ++-- src/diffpy/nmf_mapping/functions.py | 31 +++++++++++++++++++++++ src/diffpy/nmf_mapping/version.py | 5 ++-- 5 files changed, 62 insertions(+), 28 deletions(-) create mode 100644 src/diffpy/nmf_mapping/functions.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9cf0556..0e4a84d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,14 +1,14 @@ default_language_version: - python: python3 + python: python3 ci: - autofix_commit_msg: | - [pre-commit.ci] auto fixes from pre-commit hooks - autofix_prs: true - autoupdate_branch: 'pre-commit-autoupdate' - autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate' - autoupdate_schedule: monthly - skip: [no-commit-to-branch] - submodules: false + autofix_commit_msg: | + [pre-commit.ci] auto fixes from pre-commit hooks + autofix_prs: true + autoupdate_branch: "pre-commit-autoupdate" + autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate" + autoupdate_schedule: monthly + skip: [no-commit-to-branch] + submodules: false repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 @@ -47,6 +47,20 @@ repos: - repo: https://github.com/codespell-project/codespell rev: v2.3.0 hooks: - - id: codespell - additional_dependencies: - - tomli + - 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 58c58be..1584c1d 100644 --- a/src/diffpy/__init__.py +++ b/src/diffpy/__init__.py @@ -1,7 +1,7 @@ #!/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. @@ -12,12 +12,3 @@ # See LICENSE.rst for license information. # ############################################################################## - -"""Blank namespace package for module diffpy.""" - - -from pkgutil import extend_path - -__path__ = extend_path(__path__, __name__) - -# End of file diff --git a/src/diffpy/nmf_mapping/__init__.py b/src/diffpy/nmf_mapping/__init__.py index 031f6ef..6e3c01f 100644 --- a/src/diffpy/nmf_mapping/__init__.py +++ b/src/diffpy/nmf_mapping/__init__.py @@ -1,7 +1,7 @@ #!/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. @@ -12,11 +12,10 @@ # See LICENSE.rst for license information. # ############################################################################## - """Python package for running NMF analysis on PDF and XRD data.""" # package version -from diffpy.nmf_mapping.version import __version__ +from diffpy.nmf_mapping.version import __version__ # noqa # silence the pyflakes syntax checker assert __version__ or True diff --git a/src/diffpy/nmf_mapping/functions.py b/src/diffpy/nmf_mapping/functions.py new file mode 100644 index 0000000..e7e2c8e --- /dev/null +++ b/src/diffpy/nmf_mapping/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/nmf_mapping/version.py b/src/diffpy/nmf_mapping/version.py index 0991a0b..dc2d4e4 100644 --- a/src/diffpy/nmf_mapping/version.py +++ b/src/diffpy/nmf_mapping/version.py @@ -1,18 +1,17 @@ #!/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.nmf_mapping/graphs/contributors +# https://github.com/diffpy/diffpy.nmf_mapping/graphs/contributors # noqa: E501 # # See LICENSE.rst for license information. # ############################################################################## - """Definition of __version__.""" # We do not use the other three variables, but can be added back if needed. From 6eba0054e5ec2639a7d0f8c540b3dbea4295bc68 Mon Sep 17 00:00:00 2001 From: Dasun Abeykoon Date: Fri, 27 Jun 2025 16:20:32 -0700 Subject: [PATCH 2/9] skpkg: add tests folder --- tests/test_functions.py | 40 ++++++++++++++++++++++++++++++++++++++++ tests/test_version.py | 8 ++++---- 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 tests/test_functions.py diff --git a/tests/test_functions.py b/tests/test_functions.py new file mode 100644 index 0000000..77a5233 --- /dev/null +++ b/tests/test_functions.py @@ -0,0 +1,40 @@ +import numpy as np +import pytest + +from diffpy.nmf_mapping 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 1167910..f9d0038 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -1,10 +1,10 @@ -"""Unit tests for __version__.py -""" +"""Unit tests for __version__.py.""" -import diffpy.nmf_mapping +import diffpy.nmf_mapping # noqa def test_package_version(): - """Ensure the package version is defined and not set to the initial placeholder.""" + """Ensure the package version is defined and not set to the initial + placeholder.""" assert hasattr(diffpy.nmf_mapping, "__version__") assert diffpy.nmf_mapping.__version__ != "0.0.0" From b997d01b5584d878c8deb4fc3009a76f56d22ceb Mon Sep 17 00:00:00 2001 From: Dasun Abeykoon Date: Fri, 27 Jun 2025 16:23:23 -0700 Subject: [PATCH 3/9] skpkg: list dependencies in requirement folder --- requirements/build.txt | 0 requirements/docs.txt | 1 + 2 files changed, 1 insertion(+) delete mode 100644 requirements/build.txt diff --git a/requirements/build.txt b/requirements/build.txt deleted file mode 100644 index e69de29..0000000 diff --git a/requirements/docs.txt b/requirements/docs.txt index ab17b1c..5f34c6e 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -1,4 +1,5 @@ sphinx sphinx_rtd_theme +sphinx-copybutton doctr m2r From 4f451aa5dfec714602cbb8c9d6786f4df28d61bb Mon Sep 17 00:00:00 2001 From: Dasun Abeykoon Date: Fri, 27 Jun 2025 16:35:23 -0700 Subject: [PATCH 4/9] skpkg: add CI and issue/PR templates --- .github/workflows/tests-on-pr.yml | 9 +++------ .gitignore | 8 +------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/.github/workflows/tests-on-pr.yml b/.github/workflows/tests-on-pr.yml index 766a79d..3245cde 100644 --- a/.github/workflows/tests-on-pr.yml +++ b/.github/workflows/tests-on-pr.yml @@ -1,18 +1,15 @@ name: Tests on PR on: - push: - branches: - - main pull_request: workflow_dispatch: jobs: - validate: - uses: Billingegroup/release-scripts/.github/workflows/_tests-on-pr.yml@v0 + tests-on-pr: + uses: scikit-package/release-scripts/.github/workflows/_tests-on-pr.yml@v0 with: project: diffpy.nmf_mapping c_extension: false - headless: false + headless: true secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index a25212e..099e294 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 f73b3eaf603ccd7c53b6fb07bdb5f0ce0e4f6874 Mon Sep 17 00:00:00 2001 From: Dasun Abeykoon Date: Fri, 27 Jun 2025 16:36:41 -0700 Subject: [PATCH 5/9] skpkg: add pyproject.toml --- pyproject.toml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c906f67..6094416 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,13 +6,13 @@ build-backend = "setuptools.build_meta" name = "diffpy.nmf_mapping" dynamic=['version', 'dependencies'] authors = [ - { name="Simon J.L. Billinge group", email="simon.billinge@gmail.com" }, + { name="Simon J.L. Billinge group", email="sb2896@columbia.edu" }, ] maintainers = [ - { name="Simon J.L. Billinge group", email="simon.billinge@gmail.com" }, + { name="Simon J.L. Billinge group", email="sb2896@columbia.edu" }, ] description = "Python package for running NMF analysis on PDF and XRD data." -keywords = ['"diffpy"', '"PDF"', '"NMF"'] +keywords = ['diffpy', 'PDF', 'NMF'] readme = "README.rst" requires-python = ">=3.11, <3.14" classifiers = [ @@ -42,9 +42,6 @@ template = "{tag}" dev_template = "{tag}" dirty_template = "{tag}" -[project.scripts] -snmf = "diffpy.nmf_mapping.main:main" - [tool.setuptools.packages.find] where = ["src"] # list of folders that contain the packages (["."] by default) include = ["*"] # package names should match these glob patterns (["*"] by default) @@ -59,8 +56,13 @@ exclude-file = ".codespell/ignore_lines.txt" ignore-words = ".codespell/ignore_words.txt" skip = "*.cif,*.dat" +[tool.docformatter] +recursive = true +wrap-summaries = 72 +wrap-descriptions = 72 + [tool.black] -line-length = 115 +line-length = 79 include = '\.pyi?$' exclude = ''' /( From 1f6f59d5165eddce5aa9d21e147823530cfb18c9 Mon Sep 17 00:00:00 2001 From: Dasun Abeykoon Date: Fri, 27 Jun 2025 16:41:23 -0700 Subject: [PATCH 6/9] chore: revert uneeded deletion --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6094416..d50abc8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,9 @@ template = "{tag}" dev_template = "{tag}" dirty_template = "{tag}" +[project.scripts] +snmf = "diffpy.nmf_mapping.main:main" + [tool.setuptools.packages.find] where = ["src"] # list of folders that contain the packages (["."] by default) include = ["*"] # package names should match these glob patterns (["*"] by default) @@ -62,7 +65,7 @@ wrap-summaries = 72 wrap-descriptions = 72 [tool.black] -line-length = 79 +line-length = 115 include = '\.pyi?$' exclude = ''' /( From 201d0ea92fcfb967448bbf3c2e8c7bc0b85b6f16 Mon Sep 17 00:00:00 2001 From: Dasun Abeykoon Date: Fri, 27 Jun 2025 16:47:25 -0700 Subject: [PATCH 7/9] chore: reverted uneeded changes in src directory --- src/diffpy/__init__.py | 11 +++++++++- src/diffpy/nmf_mapping/__init__.py | 2 +- src/diffpy/nmf_mapping/functions.py | 31 ----------------------------- src/diffpy/nmf_mapping/version.py | 2 +- 4 files changed, 12 insertions(+), 34 deletions(-) delete mode 100644 src/diffpy/nmf_mapping/functions.py diff --git a/src/diffpy/__init__.py b/src/diffpy/__init__.py index 1584c1d..256c067 100644 --- a/src/diffpy/__init__.py +++ b/src/diffpy/__init__.py @@ -1,7 +1,7 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2025 The Trustees of Columbia University in the City of New York. +# (c) 2024-2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # # File coded by: Billinge Group members and community contributors. @@ -12,3 +12,12 @@ # See LICENSE.rst for license information. # ############################################################################## + +"""Blank namespace package for module diffpy.""" + + +from pkgutil import extend_path + +__path__ = extend_path(__path__, __name__) + +# End of file diff --git a/src/diffpy/nmf_mapping/__init__.py b/src/diffpy/nmf_mapping/__init__.py index 6e3c01f..c6eb4f6 100644 --- a/src/diffpy/nmf_mapping/__init__.py +++ b/src/diffpy/nmf_mapping/__init__.py @@ -1,7 +1,7 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2025 The Trustees of Columbia University in the City of New York. +# (c) 2024-2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # # File coded by: Billinge Group members and community contributors. diff --git a/src/diffpy/nmf_mapping/functions.py b/src/diffpy/nmf_mapping/functions.py deleted file mode 100644 index e7e2c8e..0000000 --- a/src/diffpy/nmf_mapping/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/src/diffpy/nmf_mapping/version.py b/src/diffpy/nmf_mapping/version.py index dc2d4e4..fd17c35 100644 --- a/src/diffpy/nmf_mapping/version.py +++ b/src/diffpy/nmf_mapping/version.py @@ -1,7 +1,7 @@ #!/usr/bin/env python ############################################################################## # -# (c) 2025 The Trustees of Columbia University in the City of New York. +# (c) 2024-2025 The Trustees of Columbia University in the City of New York. # All rights reserved. # # File coded by: Billinge Group members and community contributors. From 914fbc305f5962c3c4886e50dd5a39a88baf8b5b Mon Sep 17 00:00:00 2001 From: Dasun Abeykoon Date: Fri, 27 Jun 2025 16:47:54 -0700 Subject: [PATCH 8/9] chore: reverted uneeded changes in tests directory --- tests/test_functions.py | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 tests/test_functions.py diff --git a/tests/test_functions.py b/tests/test_functions.py deleted file mode 100644 index 77a5233..0000000 --- a/tests/test_functions.py +++ /dev/null @@ -1,40 +0,0 @@ -import numpy as np -import pytest - -from diffpy.nmf_mapping 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 345116dd080d2040eafa1b76ed3ba90eb74d0a39 Mon Sep 17 00:00:00 2001 From: Dasun Abeykoon Date: Sat, 28 Jun 2025 09:40:42 -0700 Subject: [PATCH 9/9] Fix: set headless to false for test-on-PR gh workflow Signed-off-by: Dasun Abeykoon --- .github/workflows/tests-on-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests-on-pr.yml b/.github/workflows/tests-on-pr.yml index 3245cde..6de41f3 100644 --- a/.github/workflows/tests-on-pr.yml +++ b/.github/workflows/tests-on-pr.yml @@ -10,6 +10,6 @@ jobs: with: project: diffpy.nmf_mapping c_extension: false - headless: true + headless: false secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}