Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update copier and dependencies #485

Merged
merged 6 commits into from
Jan 24, 2024
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
40 changes: 0 additions & 40 deletions .buildconfig/ci-linux-39.yml

This file was deleted.

11 changes: 5 additions & 6 deletions .buildconfig/ci-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@ dependencies:
- ipympl==0.9.3
- ipywidgets==8.0.6
- mantid==6.8.0
- matplotlib==3.7.1
- matplotlib==3.8.2
- ninja==1.11.1
- plopp==23.10.1
- plopp==24.01.1
- pooch==1.7.0
- pytest==7.4.2
- pytest-asyncio==0.21.1
- python-confluent-kafka==2.1.1
- python-graphviz==0.20.1
- pythreejs==2.4.2
- scipp==23.07.0
- scippnexus==23.11.0
- scipy==1.11.3
- scippnexus==23.12.1
- scipy==1.12.0
- tox==4.11.3

# docs
- myst-parser==2.0.0
- nbsphinx==0.9.3
- packaging==23.2
- pandoc==3.1.3
- pydata-sphinx-theme==0.14.4
- requests==2.31.0
- pydata-sphinx-theme==0.15.2
- sphinx==7.2.6
- sphinx-autodoc-typehints==1.25.2
- sphinx-copybutton==0.5.2
Expand Down
10 changes: 5 additions & 5 deletions .buildconfig/ci-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ channels:
dependencies:
- comm=0.1.4 # earlier versions break tests with ipywidgets with latest ipykernel
- h5py==3.8.0
- hypothesis==6.71.0
- hypothesis==6.88.1
- mantid==6.8.0
- matplotlib==3.7.1
- matplotlib==3.8.2
- ninja==1.11.1
- plopp==23.10.1
- plopp==24.01.1
- pooch==1.7.0
- pytest==7.4.2
- pytest-asyncio==0.21.1
- pythreejs==2.4.2
- scipp==23.07.0
- scippnexus==23.11.0
- scipy==1.11.3
- scippnexus==23.12.1
- scipy==1.12.0
8 changes: 4 additions & 4 deletions .buildconfig/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ dependencies:
- h5py==3.8.0
- hypothesis==6.88.1
- mantid==6.8.0
- matplotlib==3.8.0
- matplotlib==3.8.2
- ninja==1.11.1
- plopp==23.10.1
- plopp==24.01.1
- pooch==1.7.0
- pytest==7.4.2
- pytest-asyncio==0.21.1
- pythreejs==2.4.2
- scipp==23.07.0
- scippnexus==23.11.0
- scipy==1.11.3
- scippnexus==23.12.1
- scipy==1.12.0
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: ff406b1
_commit: 0b94d03
_src_path: gh:scipp/copier_template
description: Neutron scattering tools for Data Reduction
max_python: '3.11'
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/pr_and_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ jobs:
fail-fast: false
matrix:
variant:
- {os: ubuntu-20.04, python-version: "3.10", build-config: ci-linux}
- {os: ubuntu-22.04, python-version: "3.10", build-config: ci-linux}
- {os: macos-11, python-version: "3.10", build-config: ci-macos}
- {os: windows-2019, python-version: "3.10", build-config: ci-windows}
- {os: ubuntu-20.04, python-version: "3.9", build-config: ci-linux-39}

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ html

*.sw?

# Environments
venv

# Caches
.clangd/
*.ipynb_checkpoints
Expand Down
3 changes: 2 additions & 1 deletion conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ test:
- pyproject.toml
- tests/
commands:
- python -m pytest tests
# We ignore warnings during release package builds
- python -m pytest -Wignore tests

build:
ignore_run_exports:
Expand Down
83 changes: 83 additions & 0 deletions docs/_typehints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from typing import Any, NewType, Optional
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain what the code in this file is doing? How differently do things render in the docs when this is used?

Copy link
Member Author

Choose a reason for hiding this comment

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


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}>`'
3 changes: 3 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

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

from _typehints import typehints_formatter_for # noqa: E402

# General information about the project.
project = u'ScippNeutron'
copyright = u'2023 Scipp contributors'
Expand Down Expand Up @@ -82,6 +84,7 @@
}
typehints_defaults = 'comma'
typehints_use_rtype = False
typehints_formatter = typehints_formatter_for('scippneutron')

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down
23 changes: 13 additions & 10 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ decorator==5.1.1
# via ipython
executing==2.0.1
# via stack-data
fonttools==4.46.0
fonttools==4.47.2
# via matplotlib
graphviz==0.20.1
# via scipp
Expand All @@ -32,6 +32,8 @@ h5py==3.10.0
# scippnexus
idna==3.6
# via requests
importlib-resources==6.1.1
# via matplotlib
ipython==8.9.0
# via -r base.in
jedi==0.19.1
Expand All @@ -44,7 +46,7 @@ matplotlib==3.8.2
# scipp
matplotlib-inline==0.1.6
# via ipython
numpy==1.26.2
numpy==1.26.3
# via
# -r base.in
# contourpy
Expand All @@ -62,11 +64,11 @@ pexpect==4.9.0
# via ipython
pickleshare==0.7.5
# via ipython
pillow==10.1.0
pillow==10.2.0
# via matplotlib
platformdirs==4.0.0
platformdirs==4.1.0
# via pooch
plopp==23.11.0
plopp==24.1.1
# via scipp
pooch==1.8.0
# via
Expand All @@ -93,11 +95,10 @@ requests==2.31.0
scipp[all]==23.12.0
# via
# -r base.in
# scipp
# scippnexus
scippnexus==23.12.0
scippnexus==23.12.1
# via -r base.in
scipy==1.11.4
scipy==1.12.0
# via
# -r base.in
# scipp
Expand All @@ -108,11 +109,13 @@ six==1.16.0
# python-dateutil
stack-data==0.6.3
# via ipython
traitlets==5.14.0
traitlets==5.14.1
# via
# ipython
# matplotlib-inline
urllib3==2.1.0
# via requests
wcwidth==0.2.12
wcwidth==0.2.13
# via prompt-toolkit
zipp==3.17.0
# via importlib-resources
16 changes: 8 additions & 8 deletions requirements/basetest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#
asttokens==2.4.1
# via stack-data
attrs==23.1.0
attrs==23.2.0
# via hypothesis
backcall==0.2.0
# via ipython
comm==0.2.0
comm==0.2.1
# via ipywidgets
decorator==5.1.1
# via ipython
Expand All @@ -23,7 +23,7 @@ execnet==2.0.2
# via pytest-xdist
executing==2.0.1
# via stack-data
hypothesis==6.91.0
hypothesis==6.96.4
# via -r basetest.in
iniconfig==2.0.0
# via pytest
Expand All @@ -43,7 +43,7 @@ jupyterlab-widgets==3.0.9
# via ipywidgets
matplotlib-inline==0.1.6
# via ipython
numpy==1.26.2
numpy==1.26.3
# via
# ipydatawidgets
# pythreejs
Expand All @@ -61,15 +61,15 @@ prompt-toolkit==3.0.36
# via
# -r basetest.in
# ipython
psutil==5.9.6
psutil==5.9.8
# via -r basetest.in
ptyprocess==0.7.0
# via pexpect
pure-eval==0.2.2
# via stack-data
pygments==2.17.2
# via ipython
pytest==7.4.3
pytest==7.4.4
# via
# -r basetest.in
# pytest-xdist
Expand All @@ -85,7 +85,7 @@ stack-data==0.6.3
# via ipython
tomli==2.0.1
# via pytest
traitlets==5.14.0
traitlets==5.14.1
# via
# comm
# ipython
Expand All @@ -95,7 +95,7 @@ traitlets==5.14.0
# traittypes
traittypes==0.2.1
# via ipydatawidgets
wcwidth==0.2.12
wcwidth==0.2.13
# via prompt-toolkit
widgetsnbextension==4.0.9
# via ipywidgets
Loading
Loading