Skip to content

Commit

Permalink
Merge pull request #52 from scipp/copier-update-2024-06
Browse files Browse the repository at this point in the history
Copier update 2024 06
  • Loading branch information
nvaytet authored Jun 19, 2024
2 parents acf1cba + bd382db commit 92bb40c
Show file tree
Hide file tree
Showing 32 changed files with 121 additions and 708 deletions.
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: '2955216'
_commit: 91ffffb
_src_path: gh:scipp/copier_template
description: Reflectometry data reduction for the European Spallation Source
max_python: '3.12'
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ 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@v5
with:
Expand All @@ -64,7 +65,7 @@ jobs:
name: docs_html
path: html/

- uses: JamesIves/github-pages-deploy-action@v4.5.0
- uses: JamesIves/github-pages-deploy-action@v4.6.1
if: ${{ inputs.publish }}
with:
branch: gh-pages
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]

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
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.3
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
20 changes: 10 additions & 10 deletions conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ package:
source:
path: ..


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


requirements:
build:
- setuptools
- setuptools_scm
run:
- dask
- python-dateutil
- graphviz
- plopp
- pythreejs
- orsopy
- sciline>=23.9.1
- scipp>=23.8.0
- scippneutron>=23.9.0
- essreduce
- python>=3.10

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


test:
imports:
- ess.reflectometry
Expand Down
2 changes: 1 addition & 1 deletion docs/_templates/doc_version.html
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- This will display the version of the docs -->
Current {{ project }} version: {{ version }} (<a href="https://github.com/{{orgname}}/{{ project|lower }}/releases">older versions</a>).
Current ESSreflectometry version: {{ version }} (<a href="https://github.com/scipp/essreflectometry/releases">older versions</a>).
29 changes: 19 additions & 10 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# -*- coding: utf-8 -*-

import doctest
import os
import sys
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as get_version

from ess import reflectometry
from sphinx.util import logging

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

logger = logging.getLogger(__name__)

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

html_show_sourcelink = True

Expand All @@ -35,6 +37,8 @@
import sciline.sphinxext.domain_types # noqa: F401

extensions.append('sciline.sphinxext.domain_types')
# See https://github.com/tox-dev/sphinx-autodoc-typehints/issues/457
suppress_warnings = ["config.cache"]
except ModuleNotFoundError:
pass

Expand Down Expand Up @@ -111,10 +115,15 @@
# built documents.
#

# The short X.Y version.
version = reflectometry.__version__
# The full version, including alpha/beta/rc tags.
release = reflectometry.__version__
try:
release = get_version("essreflectometry")
version = ".".join(release.split('.')[:3]) # CalVer
except PackageNotFoundError:
logger.info(
"Warning: determining version from package metadata failed, falling back to "
"a dummy version number."
)
release = version = "0.0.0-dev"

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
4 changes: 1 addition & 3 deletions docs/user-guide/amor/amor-reduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"outputs": [],
"source": [
"import scipp as sc\n",
"import sciline\n",
"from ess import amor\n",
"from ess.reflectometry.types import *\n",
"from ess.amor.types import *"
Expand Down Expand Up @@ -354,8 +353,7 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
Expand Down
9 changes: 4 additions & 5 deletions docs/user-guide/amor/compare-to-eos.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"\n",
"import scipp as sc\n",
"import plopp as pp\n",
"import sciline\n",
"from ess import amor\n",
"from ess.reflectometry.types import *\n",
"from ess.amor.types import ChopperPhase"
Expand Down Expand Up @@ -137,7 +136,7 @@
"outputs": [],
"source": [
"# PSI results\n",
"for key, angle in mu.items():\n",
"for key in mu:\n",
" d = orsopy.fileio.load_orso(amor.data.amor_psi_software_result(key))[0].data\n",
" y = sc.array(dims=['Q'], values=d[:, 1], variances=d[:, 2] ** 2)\n",
" results['psi'][key] = sc.DataArray(\n",
Expand All @@ -162,7 +161,7 @@
"source": [
"fig, axs = plt.subplots(3, 2, figsize=(12, 12))\n",
"\n",
"for ax, (key, angle) in zip(axs.ravel(), mu.items()):\n",
"for ax, (key, angle) in zip(axs.ravel(), mu.items(), strict=True):\n",
" pp.plot(\n",
" {\n",
" facility: results[facility][key][results[facility][key].data > 0.0]\n",
Expand Down Expand Up @@ -196,9 +195,9 @@
"source": [
"fig, axs = plt.subplots(1, 2, figsize=(12, 4))\n",
"\n",
"for ax, (facility, res) in zip(axs.ravel(), results.items()):\n",
"for ax, (facility, res) in zip(axs.ravel(), results.items(), strict=True):\n",
" pp.plot(\n",
" {k: v for k, v in list(res.items())[:4]}, # First 4 curves\n",
" dict(list(res.items())[:4]), # First 4 curves\n",
" ax=ax,\n",
" norm='log',\n",
" ls='solid',\n",
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:.*metadata to be logged in the data array, it is necessary to install the orsopy package.:UserWarning",
]

[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", "UP", "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 = ["essreflectometry"]
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 = ["essreflectometry"]
[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
3 changes: 0 additions & 3 deletions requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ copier
jupyterlab
pip-compile-multi
pre-commit

# See https://github.com/copier-org/copier/issues/1568
pyyaml-include<2
3 changes: 1 addition & 2 deletions requirements/make_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
from argparse import ArgumentParser
from pathlib import Path
from typing import List

import tomli

Expand All @@ -20,7 +19,7 @@
"""


def write_dependencies(dependency_name: str, dependencies: List[str]) -> None:
def write_dependencies(dependency_name: str, dependencies: list[str]) -> None:
path = Path(f"{dependency_name}.in")
if path.exists():
sections = path.read_text().split(CUSTOM_AUTO_SEPARATOR)
Expand Down
4 changes: 0 additions & 4 deletions setup.cfg

This file was deleted.

6 changes: 2 additions & 4 deletions src/ess/amor/geometry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
from typing import Tuple

import scipp as sc


Expand Down Expand Up @@ -30,7 +28,7 @@ class Detector:

def _pixel_coordinate_in_detector_system(
pixelID: sc.Variable,
) -> Tuple[sc.Variable, sc.Variable]:
) -> tuple[sc.Variable, sc.Variable]:
"""Determines beam travel distance inside the detector
and the beam divergence angle from the detector number."""
(bladeNr, bPixel) = (
Expand All @@ -55,7 +53,7 @@ def _pixel_coordinate_in_detector_system(

def pixel_coordinate_in_lab_frame(
pixelID: sc.Variable, nu: sc.Variable
) -> Tuple[sc.Variable, sc.Variable]:
) -> tuple[sc.Variable, sc.Variable]:
"""Computes spatial coordinates (lab reference frame), and the beam divergence
angle for the detector pixel associated with `pixelID`"""
distance_in_detector, divergence_angle = _pixel_coordinate_in_detector_system(
Expand Down
8 changes: 2 additions & 6 deletions src/ess/amor/orso.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
"""ORSO utilities for Amor."""

from typing import Optional

import numpy as np
import scipp as sc
from orsopy.fileio import base as orso_base
Expand Down Expand Up @@ -81,9 +79,7 @@ def _extract_values_array(var: sc.Variable) -> np.ndarray:
return var.values


def _limits_of_coord(
data: sc.DataArray, name: str
) -> Optional[tuple[float, float, str]]:
def _limits_of_coord(data: sc.DataArray, name: str) -> tuple[float, float, str] | None:
if (coord := _get_coord(data, name)) is None:
return None
min_ = coord.min().value
Expand All @@ -92,7 +88,7 @@ def _limits_of_coord(
return float(min_), float(max_), _ascii_unit(coord.unit)


def _get_coord(data: sc.DataArray, name: str) -> Optional[sc.Variable]:
def _get_coord(data: sc.DataArray, name: str) -> sc.Variable | None:
if name in data.coords:
return sc.DataArray(data=data.coords[name], masks=data.masks)
if (data.bins is not None) and (name in data.bins.coords):
Expand Down
Loading

0 comments on commit 92bb40c

Please sign in to comment.