Skip to content

Commit 9f10378

Browse files
skpkg: setup CI after migrating tests, src, requirements, and .github folder (#151)
* skpkg: migrate src folder * skpkg: migrate tests folder * skpkg: list dependencies in requirements folder * skpkg: add CI and issue/PR templates * skpkg: add pyproject.toml * skpkg: standardize files by removing examples and adding back necessary scripts * skpkg: modify copyright years and contributors in a missed file * style: changed line length to 115 and ran pre-commit again * fix: testing if adding .github/workflow will pass CI * [pre-commit.ci] auto fixes from pre-commit hooks --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 31c23a0 commit 9f10378

25 files changed

+582
-128
lines changed

.codecov.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
coverage:
22
status:
3-
project: # more options at https://docs.codecov.com/docs/commit-status
3+
project: # more options at https://docs.codecov.com/docs/commit-status
44
default:
55
target: auto # use the coverage from the base commit, fail if coverage is lower
6-
threshold: 0% # allow the coverage to drop by
6+
threshold: 0% # allow the coverage to drop by
77

88
comment:
99
layout: " diff, flags, files"
1010
behavior: default
1111
require_changes: false
12-
require_base: false # [true :: must have a base report to post]
13-
require_head: false # [true :: must have a head report to post]
12+
require_base: false # [true :: must have a base report to post]
13+
require_head: false # [true :: must have a head report to post]
1414
hide_project_coverage: false # [true :: only show coverage on the git diff aka patch coverage]

.github/ISSUE_TEMPLATE/release_checklist.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ assignees: ""
1212
- [ ] All the badges on the README are passing.
1313
- [ ] License information is verified as correct. If you are unsure, please comment below.
1414
- [ ] Locally rendered documentation contains all appropriate pages, including API references (check no modules are
15-
missing), tutorials, and other human written text is up-to-date with any changes in the code.
15+
missing), tutorials, and other human written text is up-to-date with any changes in the code.
1616
- [ ] Installation instructions in the README, documentation and on the website (e.g., diffpy.org) are updated.
1717
- [ ] Successfully run any tutorial examples or do functional testing with the latest Python version.
1818
- [ ] Grammar and writing quality are checked (no typos).
@@ -31,5 +31,5 @@ version information and details about the pre-release here:
3131

3232
<!-- Before closing this issue, please complete the following: -->
3333

34-
- [ ] Run tutorial examples and conduct functional testing using the installation guide in the README. Attach screenshots/results as comments.
35-
- [ ] Documentation (README, tutorials, API references, and websites) is deployed without broken links or missing figures.
34+
- [ ] Run tutorial examples and conduct functional testing using the installation guide in the README. Attach screenshots/results as comments.
35+
- [ ] Documentation (README, tutorials, API references, and websites) is deployed without broken links or missing figures.

.github/workflows/build-wheel-release-upload.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ on:
44
workflow_dispatch:
55
push:
66
tags:
7-
- '*' # Trigger on all tags initially, but tag and release privilege are verified in _build-wheel-release-upload.yml
7+
- "*" # Trigger on all tags initially, but tag and release privilege are verified in _build-wheel-release-upload.yml
88

99
jobs:
1010
release:
11-
uses: Billingegroup/release-scripts/.github/workflows/_build-wheel-release-upload.yml@v0
11+
uses: scikit-package/release-scripts/.github/workflows/_build-wheel-release-upload.yml@v0
1212
with:
1313
project: diffpy.snmf
14+
c_extension: false
15+
maintainer_GITHUB_username: sbillinge
1416
secrets:
1517
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
1618
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}

.github/workflows/check-news-item.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: Check for News
33
on:
44
pull_request_target:
55
branches:
6-
- main
6+
- main
77

88
jobs:
9-
build:
10-
uses: Billingegroup/release-scripts/.github/workflows/_check-news-item.yml@v0
9+
check-news-item:
10+
uses: scikit-package/release-scripts/.github/workflows/_check-news-item.yml@v0
1111
with:
1212
project: diffpy.snmf

.github/workflows/matrix-and-codecov-on-merge-to-main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ on:
1111
workflow_dispatch:
1212

1313
jobs:
14-
coverage:
15-
uses: Billingegroup/release-scripts/.github/workflows/_matrix-and-codecov-on-merge-to-main.yml@v0
14+
matrix-coverage:
15+
uses: scikit-package/release-scripts/.github/workflows/_matrix-and-codecov-on-merge-to-main.yml@v0
1616
with:
1717
project: diffpy.snmf
1818
c_extension: false
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Deploy Documentation on Release
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
docs:
8+
uses: scikit-package/release-scripts/.github/workflows/_publish-docs-on-release.yml@v0
9+
with:
10+
project: diffpy.snmf
11+
c_extension: false
12+
headless: false

.github/workflows/tests-on-pr.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
name: Tests on PR
22

33
on:
4-
push:
5-
branches:
6-
- main
74
pull_request:
85
workflow_dispatch:
96

107
jobs:
11-
validate:
12-
uses: Billingegroup/release-scripts/.github/workflows/_tests-on-pr.yml@v0
8+
tests-on-pr:
9+
uses: scikit-package/release-scripts/.github/workflows/_tests-on-pr.yml@v0
1310
with:
1411
project: diffpy.snmf
1512
c_extension: false

.gitignore

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ __pycache__/
1010
.Python
1111
env/
1212
build/
13+
_build/
1314
develop-eggs/
1415
dist/
1516
downloads/
@@ -90,10 +91,3 @@ target/
9091

9192
# Ipython Notebook
9293
.ipynb_checkpoints
93-
94-
# version information
95-
setup.cfg
96-
/src/diffpy/*/version.cfg
97-
98-
# Rever
99-
rever/

.pre-commit-config.yaml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
default_language_version:
2-
python: python3
2+
python: python3
33
ci:
4-
autofix_commit_msg: |
5-
[pre-commit.ci] auto fixes from pre-commit hooks
6-
autofix_prs: true
7-
autoupdate_branch: 'pre-commit-autoupdate'
8-
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
9-
autoupdate_schedule: monthly
10-
skip: [no-commit-to-branch]
11-
submodules: false
4+
autofix_commit_msg: |
5+
[pre-commit.ci] auto fixes from pre-commit hooks
6+
autofix_prs: true
7+
autoupdate_branch: "pre-commit-autoupdate"
8+
autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate"
9+
autoupdate_schedule: monthly
10+
skip: [no-commit-to-branch]
11+
submodules: false
1212
repos:
1313
- repo: https://github.com/pre-commit/pre-commit-hooks
1414
rev: v4.6.0
@@ -47,6 +47,20 @@ repos:
4747
- repo: https://github.com/codespell-project/codespell
4848
rev: v2.3.0
4949
hooks:
50-
- id: codespell
51-
additional_dependencies:
52-
- tomli
50+
- id: codespell
51+
additional_dependencies:
52+
- tomli
53+
# prettier - multi formatter for .json, .yml, and .md files
54+
- repo: https://github.com/pre-commit/mirrors-prettier
55+
rev: f12edd9c7be1c20cfa42420fd0e6df71e42b51ea # frozen: v4.0.0-alpha.8
56+
hooks:
57+
- id: prettier
58+
additional_dependencies:
59+
- "prettier@^3.2.4"
60+
# docformatter - PEP 257 compliant docstring formatter
61+
- repo: https://github.com/s-weigand/docformatter
62+
rev: 5757c5190d95e5449f102ace83df92e7d3b06c6c
63+
hooks:
64+
- id: docformatter
65+
additional_dependencies: [tomli]
66+
args: [--in-place, --config, ./pyproject.toml]

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ build-backend = "setuptools.build_meta"
66
name = "diffpy.snmf"
77
dynamic=['version', 'dependencies']
88
authors = [
9-
{ name="Simon J.L. Billinge group", email="[email protected]" },
9+
{ name="Simon J.L. Billinge group", email="[email protected]" },
1010
]
1111
maintainers = [
12-
{ name="Simon J.L. Billinge group", email="[email protected]" },
12+
{ name="Simon J.L. Billinge group", email="[email protected]" },
1313
]
1414
description = "Python package implementing the stretched NMF algorithm."
1515
keywords = ['diffpy', 'PDF']
1616
readme = "README.rst"
1717
requires-python = ">=3.11, <3.14"
1818
classifiers = [
19-
'Development Status :: 4 - Beta',
19+
'Development Status :: 5 - Production/Stable',
2020
'Environment :: Console',
2121
'Intended Audience :: Developers',
2222
'Intended Audience :: Science/Research',

requirements/build.txt

Whitespace-only changes.

src/diffpy/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
##############################################################################
33
#
4-
# (c) 2024 The Trustees of Columbia University in the City of New York.
4+
# (c) 2024-2025 The Trustees of Columbia University in the City of New York.
55
# All rights reserved.
66
#
77
# File coded by: Billinge Group members and community contributors.
@@ -12,7 +12,6 @@
1212
# See LICENSE.rst for license information.
1313
#
1414
##############################################################################
15-
1615
"""Blank namespace package for module diffpy."""
1716

1817

src/diffpy/snmf/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
##############################################################################
33
#
4-
# (c) 2024 The Trustees of Columbia University in the City of New York.
4+
# (c) 2024-2025 The Trustees of Columbia University in the City of New York.
55
# All rights reserved.
66
#
77
# File coded by: Billinge Group members and community contributors.
@@ -12,11 +12,10 @@
1212
# See LICENSE.rst for license information.
1313
#
1414
##############################################################################
15-
16-
"""A python package implementing the stretched NMF algorithm."""
15+
"""Python package implementing the stretched NMF algorithm."""
1716

1817
# package version
19-
from diffpy.snmf.version import __version__
18+
from diffpy.snmf.version import __version__ # noqa
2019

2120
# silence the pyflakes syntax checker
2221
assert __version__ or True

src/diffpy/snmf/containers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, grid, number_of_signals, id_number, perturbation=1e-3):
2626
self.id = int(id_number)
2727

2828
def apply_stretch(self, m):
29-
"""Applies a stretching factor to a component
29+
"""Applies a stretching factor to a component.
3030
3131
Parameters
3232
----------
@@ -41,7 +41,11 @@ def apply_stretch(self, m):
4141
"""
4242
normalized_grid = np.arange(len(self.grid))
4343
interpolate_intensity = lambda stretching_factor: np.interp( # noqa: E731
44-
normalized_grid / stretching_factor, normalized_grid, self.iq, left=0, right=0
44+
normalized_grid / stretching_factor,
45+
normalized_grid,
46+
self.iq,
47+
left=0,
48+
right=0,
4549
)
4650
derivative_func = numdifftools.Derivative(interpolate_intensity)
4751
second_derivative_func = numdifftools.Derivative(derivative_func)

src/diffpy/snmf/factorizers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44

55
def lsqnonneg(stretched_component_matrix, target_signal):
6-
"""Finds the weights of stretched component signals under one-sided constraint.
6+
"""Finds the weights of stretched component signals under one-sided
7+
constraint.
78
89
Solves ``argmin_x || Ax - b ||_2`` for ``x>=0`` where A is the stretched_component_matrix and b is the
910
target_signal vector. Finds the weights of component signals given undecomposed signal data and stretched

src/diffpy/snmf/io.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def initialize_variables(data_input, number_of_components, data_type, sparsity=1
3939
guess for the weight factor matrix, an initial guess for the stretching factor matrix, a parameter
4040
controlling smoothness of the solution, a parameter controlling sparseness of the solution, the matrix
4141
representing the smoothness term, and a matrix used to construct a hessian matrix.
42-
4342
"""
4443
signal_length = data_input.shape[0]
4544
number_of_signals = data_input.shape[1]
@@ -74,7 +73,8 @@ def initialize_variables(data_input, number_of_components, data_type, sparsity=1
7473

7574

7675
def load_input_signals(file_path=None):
77-
"""Processes a directory of a series of PDF/XRD patterns into a usable format.
76+
"""Processes a directory of a series of PDF/XRD patterns into a usable
77+
format.
7878
7979
Constructs a 2d array out of a directory of PDF/XRD patterns containing each files dependent variable
8080
column in a new column. Constructs a 1d array containing the grid values.
@@ -92,7 +92,6 @@ def load_input_signals(file_path=None):
9292
The tuple whose first element is an R x M 2d array made of PDF/XRD patterns as each column; R is the
9393
length of the signal and M is the number of patterns. The tuple contains a 1d array containing the values
9494
of the grid points as its second element; Has length R.
95-
9695
"""
9796

9897
if file_path is None:

src/diffpy/snmf/optimizers.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
from scipy.optimize import minimize
33

44

5-
def get_weights(stretched_component_gram_matrix, linear_coefficient, lower_bound, upper_bound):
6-
"""Finds the weights of stretched component signals under a two-sided constraint
5+
def get_weights(
6+
stretched_component_gram_matrix,
7+
linear_coefficient,
8+
lower_bound,
9+
upper_bound,
10+
):
11+
"""Finds the weights of stretched component signals under a two-sided
12+
constraint.
713
814
Solves min J(y) = (linear_coefficient)' * y + (1/2) * y' * (quadratic coefficient) * y where
915
lower_bound <= y <= upper_bound and stretched_component_gram_matrix is symmetric positive definite.
@@ -34,7 +40,6 @@ def get_weights(stretched_component_gram_matrix, linear_coefficient, lower_bound
3440
1d array like
3541
The vector containing the weightings of the components needed to reconstruct a given input signal from the
3642
input set. Has length C
37-
3843
"""
3944

4045
stretched_component_gram_matrix = np.asarray(stretched_component_gram_matrix)

src/diffpy/snmf/polynomials.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33

44
def compute_root(linear_coefficient, constant_term):
5-
"""
6-
Returns the largest real root of x^3+(linear_coefficient) * x + constant_term. If there are no real roots
7-
return 0.
5+
"""Returns the largest real root of x^3+(linear_coefficient) * x +
6+
constant_term. If there are no real roots return 0.
87
98
Parameters
109
----------
@@ -18,7 +17,6 @@ def compute_root(linear_coefficient, constant_term):
1817
ndarray of floats
1918
The largest real root of x^3+(linear_coefficient) * x + constant_term if roots are real, else
2019
return 0 array
21-
2220
"""
2321
linear_coefficient = np.asarray(linear_coefficient)
2422
constant_term = np.asarray(constant_term)

src/diffpy/snmf/stretchednmfapp.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
from diffpy.snmf.io import initialize_variables, load_input_signals
55
from diffpy.snmf.subroutines import initialize_components, lift_data
66

7-
ALLOWED_DATA_TYPES = ["powder_diffraction", "pd", "pair_distribution_function", "pdf"]
7+
ALLOWED_DATA_TYPES = [
8+
"powder_diffraction",
9+
"pd",
10+
"pair_distribution_function",
11+
"pdf",
12+
]
813

914

1015
def create_parser():
1116
parser = argparse.ArgumentParser(
12-
prog="stretched_nmf", description="Stretched Nonnegative Matrix Factorization"
17+
prog="stretched_nmf",
18+
description="Stretched Nonnegative Matrix Factorization",
1319
)
1420
parser.add_argument(
1521
"-i",
@@ -44,7 +50,12 @@ def create_parser():
4450
type=int,
4551
help="The number of component signals for the NMF decomposition. Must be an integer greater than 0",
4652
)
47-
parser.add_argument("-v", "--version", action="version", help="Print the software version number")
53+
parser.add_argument(
54+
"-v",
55+
"--version",
56+
action="version",
57+
help="Print the software version number",
58+
)
4859
args = parser.parse_args()
4960
return args
5061

0 commit comments

Comments
 (0)