Skip to content

Update the description of the entry point in purpose and scope #327

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

Merged
merged 2 commits into from
Nov 9, 2021
Merged
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: 33 additions & 7 deletions spec/purpose_and_scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,24 +336,50 @@ The `xp` namespace must contain all functionality specified in
including additional functionality is not recommended as doing so may hinder
portability and inter-operation of array libraries within user code.

### Checking for Compliance
### Checking an array object for Compliance

Array-consuming libraries are likely to want a mechanism for determining whether a provided array is specification compliant. The recommended approach to check for compliance is by checking whether an array object has an `__array_namespace__` attribute, as this is the one distinguishing feature of an array-compliant object.
Array-consuming libraries are likely to want a mechanism for determining
whether a provided array is specification compliant. The recommended approach
to check for compliance is by checking whether an array object has an
`__array_namespace__` attribute, as this is the one distinguishing feature of
an array-compliant object.

Checking for an `__array_namespace__` attribute can be implemented as a small utility function similar to the following.
Checking for an `__array_namespace__` attribute can be implemented as a small
utility function similar to the following.

```python
def is_array_api_obj(x):
return hasattr(x, '__array_namespace__')
```

```{note}
Providing a "reference library" on which people depend is out-of-scope; hence, the standard cannot, e.g., provide an array ABC from which libraries can inherit to enable an `isinstance` check.
Providing a "reference library" on which people depend is out-of-scope for
the standard. Hence the standard cannot, e.g., provide an array ABC from
which libraries can inherit to enable an `isinstance` check. However, note
that the `numpy.array_api` implementation aims to provide a reference
implementation with only the behavior specified in this standard - it may
prove useful for verifying one is writing portable code.
```

### Discoverability

To assist array-consuming libraries which need to create arrays originating from multiple conforming array implementations, conforming implementations may provide an {pypa}`entry point <specifications/entry-points/>` in order to make an array API namespace discoverable. For example,
### Discoverability of conforming implementations

It may be useful to have a way to discover all packages in a Python
environment which provide a conforming array API implementation, and the
namespace that that implementation resides in.
To assist array-consuming libraries which need to create arrays originating
from multiple conforming array implementations, or developers who want to perform
for example cross-library testing, libraries may provide an
{pypa}`entry point <specifications/entry-points/>` in order to make an array API
namespace discoverable.

:::{admonition} Optional feature
Given that entry points typically require build system & package installer
specific implementation, this standard chooses to recommend rather than
mandate providing an entry point.
:::

The following code is an example for how one can discover installed
conforming libraries:

```python
from importlib.metadata import entry_points
Expand Down