Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: 8484c9e
_commit: 7afbc9a
_src_path: gh:scipp/copier_template
description: Diffraction data reduction for the European Spallation Source
max_python: '3.12'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: |
echo "min_python=$(cat .github/workflows/python-version-ci)" >> $GITHUB_OUTPUT
echo "min_tox_env=py$(cat .github/workflows/python-version-ci | sed 's/\.//g')" >> $GITHUB_OUTPUT
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version-file: '.github/workflows/python-version-ci'
- uses: pre-commit/action@v3.0.1
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Copier template sync

on:
workflow_dispatch:
schedule:
- cron: '0 1 * * 1'

jobs:
update:
name: Sync with copier template
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.X'
- run: pip install copier
- run: copier update --skip-answered --vcs-ref=HEAD --conflict=rej
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
title: '[CRON] Sync with copier template'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scipp bot isn't here but let's try something anyway. We can run the action through workflow dispatch.

body: |
This PR updates the project to the latest version of scipp's [copier-template](https://github.com/scipp/copier_template).
Remember to check for any conflicts and resolve them.
7 changes: 4 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ jobs:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.branch == '' && github.ref_name || inputs.branch }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0 # history required so cmake can determine version
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version-file: '.github/workflows/python-version-ci'
- run: python -m pip install --upgrade pip
Expand All @@ -59,12 +60,12 @@ jobs:
if: ${{ inputs.version == '' }}
- run: tox -e linkcheck
if: ${{ inputs.linkcheck }}
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: docs_html
path: html/

- uses: JamesIves/github-pages-deploy-action@v4.5.0
- uses: JamesIves/github-pages-deploy-action@v4.6.0
if: ${{ inputs.publish }}
with:
branch: gh-pages
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
boa
- run: conda mambabuild --channel conda-forge --channel scipp --no-anaconda-upload --override-channels --output-folder conda/package conda

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: conda-package-noarch
path: conda/package/noarch/*.tar.bz2
Expand All @@ -42,7 +42,7 @@ jobs:
with:
fetch-depth: 0 # history required so setuptools_scm can determine version

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version-file: '.github/workflows/python-version-ci'

Expand All @@ -53,7 +53,7 @@ jobs:
run: python -m build

- name: Upload wheels
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: dist
path: dist
Expand All @@ -67,7 +67,7 @@ jobs:
id-token: write
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
- uses: pypa/gh-action-pypi-publish@v1.8.14

upload_conda:
Expand All @@ -77,7 +77,7 @@ jobs:
if: github.event_name == 'release' && github.event.action == 'published'

steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
- uses: mamba-org/setup-micromamba@v1
with:
environment-name: upload-env
Expand All @@ -101,7 +101,7 @@ jobs:
permissions:
contents: write # This is needed so that the action can upload the asset
steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
- name: Zip documentation
run: |
mv docs_html documentation-${{ github.ref_name }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- run: python -m pip install --upgrade pip
- run: python -m pip install -r ${{ inputs.pip-recipe }}
- run: tox -e ${{ inputs.tox-env }}
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: ${{ inputs.coverage-report }}
with:
name: CoverageReport
Expand Down
29 changes: 8 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,21 @@ repos:
- id: trailing-whitespace
args: [ --markdown-linebreak-ext=md ]
exclude: '\.svg'
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.11.0
hooks:
- id: black
- repo: https://github.com/kynan/nbstripout
rev: 0.6.0
hooks:
- id: nbstripout
types: [ "jupyter" ]
args: [ "--drop-empty-cells",
"--extra-keys 'metadata.language_info.version cell.metadata.jp-MarkdownHeadingCollapsed cell.metadata.pycharm'" ]
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
types: ["python"]
additional_dependencies: ["flake8-bugbear==23.9.16"]
- repo: https://github.com/pycqa/bandit
rev: 1.7.5
hooks:
- id: bandit
additional_dependencies: ["bandit[toml]"]
args: ["-c", "pyproject.toml"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
hooks:
- id: ruff
args: [ --fix ]
types_or: [ python, pyi, jupyter ]
- id: ruff-format
types_or: [ python, pyi ]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
Expand Down
10 changes: 10 additions & 0 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ package:
source:
path: ..


{% set pyproject = load_file_data('pyproject.toml') %}
{% set dependencies = pyproject.get('project', {}).get('dependencies', {}) %}


requirements:
build:
- setuptools
Expand All @@ -23,6 +28,11 @@ requirements:
- scippnexus>=23.12.0
- python>=3.10

{% for package in dependencies %}
- {% if package == "graphviz" %}python-graphviz{% else %}{{ package }}{% endif %}
{% endfor %}


test:
imports:
- ess.diffraction
Expand Down
15 changes: 6 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import doctest
import os
import sys

from ess import diffraction
from importlib.metadata import version as get_version

sys.path.insert(0, os.path.abspath('.'))

# General information about the project.
project = u'ESSdiffraction'
copyright = u'2024 Scipp contributors'
author = u'Scipp contributors'
project = 'ESSdiffraction'
copyright = '2024 Scipp contributors'
author = 'Scipp contributors'

html_show_sourcelink = True

Expand Down Expand Up @@ -112,10 +111,8 @@
# built documents.
#

# The short X.Y version.
version = diffraction.__version__
# The full version, including alpha/beta/rc tags.
release = diffraction.__version__
release = get_version("essdiffraction")
version = ".".join(release.split('.')[:3]) # CalVer

warning_is_error = True

Expand Down
2 changes: 1 addition & 1 deletion docs/developer/coding-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Code formatting

There are no explicit code formatting conventions since we use `black` to enforce a format.
There are no explicit code formatting conventions since we use `ruff` to enforce a format.

## Docstring format

Expand Down
2 changes: 0 additions & 2 deletions docs/user-guide/dream/dream-data-reduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"import scipp as sc\n",
"import scippneutron as scn\n",
"import sciline\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"import scippneutron as scn\n",
"import sciline\n",
"\n",
"import ess.diffraction\n",
"from ess import powder\n",
"from ess.powder.external import powgen\n",
"from ess.powder.types import *"
Expand Down
45 changes: 35 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,43 @@ filterwarnings = [
'ignore:\s*Pyarrow will become a required dependency of pandas:DeprecationWarning',
]

[tool.bandit]
# Excluding tests because bandit doesn't like `assert`.
exclude_dirs = ["docs/conf.py", "tests"]
[tool.ruff]
line-length = 88
extend-include = ["*.ipynb"]
extend-exclude = [
".*", "__pycache__", "build", "dist", "install",
]

[tool.ruff.lint]
# See https://docs.astral.sh/ruff/rules/
select = ["B", "C4", "DTZ", "E", "F", "G", "I", "PERF", "PGH", "PT", "PYI", "RUF", "S", "T20", "W"]
ignore = [
# Conflict with ruff format, see
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"COM812", "COM819", "D206", "D300", "E111", "E114", "E117", "ISC001", "ISC002", "Q000", "Q001", "Q002", "Q003", "W191",
]
fixable = ["I001", "B010"]
isort.known-first-party = ["essdiffraction"]
pydocstyle.convention = "numpy"

[tool.black]
skip-string-normalization = true
[tool.ruff.lint.per-file-ignores]
# those files have an increased risk of relying on import order
"__init__.py" = ["I"]
"tests/*" = [
"S101", # asserts are fine in tests
"B018", # 'useless expressions' are ok because some tests just check for exceptions
]
"*.ipynb" = [
"E501", # longer lines are sometimes more readable
"F403", # *-imports used with domain types
"F405", # linter may fail to find names because of *-imports
"I", # we don't collect imports at the top
"S101", # asserts are used for demonstration and are safe in notebooks
"T201", # printing is ok for demonstration purposes
]

[tool.isort]
skip_gitignore = true
profile = "black"
known_first_party = ["essdiffraction"]
[tool.ruff.format]
quote-style = "preserve"

[tool.mypy]
strict = true
Expand All @@ -87,5 +113,4 @@ enable_error_code = [
"redundant-expr",
"truthy-bool",
]
show_error_codes = true
warn_unreachable = true
4 changes: 0 additions & 4 deletions setup.cfg

This file was deleted.

1 change: 1 addition & 0 deletions src/ess/diffraction/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
# ruff: noqa: E402, F401

"""
Components for diffraction experiments (powder and single crystal).
Expand Down
1 change: 1 addition & 0 deletions src/ess/dream/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
Components for DREAM
"""

import importlib.metadata

from . import beamline, data
Expand Down
12 changes: 7 additions & 5 deletions src/ess/dream/instrument_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ def _add_module_control(self):

self.fig = self.scatter[0]
self.cutting_tool = self.scatter[1]
self.artist_mapping = {
name: key for name, key in zip(self.data.keys(), self.fig.artists.keys())
}
self.artist_mapping = dict(
zip(self.data.keys(), self.fig.artists.keys(), strict=True)
)
self.checkboxes = {
key: ipw.Checkbox(
value=True,
Expand All @@ -130,8 +130,10 @@ def _add_module_control(self):
}

self.modules_widget = ipw.HBox(
[ipw.HTML(value="Modules:     ")]
+ list(self.checkboxes.values())
[
ipw.HTML(value="Modules:     "),
*self.checkboxes.values(),
]
)
for key, ch in self.checkboxes.items():
ch.key = key
Expand Down
7 changes: 3 additions & 4 deletions src/ess/dream/io/geant4.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
import numpy as np
import sciline
import scipp as sc
from ess.reduce.nexus import extract_detector_data

from ess.powder.types import (
DetectorName,
FilePath,
RawDetector,
RawDetectorData,
RunType,
)
from ess.reduce.nexus import extract_detector_data

MANTLE_DETECTOR_ID = sc.index(7)
HIGH_RES_DETECTOR_ID = sc.index(8)
Expand All @@ -28,7 +27,7 @@ class AllRawDetectors(sciline.Scope[RunType, sc.DataGroup], sc.DataGroup):


def load_geant4_csv(
file_path: Union[FilePath[RunType], str, StringIO, BytesIO]
file_path: Union[FilePath[RunType], str, StringIO, BytesIO],
) -> AllRawDetectors[RunType]:
"""Load a GEANT4 CSV file for DREAM.

Expand Down Expand Up @@ -73,7 +72,7 @@ def extract_geant4_detector_data(


def _load_raw_events(
file_path: Union[str, os.PathLike, StringIO, BytesIO]
file_path: Union[str, os.PathLike, StringIO, BytesIO],
) -> sc.DataArray:
table = sc.io.load_csv(
file_path, sep='\t', header_parser='bracket', data_columns=[]
Expand Down
Loading