Skip to content

Commit 1e14856

Browse files
committed
Include entry points as an optional feature
1 parent 996111c commit 1e14856

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

spec/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,5 @@
143143
),
144144
"durole": ("http://docutils.sourceforge.net/docs/ref/rst/" "roles.html#%s", ""),
145145
"dudir": ("http://docutils.sourceforge.net/docs/ref/rst/" "directives.html#%s", ""),
146+
"pypa": ("https://packaging.python.org/%s", ""),
146147
}

spec/purpose_and_scope.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,38 @@ recommended not to add other functions or objects, because that may make it
369369
harder for users to write code that will work with multiple array libraries.
370370

371371

372+
### Discoverability
373+
374+
Libraries that wish to [create arrays](../API_specification/creation_functions.md)
375+
using multiple array libraries would still need to explicitly import each
376+
library, as [`__array_namespace__()`](method-__array_namespace__) only makes an
377+
API namespace accessible when consuming arrays.
378+
379+
To address this issue, an {pypa}`entry point <specifications/entry-points/>` may
380+
be provided by a conforming implementation to make its API namespace
381+
discoverable:
382+
383+
```python
384+
from importlib.metadata import entry_points
385+
386+
try:
387+
eps = entry_points()['array_api']
388+
ep = next(ep for ep in eps if ep.name == 'package_name')
389+
except TypeError:
390+
# The dict interface for entry_points() is deprecated in py3.10,
391+
# supplanted by a new select interface.
392+
ep = entry_points(group='array_api', name='package_name')
393+
394+
xp = ep.load()
395+
```
396+
397+
The properties of an entry point should have:
398+
399+
- `array_api` as the **group**
400+
- The package name as the **name**
401+
- The import path to the API namespace as the **object reference**
402+
403+
372404
* * *
373405

374406
## Conformance

0 commit comments

Comments
 (0)