Skip to content

Commit 1f33da1

Browse files
committed
Run linter -- add hooks
1 parent 982860d commit 1f33da1

19 files changed

+267
-309
lines changed

.github/workflows/publish-to-pypi.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ name: Publish Package to PyPI and TestPyPI
33
on:
44
workflow_dispatch:
55
push:
6-
paths:
6+
paths:
77
- pyproject.toml
88

9-
jobs:
9+
jobs:
1010
create-tag:
1111
name: Create tag from new version
1212
runs-on: "ubuntu-latest"
1313
permissions:
14-
contents: write
15-
id-token: write
16-
outputs:
17-
MPYTHON_VERSION: ${{ steps.getversion.outputs.MPYTHON_VERSION }}
18-
steps:
14+
contents: write
15+
id-token: write
16+
outputs:
17+
MPYTHON_VERSION: ${{ steps.getversion.outputs.MPYTHON_VERSION }}
18+
steps:
1919
- name: Check out package
2020
uses: actions/checkout@v4
2121
- name: Get package version
2222
id: getversion
2323
run: |
2424
VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' pyproject.toml)
25-
echo "pyproject.toml version: $VERSION"
25+
echo "pyproject.toml version: $VERSION"
2626
git config user.name github-actions
2727
git config user.email [email protected]
2828
MSG=$(git log $(git describe --tags --abbrev=0)..HEAD --oneline)
@@ -31,12 +31,12 @@ jobs:
3131
git tag -a "$VERSION" -m "$MSG"
3232
echo "MPYTHON_VERSION=$VERSION" >> "$GITHUB_OUTPUT"
3333
- name: Publish tags
34-
run: git push --tags
34+
run: git push --tags
3535

3636
build:
3737
name: Build Package
3838
runs-on: ubuntu-latest
39-
needs:
39+
needs:
4040
- create-tag
4141
steps:
4242
- uses: actions/checkout@v4
@@ -59,7 +59,7 @@ jobs:
5959
with:
6060
name: python-package-distributions
6161
path: dist/
62-
62+
6363
publish-to-pypi:
6464
name: >-
6565
Publish Package to PyPI
@@ -109,7 +109,7 @@ jobs:
109109
- name: Create GitHub Release
110110
env:
111111
GITHUB_TOKEN: ${{ github.token }}
112-
run: |
112+
run: |
113113
gh release create ${{ needs.create-tag.outputs.MPYTHON_VERSION }} --repo "$GITHUB_REPOSITORY" --notes ""
114114
- name: Upload artifact signatures to GitHub Release
115115
env:

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,3 @@ This project is licensed under the [GNU General Public License v2 (GPLv2)](LICEN
102102
## Links
103103

104104
- [Repository](https://github.com/MPython-Package-Factory/mpython-core)
105-

mpython/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
from .runtime import Runtime
1+
from .array import Array
2+
from .cell import Cell
23
from .matlab_class import MatlabClass
34
from .matlab_function import MatlabFunction
4-
from .cell import Cell
5-
from .struct import Struct
6-
from .array import Array
5+
from .runtime import Runtime
76
from .sparse_array import SparseArray
7+
from .struct import Struct
88

99
__all__ = [
10-
'Runtime',
11-
'MatlabClass',
12-
'MatlabFunction',
13-
'Cell',
14-
'Struct',
15-
'Array',
16-
'SparseArray'
10+
"Runtime",
11+
"MatlabClass",
12+
"MatlabFunction",
13+
"Cell",
14+
"Struct",
15+
"Array",
16+
"SparseArray",
1717
]
1818

1919
# ----------------------------------------------------------------------
@@ -69,4 +69,4 @@
6969

7070
# * We should probably implement a helper to convert matlab batches into
7171
# python batches.
72-
# """
72+
# """

mpython/array.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
from .core import (
2-
WrappedArray,
3-
_ListishMixin
4-
)
5-
from .utils import _copy_if_needed
6-
71
import numpy as np
82

3+
from .core import WrappedArray, _ListishMixin
4+
from .utils import _copy_if_needed
5+
96

107
class Array(_ListishMixin, WrappedArray):
118
"""
@@ -31,6 +28,7 @@ class Array(_ListishMixin, WrappedArray):
3128
`Array` constructor. To ensure that they are interpreted as
3229
arrays to copy, use `Array.from_any`.
3330
"""
31+
3432
@classmethod
3533
def _DEFAULT(cls, n: list = ()) -> int:
3634
return 0
@@ -178,16 +176,19 @@ def from_cell(cls, other, **kwargs) -> "Array":
178176
array : Array
179177
Converted array.
180178
"""
181-
from .cell import Cell # FIXME: avoid circular import
179+
from .cell import Cell # FIXME: avoid circular import
182180

183181
if not isinstance(other, Cell):
184182
raise TypeError(f"Expected a {Cell} but got a {type(other)}")
185183
order = kwargs.get("order", None)
186184
if order in (None, "K", "A"):
187185
order = (
188-
"F" if other.flags.f_contiguous else
189-
"C" if other.flags.c_contiguous else
190-
order)
186+
"F"
187+
if other.flags.f_contiguous
188+
else "C"
189+
if other.flags.c_contiguous
190+
else order
191+
)
191192
kwargs["order"] = order
192193
return cls.from_any(other.tolist(), **kwargs)
193194

@@ -200,4 +201,4 @@ def __repr__(self):
200201
# Scalar -> display as python scalar
201202
return np.array2string(self, separator=", ")
202203
else:
203-
return super().__repr__()
204+
return super().__repr__()

mpython/cell.py

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
from .core import (
2-
MatlabType,
3-
WrappedArray,
4-
DelayedCell,
5-
AnyDelayedArray,
6-
_ListMixin,
7-
)
8-
from .utils import (
9-
_empty_array,
10-
_copy_if_needed,
11-
_import_matlab,
12-
_matlab_array_types
13-
)
14-
global matlab
15-
161
import numpy as np
172

3+
from .core import AnyDelayedArray, DelayedCell, MatlabType, WrappedArray, _ListMixin
4+
from .utils import _copy_if_needed, _empty_array, _import_matlab, _matlab_array_types
5+
6+
global matlab
7+
188

199
class Cell(_ListMixin, WrappedArray):
2010
"""
@@ -77,8 +67,7 @@ class Cell(_ListMixin, WrappedArray):
7767
def _DEFAULT(cls, shape: list = ()) -> np.ndarray:
7868
data = np.empty(shape, dtype=object)
7969
opt = dict(
80-
flags=['refs_ok', 'zerosize_ok'],
81-
op_flags=['writeonly', 'no_broadcast']
70+
flags=["refs_ok", "zerosize_ok"], op_flags=["writeonly", "no_broadcast"]
8271
)
8372
with np.nditer(data, **opt) as iter:
8473
for elem in iter:
@@ -87,8 +76,9 @@ def _DEFAULT(cls, shape: list = ()) -> np.ndarray:
8776

8877
def _fill_default(self):
8978
arr = np.ndarray.view(self, np.ndarray)
90-
opt = dict(flags=['refs_ok', 'zerosize_ok'],
91-
op_flags=['writeonly', 'no_broadcast'])
79+
opt = dict(
80+
flags=["refs_ok", "zerosize_ok"], op_flags=["writeonly", "no_broadcast"]
81+
)
9282
with np.nditer(arr, **opt) as iter:
9383
for elem in iter:
9484
elem[()] = _empty_array()
@@ -113,37 +103,36 @@ def _as_runtime(self) -> dict:
113103
data = np.ndarray.view(self, np.ndarray)
114104
data = np.reshape(data, [-1], order="F").tolist()
115105
data = MatlabType._to_runtime(data)
116-
return dict(type__='cell', size__=size, data__=data)
106+
return dict(type__="cell", size__=size, data__=data)
117107

118108
@classmethod
119109
def _from_runtime(cls, objdict: dict) -> "Cell":
120110
if isinstance(objdict, (list, tuple, set)):
121111
shape = [len(objdict)]
122-
objdict = dict(type__='cell', size__=shape, data__=objdict)
112+
objdict = dict(type__="cell", size__=shape, data__=objdict)
123113

124-
if objdict['type__'] != 'cell':
125-
raise TypeError('objdict is not a cell')
114+
if objdict["type__"] != "cell":
115+
raise TypeError("objdict is not a cell")
126116

127-
size = np.array(objdict['size__'], dtype=np.uint64).ravel()
117+
size = np.array(objdict["size__"], dtype=np.uint64).ravel()
128118
if len(size) == 2 and size[0] == 1:
129119
# NOTE: should not be needed for Cell, as this should
130120
# have been taken care of by MPython, but I am keeping it
131121
# here for symmetry with Array and Struct.
132122
size = size[1:]
133-
data = np.fromiter(objdict['data__'], dtype=object)
123+
data = np.fromiter(objdict["data__"], dtype=object)
134124
data = data.reshape(size[::-1]).transpose()
135125
try:
136126
obj = data.view(cls)
137127
except Exception:
138128
raise RuntimeError(
139-
f'Failed to construct Cell data:\n'
140-
f' data={data}\n'
141-
f' objdict={objdict}'
129+
f"Failed to construct Cell data:\n data={data}\n objdict={objdict}"
142130
)
143131

144132
# recurse
145-
opt = dict(flags=['refs_ok', 'zerosize_ok'],
146-
op_flags=['readwrite', 'no_broadcast'])
133+
opt = dict(
134+
flags=["refs_ok", "zerosize_ok"], op_flags=["readwrite", "no_broadcast"]
135+
)
147136
with np.nditer(data, **opt) as iter:
148137
for elem in iter:
149138
elem[()] = MatlabType._from_runtime(elem.item())
@@ -276,8 +265,9 @@ def asrecursive(other):
276265
other[...] = tmp
277266

278267
# recurse
279-
opt = dict(flags=['refs_ok', 'zerosize_ok'],
280-
op_flags=['readwrite', 'no_broadcast'])
268+
opt = dict(
269+
flags=["refs_ok", "zerosize_ok"], op_flags=["readwrite", "no_broadcast"]
270+
)
281271
with np.nditer(other, **opt) as iter:
282272
for elem in iter:
283273
elem[()] = MatlabType.from_any(elem.item())
@@ -295,8 +285,9 @@ def _unroll_build(cls, arr):
295285
# them to lists, and recurse.
296286
rebuild = False
297287
arr = np.asarray(arr)
298-
opt = dict(flags=['refs_ok', 'zerosize_ok'],
299-
op_flags=['readwrite', 'no_broadcast'])
288+
opt = dict(
289+
flags=["refs_ok", "zerosize_ok"], op_flags=["readwrite", "no_broadcast"]
290+
)
300291
with np.nditer(arr, **opt) as iter:
301292
for elem in iter:
302293
item = elem.item()

mpython/core/__init__.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
from .base_types import (
2-
MatlabType,
3-
AnyMatlabArray
4-
)
5-
from .wrapped_types import (
6-
AnyWrappedArray,
7-
WrappedArray
8-
)
9-
from .mixin_types import (
10-
_ListishMixin,
11-
_ListMixin,
12-
_DictMixin,
13-
_SparseMixin,
14-
)
1+
from .base_types import AnyMatlabArray, MatlabType
152
from .delayed_types import (
16-
AnyDelayedArray,
3+
AnyDelayedArray,
174
DelayedArray,
18-
DelayedCell,
5+
DelayedCell,
196
DelayedStruct,
20-
WrappedDelayedArray
21-
)
7+
WrappedDelayedArray,
8+
)
9+
from .mixin_types import _DictMixin, _ListishMixin, _ListMixin, _SparseMixin
10+
from .wrapped_types import AnyWrappedArray, WrappedArray
11+
12+
__all__ = [
13+
"AnyMatlabArray",
14+
"AnyDelayedArray",
15+
"AnyWrappedArray",
16+
"MatlabType",
17+
"WrappedArray",
18+
"DelayedArray",
19+
"DelayedCell",
20+
"DelayedStruct",
21+
"_ListishMixin",
22+
"_ListMixin",
23+
"_DictMixin",
24+
"_SparseMixin",
25+
"WrappedDelayedArray",
26+
]

0 commit comments

Comments
 (0)