-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d1dc884
Copier update
jl-wynen 68cf066
Update dependencies
jl-wynen 140b229
Apply automatic formatting
jl-wynen f434735
Fix buildconfig versions
jl-wynen 8290c38
Only run Linux py3.9 tests once
jl-wynen fe060f7
Use ubuntu 22.04
jl-wynen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ html | |
|
||
*.sw? | ||
|
||
# Environments | ||
venv | ||
|
||
# Caches | ||
.clangd/ | ||
*.ipynb_checkpoints | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
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}>`' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See scipp/copier_template#124