-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add ruff to ci setup #82
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
42e2a8b
Add ruff to ci setup
adonath 4d0ccb9
Fix ruff errors in common/
adonath fbe6bd4
Fix ruff errors in cupy/
adonath c7c27be
Fix ruff errors in numpy/
adonath d3d57b9
Fix ruff errors in torch/
adonath 0d437cd
Fix ruff errors in tests/
adonath afccf29
Fix ruff errors in array_api_compat/__init__.py
adonath 2395ea0
Implement _get_all_public_members
adonath 645cef2
Move linalg aliases to _aliases
adonath 5a6f411
Fix ruff errors in cupy/linalg
adonath 0ff0836
Move linalg aliases to numpy/_aliases
adonath f4d78c7
Fix ruff errors in numpy/linalg
adonath 31bbbfa
Hide helper variables in cupy/linalg.py
adonath 5ecc7b5
Move linalg aliases to torch/_aliases
adonath 8e4e9ca
Fix ruff errors in torch/linalg
adonath 5c66efc
Fix final ruff errors in array_api_compat/torch/__init__.py
adonath bca606d
Expose public members from numpy an cupy in __all__ respectively
adonath 890c497
Clean up
adonath b2f9557
Add importorskip torch
adonath 52ef9ee
Use importorskip
adonath b069230
Add missing isdtype
adonath ff51015
Fix tests
adonath b0a323d
Rename import_ to import_or_skip_cupy
adonath 0ec2d89
Add missing imports and sort __all__
adonath 2baa4da
More cleanup
adonath efd745c
Remove redefinitions
adonath 49f2b7a
Add ruff select F822 option [skip ci]
adonath a748bfa
Add PLC0414 error code as well
adonath 6b4e92c
Avoid in place modification of __all__ in _get_all_public_members
adonath a92f640
Add sort check for __all__
adonath 9b1110b
Sort __all__ lists
adonath 68c788f
Use * import for array_api_compat/__init__.py
adonath 1720fb6
Update array_api_compat/_internal.py
adonath 5cd47df
Adapt dask
adonath c5d55ae
Fix ruff errors for dask/array/linalg
adonath 49851b5
Fix __all__ order in dask linalg
adonath 2db3d6a
Fix import of __all__ in dask/array/__init__.py
adonath 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 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,19 @@ | ||
name: CI | ||
on: [push, pull_request] | ||
jobs: | ||
check-ruff: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.11" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install ruff | ||
# Update output format to enable automatic inline annotations. | ||
- name: Run Ruff | ||
run: ruff check --output-format=github --select F822,PLC0414,RUF022 --preview . |
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 |
---|---|---|
|
@@ -19,4 +19,4 @@ | |
""" | ||
__version__ = '1.4.1' | ||
|
||
from .common import * | ||
from .common import * # noqa: F401, F403 |
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 |
---|---|---|
@@ -1 +1,17 @@ | ||
from ._helpers import * | ||
from ._helpers import ( | ||
array_namespace, | ||
device, | ||
get_namespace, | ||
is_array_api_obj, | ||
size, | ||
to_device, | ||
) | ||
|
||
__all__ = [ | ||
"array_namespace", | ||
"device", | ||
"get_namespace", | ||
"is_array_api_obj", | ||
"size", | ||
"to_device", | ||
] |
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 |
---|---|---|
@@ -1,16 +1,153 @@ | ||
from cupy import * | ||
import cupy as _cp | ||
from cupy import * # noqa: F401, F403 | ||
|
||
# from cupy import * doesn't overwrite these builtin names | ||
from cupy import abs, max, min, round | ||
|
||
from .._internal import _get_all_public_members | ||
from ..common._helpers import ( | ||
array_namespace, | ||
device, | ||
get_namespace, | ||
is_array_api_obj, | ||
size, | ||
to_device, | ||
) | ||
|
||
# These imports may overwrite names from the import * above. | ||
from ._aliases import * | ||
from ._aliases import ( | ||
UniqueAllResult, | ||
UniqueCountsResult, | ||
UniqueInverseResult, | ||
acos, | ||
acosh, | ||
arange, | ||
argsort, | ||
asarray, | ||
asarray_cupy, | ||
asin, | ||
asinh, | ||
astype, | ||
atan, | ||
atan2, | ||
atanh, | ||
bitwise_invert, | ||
bitwise_left_shift, | ||
bitwise_right_shift, | ||
bool, | ||
ceil, | ||
concat, | ||
empty, | ||
empty_like, | ||
eye, | ||
floor, | ||
full, | ||
full_like, | ||
isdtype, | ||
linspace, | ||
matmul, | ||
matrix_transpose, | ||
nonzero, | ||
ones, | ||
ones_like, | ||
permute_dims, | ||
pow, | ||
prod, | ||
reshape, | ||
sort, | ||
std, | ||
sum, | ||
tensordot, | ||
trunc, | ||
unique_all, | ||
unique_counts, | ||
unique_inverse, | ||
unique_values, | ||
var, | ||
vecdot, | ||
zeros, | ||
zeros_like, | ||
) | ||
|
||
# See the comment in the numpy __init__.py | ||
__import__(__package__ + '.linalg') | ||
__all__ = [] | ||
|
||
__all__ += _get_all_public_members(_cp) | ||
|
||
__all__ += [ | ||
"abs", | ||
"max", | ||
"min", | ||
"round", | ||
] | ||
|
||
from .linalg import matrix_transpose, vecdot | ||
__all__ += [ | ||
"array_namespace", | ||
"device", | ||
"get_namespace", | ||
"is_array_api_obj", | ||
"size", | ||
"to_device", | ||
] | ||
|
||
from ..common._helpers import * | ||
__all__ += [ | ||
"UniqueAllResult", | ||
"UniqueCountsResult", | ||
"UniqueInverseResult", | ||
"acos", | ||
"acosh", | ||
"arange", | ||
"argsort", | ||
"asarray", | ||
"asarray_cupy", | ||
"asin", | ||
"asinh", | ||
"astype", | ||
"atan", | ||
"atan2", | ||
"atanh", | ||
"bitwise_invert", | ||
"bitwise_left_shift", | ||
"bitwise_right_shift", | ||
"bool", | ||
"ceil", | ||
"concat", | ||
"empty", | ||
"empty_like", | ||
"eye", | ||
"floor", | ||
"full", | ||
"full_like", | ||
"isdtype", | ||
"linspace", | ||
"matmul", | ||
"matrix_transpose", | ||
"nonzero", | ||
"ones", | ||
"ones_like", | ||
"permute_dims", | ||
"pow", | ||
"prod", | ||
"reshape", | ||
"sort", | ||
"std", | ||
"sum", | ||
"tensordot", | ||
"trunc", | ||
"unique_all", | ||
"unique_counts", | ||
"unique_inverse", | ||
"unique_values", | ||
"var", | ||
"zeros", | ||
"zeros_like", | ||
] | ||
|
||
__all__ += [ | ||
"matrix_transpose", | ||
"vecdot", | ||
] | ||
|
||
# See the comment in the numpy __init__.py | ||
__import__(__package__ + ".linalg") | ||
|
||
__array_api_version__ = '2022.12' | ||
__array_api_version__ = "2022.12" |
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.
This is monkeypatching
torch.__all__
etc.? We don't want to do that.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.
Yes, but this just keeps the current behavior. Take a look at https://github.com/data-apis/array-api-compat/blob/main/array_api_compat/torch/__init__.py#L3
I have not checked whether this is still necessary, but probably we have to keep it this way?
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.
I checked with the following code:
And this gives:
So indeed
__all__
does not contain multiple members and most importantly it does not contain the dtypes.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.
That code does not modify the
torch.__all__
list:Generally speaking, this package should not monkeypatch the underlying libraries.
Yes, that's a known issue. pytorch/pytorch#91908
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.
Oh, now I understand. I did not mean to actually modify
torch.__all__
in place but copy and extend instead. I'll fix that behavior.