diff --git a/.copier-answers.yml b/.copier-answers.yml index c36c9d6d..dc8270dd 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,8 +1,8 @@ # Changes here will be overwritten by Copier; NEVER EDIT MANUALLY -_commit: 0b94d03 +_commit: c721391 _src_path: https://github.com/scipp/copier_template.git description: Visualization library for Scipp -max_python: '3.11' +max_python: '3.12' min_python: '3.9' namespace_package: '' nightly_deps: scipp diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20c647dc..44266a23 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,3 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) - name: CI on: @@ -24,15 +21,16 @@ 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' - - run: python -m pip install --upgrade pip - - run: python -m pip install -r requirements/ci.txt - - run: tox -e static - - uses: stefanzweifel/git-auto-commit-action@v5 + - uses: pre-commit/action@v3.0.1 + with: + extra_args: --all-files + - uses: pre-commit-ci/lite-action@v1.0.2 + if: always() with: - commit_message: Apply automatic formatting + msg: Apply automatic formatting tests: name: Tests diff --git a/.github/workflows/copier.yml b/.github/workflows/copier.yml new file mode 100644 index 00000000..b1fe6ce4 --- /dev/null +++ b/.github/workflows/copier.yml @@ -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' + 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. diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index f956ca1a..ab1be29a 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,6 +1,3 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) - name: Docs on: @@ -47,12 +44,12 @@ jobs: runs-on: 'ubuntu-22.04' steps: - run: sudo apt install --yes graphviz pandoc - - uses: actions/checkout@v3 + - 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 @@ -63,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.4.3 + - uses: JamesIves/github-pages-deploy-action@v4.5.0 if: ${{ inputs.publish }} with: branch: gh-pages diff --git a/.github/workflows/nightly_at_main.yml b/.github/workflows/nightly_at_main.yml index 10730688..08fdddd2 100644 --- a/.github/workflows/nightly_at_main.yml +++ b/.github/workflows/nightly_at_main.yml @@ -1,6 +1,3 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) - name: Nightly test at main branch on: diff --git a/.github/workflows/nightly_at_release.yml b/.github/workflows/nightly_at_release.yml index 7f1653bb..373c4546 100644 --- a/.github/workflows/nightly_at_release.yml +++ b/.github/workflows/nightly_at_release.yml @@ -1,6 +1,3 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) - name: Nightly tests at latest release on: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e492978a..d1317a76 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,3 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) - name: Release on: @@ -18,7 +15,7 @@ jobs: runs-on: 'ubuntu-22.04' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: true fetch-depth: 0 # history required so setuptools_scm can determine version @@ -31,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 @@ -41,11 +38,11 @@ jobs: runs-on: 'ubuntu-22.04' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 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' @@ -56,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 @@ -70,8 +67,8 @@ jobs: id-token: write if: github.event_name == 'release' && github.event.action == 'published' steps: - - uses: actions/download-artifact@v3 - - uses: pypa/gh-action-pypi-publish@v1.8.10 + - uses: actions/download-artifact@v4 + - uses: pypa/gh-action-pypi-publish@v1.8.14 upload_conda: name: Deploy Conda @@ -80,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 @@ -104,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 }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3cfb75de..5f56a069 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,3 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) - name: Test on: @@ -48,16 +45,16 @@ jobs: runs-on: ${{ inputs.os-variant }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ inputs.checkout_ref }} - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v5 with: python-version: ${{ inputs.python-version }} - 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 diff --git a/.github/workflows/unpinned.yml b/.github/workflows/unpinned.yml index 853c1ec5..46a84c1c 100644 --- a/.github/workflows/unpinned.yml +++ b/.github/workflows/unpinned.yml @@ -1,6 +1,3 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) - name: Unpinned tests at latest release on: diff --git a/.gitignore b/.gitignore index c66b1139..6004a49f 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ docs/generated/ *.raw *.cif *.rcif +*.ort # Images *.png diff --git a/conda/meta.yaml b/conda/meta.yaml index 698e32a5..bae3b67b 100644 --- a/conda/meta.yaml +++ b/conda/meta.yaml @@ -9,13 +9,21 @@ package: source: path: .. + +{% set pyproject = load_file_data('pyproject.toml') %} +{% set dependencies = pyproject.get('project', {}).get('dependencies', {}) %} + + requirements: build: - setuptools - setuptools_scm run: - - matplotlib - python>=3.9 + {% for package in dependencies %} + - {% if package == "graphviz" %}python-graphviz{% else %}{{ package }}{% endif %} + {% endfor %} + test: imports: diff --git a/docs/_templates/doc_version.html b/docs/_templates/doc_version.html index a348e28c..48f9aacf 100644 --- a/docs/_templates/doc_version.html +++ b/docs/_templates/doc_version.html @@ -1,2 +1,2 @@ -Current {{ project }} version: {{ version }} (older versions). +Current {{ project }} version: {{ version }} (older versions). diff --git a/docs/_typehints.py b/docs/_typehints.py deleted file mode 100644 index f9ef235e..00000000 --- a/docs/_typehints.py +++ /dev/null @@ -1,83 +0,0 @@ -from typing import Any, NewType, Optional - -import sphinx - -_typehint_aliases = { - 'scipp._scipp.core.DataArray': 'scipp.DataArray', - 'scipp._scipp.core.Dataset': 'scipp.Dataset', - 'scipp._scipp.core.DType': 'scipp.DType', - 'scipp._scipp.core.Unit': 'scipp.Unit', - 'scipp._scipp.core.Variable': 'scipp.Variable', - 'scipp.core.data_group.DataGroup': 'scipp.DataGroup', -} - - -def typehints_formatter_for(package: str) -> callable: - def typehints_formatter(annotation, config: sphinx.config.Config) -> Optional[str]: - """Format typehints with improved NewType handling.""" - _ = config - if _is_new_type(annotation): - return _format_new_type(annotation, package) - if _is_type_alias_type(annotation): - return _format_type_alias_type(annotation, package) - return None - - return typehints_formatter - - -def _is_new_type(annotation: Any) -> bool: - # TODO Switch to isinstance(key, NewType) once our minimum is Python 3.10 - # Note that we cannot pass mypy in Python<3.10 since NewType is not a type. - return hasattr(annotation, '__supertype__') - - -def _format_new_type(annotation: NewType, package: str) -> str: - return ( - f'{_internal_link(annotation, "class", package)}' - f' ({_link(annotation.__supertype__, "class")})' - ) - - -def _is_type_alias_type(annotation) -> bool: - try: - from typing import TypeAliasType - - return isinstance(annotation, TypeAliasType) - except ImportError: - return False # pre python 3.12 - - -def _format_type_alias_type(annotation: Any, package: str) -> str: - alias = _internal_link(annotation, "class", package, annotation.__type_params__) - value = _link(annotation.__value__, "class", _get_type_args(annotation.__value__)) - return f'{alias} ({value})' - - -def _get_type_args(ty: type) -> tuple[type, ...]: - if (args := getattr(ty, '__args__', None)) is not None: - return args # e.g. list[int] - return ty.__type_params__ - - -def _internal_link( - annotation: Any, - kind: str, - package: str, - type_params: Optional[tuple[type, ...]] = None, -) -> str: - target = f'{annotation.__module__}.{annotation.__name__}' - label = f'{annotation.__module__.removeprefix(package+".")}.{annotation.__name__}' - if type_params: - label += f'[{", ".join(ty.__name__ for ty in type_params)}]' - return f':{kind}:`{label} <{target}>`' - - -def _link(ty: type, kind: str, type_params: Optional[tuple[type, ...]] = None) -> str: - if ty.__module__ == 'builtins': - target = ty.__name__ - else: - target = f'{ty.__module__}.{ty.__name__}' - label = _typehint_aliases.get(target, target) - if type_params: - label += f'[{", ".join(ty.__name__ for ty in type_params)}]' - return f':{kind}:`{label} <{target}>`' diff --git a/docs/conf.py b/docs/conf.py index fd15328b..e12e3256 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -4,13 +4,10 @@ import doctest import os import sys - -import plopp +from importlib.metadata import version as get_version sys.path.insert(0, os.path.abspath('.')) -from _typehints import typehints_formatter_for # noqa: E402 - # General information about the project. project = u'Plopp' copyright = u'2024 Scipp contributors' @@ -26,6 +23,7 @@ 'sphinx.ext.intersphinx', 'sphinx.ext.mathjax', 'sphinx.ext.napoleon', + 'sphinx.ext.viewcode', 'sphinx_autodoc_typehints', 'sphinx_copybutton', 'sphinx_design', @@ -34,6 +32,14 @@ 'myst_parser', ] +try: + import sciline.sphinxext.domain_types # noqa: F401 + + extensions.append('sciline.sphinxext.domain_types') +except ModuleNotFoundError: + pass + + myst_enable_extensions = [ "amsmath", "colon_fence", @@ -77,7 +83,18 @@ } typehints_defaults = 'comma' typehints_use_rtype = False -typehints_formatter = typehints_formatter_for('plopp') + + +sciline_domain_types_prefix = 'plopp' +sciline_domain_types_aliases = { + 'scipp._scipp.core.DataArray': 'scipp.DataArray', + 'scipp._scipp.core.Dataset': 'scipp.Dataset', + 'scipp._scipp.core.DType': 'scipp.DType', + 'scipp._scipp.core.Unit': 'scipp.Unit', + 'scipp._scipp.core.Variable': 'scipp.Variable', + 'scipp.core.data_group.DataGroup': 'scipp.DataGroup', +} + # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -96,10 +113,8 @@ # built documents. # -# The short X.Y version. -version = plopp.__version__ -# The full version, including alpha/beta/rc tags. -release = plopp.__version__ +release = get_version("plopp") +version = ".".join(release.split('.')[:3]) # CalVer warning_is_error = True diff --git a/pyproject.toml b/pyproject.toml index 73f7b83a..21c5281f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Scientific/Engineering", "Typing :: Typed", ] diff --git a/requirements/base.in b/requirements/base.in index 72f66398..a08edf9b 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -1,4 +1,6 @@ -c constraints.in +# Anything above "--- END OF CUSTOM SECTION ---" +# will not be touched by ``make_base.py`` # --- END OF CUSTOM SECTION --- # The following was generated by 'tox -e deps', DO NOT EDIT MANUALLY! matplotlib>=3.5 diff --git a/requirements/constraints.in b/requirements/constraints.in index c941f332..e69de29b 100644 --- a/requirements/constraints.in +++ b/requirements/constraints.in @@ -1,5 +0,0 @@ -# Temporary until questionary (dep of copier) updates -# See https://github.com/tmbo/questionary/blob/2df265534f3eb77aafcf70902e53e80beb1793e0/pyproject.toml#L36C43-L36C110 -prompt-toolkit==3.0.36 -# Temporary pinned until prompt-tookit conflict is resolved. -ipython==8.9.0 diff --git a/requirements/make_base.py b/requirements/make_base.py index b26a1c2e..1e1f48e3 100644 --- a/requirements/make_base.py +++ b/requirements/make_base.py @@ -1,6 +1,3 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright (c) 2023 Scipp contributors (https://github.com/scipp) - import sys from argparse import ArgumentParser from pathlib import Path @@ -43,7 +40,7 @@ def write_dependencies(dependency_name: str, dependencies: List[str]) -> None: with open("../pyproject.toml", "rb") as toml_file: pyproject = tomli.load(toml_file) dependencies = pyproject["project"].get("dependencies") - if not dependencies: + if dependencies is None: raise RuntimeError("No dependencies found in pyproject.toml") dependencies = [dep.strip().strip('"') for dep in dependencies]