Skip to content

Commit ae6a28b

Browse files
Anselmoopre-commit-ci[bot]
andauthoredDec 23, 2024··
build: ⬆️ update configuration files for improved linting and formattingUpdate linting and formatting configurations (#1749)
* chore: update pre-commit configuration for argument formatting and versioning * chore: 🚨 update ruff version to v0.8.4 and comment out prettier configuration Pre Commit mirrors prettier is archived * chore: remove commented-out prettier configuration from pre-commit config * chore: ✨ add empty file for actionlint * chore: ✨ add initial actionlint configuration file * ci: ➖ disable black and isort linters in trunk configuration * build: ⬆️ update configuration files for improved linting and formatting * refactor: simplify file writing logic in PklVisualizer * refactor: streamline file handling in ExportResults and ensure safe YAML loading * test: skip tests for Python versions lower than 3.9 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: update YAML loading to use deprecated method for compatibility * refactor: ♻️ simplify file opening logic in RIXSConverter * refactor: simplify Poetry installation logic in CI workflow * test: skip tests for Python versions lower than 3.9 * test: skip tests and import for Python versions lower than 3.9 * test: add Python version check for tests requiring Python 3.9 or higher --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c2711bb commit ae6a28b

12 files changed

+364
-265
lines changed
 

‎.github/actionlint.yaml

Whitespace-only changes.

‎.github/workflows/python-ci.yml

-4
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ jobs:
6161
- name: Install Poetry and dependencies with dev-dependencies
6262
run: |
6363
python -m pip install --upgrade pip
64-
# if [ "${{ matrix.os }}" == "windows-latest" ]; then
65-
# pip install poetry
66-
# else
6764
pip install poetry
68-
# fi
6965
poetry config virtualenvs.create true
7066
poetry config virtualenvs.in-project true
7167
poetry config virtualenvs.path .venv

‎.pre-commit-config.yaml

+3-9
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ repos:
1616
- id: check-merge-conflict
1717
- id: check-case-conflict
1818
- id: check-added-large-files
19-
args: ["--maxkb=1000"]
19+
args: [--maxkb=1000]
2020
exclude: \.ipynb
2121
- repo: https://github.com/astral-sh/ruff-pre-commit
22-
rev: v0.8.3
22+
rev: v0.8.4
2323
hooks:
2424
- id: ruff
2525
files: spectrafit/
2626
- id: ruff-format
2727
files: spectrafit/
2828
- repo: https://github.com/pre-commit/mirrors-mypy
29-
rev: v1.13.0
29+
rev: v1.14.0
3030
hooks:
3131
- id: mypy
3232
additional_dependencies:
@@ -45,9 +45,3 @@ repos:
4545
hooks:
4646
- id: pydocstyle
4747
additional_dependencies: [toml>=0.10.2]
48-
- repo: https://github.com/pre-commit/mirrors-prettier
49-
rev: "v4.0.0-alpha.8"
50-
hooks:
51-
- id: prettier
52-
files: '\.(md|js|css)$'
53-
args: [--prose-wrap=always]

‎.trunk/trunk.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ runtimes:
1717
- python@3.10.8
1818
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
1919
lint:
20+
disabled:
21+
- black
22+
- isort
2023
enabled:
2124
- actionlint@1.7.4
2225
- bandit@1.8.0
23-
- black@24.10.0
2426
- checkov@3.2.334
2527
- git-diff-check
2628
- hadolint@2.12.1-beta
27-
- isort@5.13.2
2829
- markdownlint@0.43.0
2930
- mypy@1.13.0
3031
- osv-scanner@1.9.1

‎poetry.lock

+315-211
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎spectrafit/models.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ def lorentzian(
106106
Union[NDArray[np.float64], float]: Lorentzian distribution of `x` given.
107107
"""
108108
sigma = fwhml * Constants.fwhml2sig
109-
return np.array(amplitude / (1 + ((1.0 * x - center) / sigma) ** 2)) / (
110-
pi * sigma
109+
return np.array(
110+
amplitude / (1 + ((1.0 * x - center) / sigma) ** 2) / (pi * sigma),
111+
dtype=np.float64,
111112
)
112113

113114
@staticmethod
@@ -292,7 +293,7 @@ def _norm(
292293
"""
293294
if abs(sigma) < 1.0e-13:
294295
sigma = 1.0e-13
295-
return np.subtract(x, center) / sigma
296+
return np.array(np.subtract(x, center) / sigma, dtype=np.float64)
296297

297298
@staticmethod
298299
def erf(
@@ -1587,7 +1588,7 @@ def solve_local_fitting(
15871588

15881589
for key, _kwarg in peak_kwargs.items():
15891590
val += getattr(DistributionModels(), key[0])(x, **_kwarg)
1590-
return val - data
1591+
return np.array(val - data, dtype=np.float64)
15911592

15921593
@staticmethod
15931594
def solve_global_fitting(

‎spectrafit/plugins/notebook.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,7 @@ def export_report(self, report: Dict[Any, Any], args: FnameAPI) -> None:
514514
prefix=args.prefix,
515515
suffix=args.suffix,
516516
folder=args.folder,
517-
).open(
518-
"wb+",
519-
) as f:
517+
).open("wb+") as f:
520518
tomli_w.dump(report, f)
521519

522520
@staticmethod

‎spectrafit/plugins/pkl_visualizer.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,8 @@ def save(self, data: Any, fname: Path, export_format: str) -> None:
111111
format=export_format,
112112
)
113113

114-
with (
115-
pure_fname(fname)
116-
.with_suffix(".json")
117-
.open("w+", encoding="utf-8") as outfile
118-
):
119-
json.dump(data, outfile, indent=4)
114+
with open(pure_fname(fname).with_suffix(".json"), "w+", encoding="utf-8") as f:
115+
json.dump(data, f, indent=4)
120116

121117
def get_type(self, value: Any) -> Union[Dict[str, Any], str]:
122118
"""Get the type of the value.

‎spectrafit/plugins/rixs_converter.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -182,20 +182,11 @@ def save(self, data: Any, fname: Path, export_format: str) -> None:
182182
with (
183183
pure_fname(fname)
184184
.with_suffix(f".{export_format}")
185-
.open(
186-
"w",
187-
encoding="utf-8",
188-
) as f
185+
.open("w", encoding="utf-8") as f
189186
):
190187
json.dump(self.numpydict2listdict(data), f, indent=4)
191188
elif export_format in {"toml", "lock"}:
192-
with (
193-
pure_fname(fname)
194-
.with_suffix(f".{export_format}")
195-
.open(
196-
"wb",
197-
) as f
198-
):
189+
with pure_fname(fname).with_suffix(f".{export_format}").open("wb") as f:
199190
tomli_w.dump(self.numpydict2listdict(data), f, multiline_strings=False)
200191
elif export_format == "npy":
201192
np.save(pure_fname(fname).with_suffix(f".{export_format}"), data)

‎spectrafit/plugins/test/test_converter.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import shutil
77

88
from pathlib import Path
9+
import sys
910
from typing import Any
1011
from typing import Dict
1112
from typing import Tuple
@@ -25,10 +26,16 @@
2526
from spectrafit.plugins.pkl_converter import ExportData
2627
from spectrafit.plugins.pkl_converter import PklConverter
2728
from spectrafit.plugins.pkl_visualizer import PklVisualizer
28-
from spectrafit.plugins.pptx_converter import PPTXConverter
29-
from spectrafit.plugins.rixs_converter import RIXSConverter
3029

3130

31+
if sys.version_info >= (3, 9):
32+
from spectrafit.plugins.pptx_converter import PPTXConverter
33+
from spectrafit.plugins.rixs_converter import RIXSConverter
34+
else:
35+
pytest.mark.skip("Requires Python 3.9 or higher", allow_module_level=True)
36+
37+
38+
@pytest.mark.skipif(sys.version_info < (3, 9), reason="Requires Python 3.9 or higher")
3239
class TestFileConverter:
3340
"""Test the file converter plugin."""
3441

@@ -301,6 +308,7 @@ def reference_dataframe() -> pd.DataFrame:
301308
)
302309

303310

311+
@pytest.mark.skipif(sys.version_info < (3, 9), reason="Requires Python 3.9 or higher")
304312
class TestDataConverter:
305313
"""Test DataConverter class."""
306314

@@ -512,6 +520,7 @@ def tmp_file_pkl_nested(
512520
return tmp_file
513521

514522

523+
@pytest.mark.skipif(sys.version_info < (3, 9), reason="Requires Python 3.9 or higher")
515524
class TestPklConverter:
516525
"""Test PklConverter."""
517526

@@ -686,6 +695,7 @@ def test_cmd_pkl_converter(
686695
)
687696

688697

698+
@pytest.mark.skipif(sys.version_info < (3, 9), reason="Requires Python 3.9 or higher")
689699
class TestPklAsGraph:
690700
"""Test the pkl visualizer."""
691701

@@ -803,6 +813,7 @@ def fixture_tmp_list_dict_rixs(
803813
return fname, keys
804814

805815

816+
@pytest.mark.skipif(sys.version_info < (3, 9), reason="Requires Python 3.9 or higher")
806817
class TestRixsConverter:
807818
"""Test the rixs converter."""
808819

@@ -859,7 +870,7 @@ def test_save(
859870
if export_format == "npy":
860871
data_npy = np.load(fname.parent / f"{fname.stem}.npy", allow_pickle=True)
861872
assert isinstance(data_npy, np.ndarray)
862-
assert np.allclose(data_npy.item()[keys[0]], data[keys[0]])
873+
assert np.allclose(data_npy.item()[keys[0]], data[keys[0]]) # type: ignore
863874

864875
if export_format == "npz":
865876
data_npz = np.load(fname.parent / f"{fname.stem}.npz", allow_pickle=True)
@@ -1039,6 +1050,7 @@ def test_cmd_pkl_converter(
10391050
"""
10401051

10411052

1053+
@pytest.mark.skipif(sys.version_info < (3, 9), reason="Requires Python 3.9 or higher")
10421054
class TestPPTXConverter:
10431055
"""Test the pptx converter."""
10441056

‎spectrafit/plugins/test/test_rixs_visualizer.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Test of the RIXS Visualizer."""
22

33
from pathlib import Path
4+
import sys
45
from typing import Any
56
from typing import Tuple
67

@@ -9,25 +10,29 @@
910
import pytest
1011

1112
from numpy.typing import NDArray
12-
from spectrafit.plugins.rixs_converter import RIXSConverter
13-
from spectrafit.plugins.rixs_visualizer import RIXSApp
14-
from spectrafit.plugins.rixs_visualizer import RIXSFigure
15-
from spectrafit.plugins.rixs_visualizer import RIXSVisualizer
1613

14+
if sys.version_info >= (3, 9):
15+
from spectrafit.plugins.rixs_converter import RIXSConverter
16+
from spectrafit.plugins.rixs_visualizer import RIXSApp
17+
from spectrafit.plugins.rixs_visualizer import RIXSFigure
18+
from spectrafit.plugins.rixs_visualizer import RIXSVisualizer
19+
else:
20+
pytest.mark.skip("Requires Python 3.9 or higher", allow_module_level=True)
1721

22+
23+
@pytest.mark.skipif(sys.version_info < (3, 9), reason="Requires Python 3.9 or higher")
1824
@pytest.fixture(scope="module", autouse=True, name="test_data")
1925
def fixture_test_data() -> (
2026
Tuple[NDArray[np.float64], NDArray[np.float64], NDArray[np.float64]]
2127
):
2228
"""Test data."""
23-
space_x_y = np.arange(0, 10, 0.1)
29+
space_x_y = np.arange(0, 10, 0.1, dtype=np.float64)
2430
space_x, space_y = np.meshgrid(space_x_y, space_x_y)
2531
return space_x_y, space_x_y, np.sin(space_x) * np.cos(space_y)
2632

2733

2834
# Write test RIXSFigure
29-
30-
35+
@pytest.mark.skipif(sys.version_info < (3, 9), reason="Requires Python 3.9 or higher")
3136
class TestRixsFigure:
3237
"""Test of the RIXS Figure."""
3338

@@ -59,6 +64,7 @@ def test_create_rixs_figure(self, test_data: NDArray[np.float64]) -> None:
5964
assert isinstance(fig_xas, go.Figure)
6065

6166

67+
@pytest.mark.skipif(sys.version_info < (3, 9), reason="Requires Python 3.9 or higher")
6268
class TestRIXSApp:
6369
"""Test of the App."""
6470

‎spectrafit/test/test_models.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ def assert_isinstance(
662662
def test_key_not_available(self) -> None:
663663
"""Test if the key is not available."""
664664
args = {"autopeak": True, "global_": 0}
665-
x = np.arange(0, 10, 0.1)
665+
x = np.arange(0, 10, 0.1, dtype=np.float64)
666666
data = (
667667
np.sin(np.arange(0, 10, 0.1)) ** 3 + 2 * np.cos(np.arange(0, 10, 0.1)) ** 2
668668
)
@@ -705,17 +705,17 @@ def test_plateau_size(self) -> None:
705705
def test_distance(self) -> None:
706706
"""Test if the distance is calculated correctly."""
707707
args = {"autopeak": True, "global_": 0}
708-
x = 3 * np.arange(10, dtype=np.float64)
709-
data = 3 * np.exp(10, dtype=np.float64)
708+
x = 3.0 * np.arange(10, dtype=np.float64)
709+
data = 3.0 * np.exp(10, dtype=np.float64)
710710

711-
auto = AutoPeakDetection(x=x, data=data, args=args)
711+
auto = AutoPeakDetection(x=x, data=data, args=args) # type: ignore
712712
_val = auto.estimate_distance
713713
assert not isclose(_val, 1.0)
714714

715715
def test_autopeakdetection_mean(self) -> None:
716716
"""Test of auto default detection with negative values."""
717717
args = {"autopeak": True, "global_": 0}
718-
x = np.arange(0, 10, 0.1)
718+
x = np.arange(0, 10, 0.1, dtype=np.float64)
719719
data = (
720720
np.sin(np.arange(0, 10, 0.1)) ** 3 + 2 * np.cos(np.arange(0, 10, 0.1)) ** 2
721721
)

0 commit comments

Comments
 (0)
Please sign in to comment.