Skip to content

Commit c429828

Browse files
authored
refactor!: enforce naming convention of packages with singular and plural (#209)
1 parent 3bb0f4e commit c429828

35 files changed

Lines changed: 1503 additions & 1190 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ repos:
3535
hooks:
3636
- id: cpplint
3737
- repo: https://github.com/astral-sh/ruff-pre-commit
38-
rev: v0.11.7
38+
rev: v0.11.8
3939
hooks:
4040
- id: ruff
4141
args: [--fix, --exit-non-zero-on-fix]

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
### Changed
1919

20-
-
20+
- Enforce naming convention of packages with singular and plural: `optree.{accessor,integration}` -> `optree.{accessors,integrations}` by [@XuehaiPan](https://github.com/XuehaiPan) in [#209](https://github.com/metaopt/optree/pull/209).
2121

2222
### Fixed
2323

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ OpTree: Optimized PyTree Utilities
2222
.. toctree::
2323
:maxdepth: 2
2424

25-
integration.rst
25+
integrations.rst
2626

2727
License
2828
-------
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
Integration with Third-Party Libraries
2-
======================================
1+
Integrations with Third-Party Libraries
2+
=======================================
33

44
Integration for `JAX <https://github.com/jax-ml/jax>`_
55
------------------------------------------------------
66

7-
.. currentmodule:: optree.integration.jax
7+
.. currentmodule:: optree.integrations.jax
88

99
.. autosummary::
1010

@@ -17,7 +17,7 @@ Integration for `JAX <https://github.com/jax-ml/jax>`_
1717
Integration for `NumPy <https://github.com/numpy/numpy>`_
1818
---------------------------------------------------------
1919

20-
.. currentmodule:: optree.integration.numpy
20+
.. currentmodule:: optree.integrations.numpy
2121

2222
.. autosummary::
2323

@@ -30,7 +30,7 @@ Integration for `NumPy <https://github.com/numpy/numpy>`_
3030
Integration for `PyTorch <https://github.com/pytorch/pytorch>`_
3131
---------------------------------------------------------------
3232

33-
.. currentmodule:: optree.integration.torch
33+
.. currentmodule:: optree.integrations.torch
3434

3535
.. autosummary::
3636

docs/source/spelling_wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ initializer
3838
inplace
3939
instantiate
4040
instantiation
41+
integrations
4142
isinstance
4243
issubclass
4344
iterable

include/optree/treespec.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ class PyTreeSpec {
120120
[[nodiscard]] py::object Unflatten(const py::iterable &leaves) const;
121121

122122
// Flatten a PyTree up to this PyTreeSpec. 'this' must be a tree prefix of the tree-structure of
123-
// 'full_tree'.
123+
// 'tree'.
124124
// For example, if we flatten a value [(1, (2, 3)), {"foo": 4}] with a PyTreeSpec([(*, *), *]),
125125
// the result is the list of leaves [1, (2, 3), {"foo": 4}].
126-
[[nodiscard]] py::list FlattenUpTo(const py::object &full_tree) const;
126+
[[nodiscard]] py::list FlattenUpTo(const py::object &tree) const;
127127

128128
// Broadcast to a common suffix of this PyTreeSpec and other PyTreeSpec.
129129
[[nodiscard]] std::unique_ptr<PyTreeSpec> BroadcastToCommonSuffix(
@@ -136,7 +136,7 @@ class PyTreeSpec {
136136
const std::optional<py::function> &f_leaf = std::nullopt) const;
137137

138138
// Compose two PyTreeSpecs, replacing the leaves of this tree with copies of `inner`.
139-
[[nodiscard]] std::unique_ptr<PyTreeSpec> Compose(const PyTreeSpec &inner_treespec) const;
139+
[[nodiscard]] std::unique_ptr<PyTreeSpec> Compose(const PyTreeSpec &inner) const;
140140

141141
// Map a function over a PyTree structure, applying `f_leaf(leaf)` to each leaf,
142142
// and `f_node(node)` to each reconstructed non-leaf node.

optree/_C.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ class PyTreeSpec:
114114
type: builtins.type | None
115115
kind: PyTreeKind
116116
def unflatten(self, leaves: Iterable[T], /) -> PyTree[T]: ...
117-
def flatten_up_to(self, full_tree: PyTree[T], /) -> list[PyTree[T]]: ...
117+
def flatten_up_to(self, tree: PyTree[T], /) -> list[PyTree[T]]: ...
118118
def broadcast_to_common_suffix(self, other: Self, /) -> Self: ...
119119
def transform(
120120
self,
121121
/,
122122
f_node: Callable[[Self], Self] | None = None,
123123
f_leaf: Callable[[Self], Self] | None = None,
124124
) -> Self: ...
125-
def compose(self, inner_treespec: Self, /) -> Self: ...
125+
def compose(self, inner: Self, /) -> Self: ...
126126
def traverse(
127127
self,
128128
leaves: Iterable[T],

optree/__init__.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# ==============================================================================
1515
"""OpTree: Optimized PyTree Utilities."""
1616

17-
from optree import accessor, dataclasses, functools, integration, pytree, treespec, typing
18-
from optree.accessor import (
17+
from optree import accessors, dataclasses, functools, integrations, pytree, treespec, typing
18+
from optree.accessors import (
1919
AutoEntry,
2020
DataclassEntry,
2121
FlattenedEntry,
@@ -233,3 +233,22 @@
233233
"""Literal constant that treats :data:`None` as a pytree non-leaf node."""
234234
NONE_IS_LEAF: bool = NONE_IS_LEAF # literal constant
235235
"""Literal constant that treats :data:`None` as a pytree leaf node."""
236+
237+
238+
# pylint: disable-next=fixme
239+
# TODO: remove this file in version 0.18.0
240+
def __getattr__(name: str, /) -> object: # pragma: no cover
241+
"""Get an attribute from the module."""
242+
if name == 'accessor':
243+
global accessor # pylint: disable=global-statement
244+
245+
import optree.accessor as accessor # pylint: disable=import-outside-toplevel
246+
247+
return accessor # type: ignore[name-defined]
248+
if name == 'integration':
249+
global integration # pylint: disable=global-statement
250+
251+
import optree.integration as integration # pylint: disable=import-outside-toplevel
252+
253+
return integration # type: ignore[name-defined]
254+
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')

0 commit comments

Comments
 (0)