Skip to content
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

feat: Make register_plugin a standalone function and include shared lib discovery #14804

Merged
merged 35 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2a5fde9
feat: make public plugins.py module
MarcoGorelli Mar 1, 2024
c25d366
docstring, note as unstable, rename param
MarcoGorelli Mar 1, 2024
897d0e5
simplify
MarcoGorelli Mar 1, 2024
49b3099
link to user guide
MarcoGorelli Mar 1, 2024
66b6ba9
Merge remote-tracking branch 'upstream/main' into public-plugins-func…
MarcoGorelli Mar 5, 2024
93dc8dd
make register_plugin public instead of _get_shared_lib_location
MarcoGorelli Mar 5, 2024
f99f072
lint
MarcoGorelli Mar 5, 2024
0650328
docs
MarcoGorelli Mar 5, 2024
74966bf
update user guide
MarcoGorelli Mar 5, 2024
fbbe41b
add test for get_dynamic_lib_location
MarcoGorelli Mar 5, 2024
386318c
align Python and Rust names
MarcoGorelli Mar 5, 2024
4ea372d
simplify
MarcoGorelli Mar 5, 2024
0527b05
rename
MarcoGorelli Mar 5, 2024
b0407f2
WIP: try testing a plugin in CI
MarcoGorelli Mar 6, 2024
3fa9341
Merge remote-tracking branch 'upstream/main' into public-plugins-func…
MarcoGorelli Mar 6, 2024
428ff15
add test_plugins file
MarcoGorelli Mar 6, 2024
1f3c65e
update user guide
MarcoGorelli Mar 6, 2024
b03b97f
use contextlib to suppress plr import
MarcoGorelli Mar 6, 2024
179b898
dprint check
MarcoGorelli Mar 6, 2024
c60c5d3
reorganise
MarcoGorelli Mar 6, 2024
07a5205
use default unstable warning
MarcoGorelli Mar 6, 2024
680d9b6
move sample plugin location
MarcoGorelli Mar 6, 2024
7a2dbc2
activate venv in ci
MarcoGorelli Mar 6, 2024
282b409
correct path
MarcoGorelli Mar 6, 2024
2c10f34
Merge remote-tracking branch 'upstream/main' into public-plugins-func…
MarcoGorelli Mar 13, 2024
afca8da
post merge fixup
MarcoGorelli Mar 13, 2024
4d1e7b4
Merge remote-tracking branch 'upstream/main' into public-plugins-func…
MarcoGorelli Mar 14, 2024
b9e2f82
remove sample_plugin from CI
MarcoGorelli Mar 14, 2024
14d4d7a
Minor refactors
stinodego Mar 14, 2024
9d484d4
Cleanup
stinodego Mar 14, 2024
a89d44c
Rename to register_plugin_function
stinodego Mar 14, 2024
afbea38
Fix up some things
stinodego Mar 15, 2024
0ea7c74
Add test
stinodego Mar 15, 2024
263225c
Redirect to new function
stinodego Mar 15, 2024
0f5183e
Re-add deprecation warning
stinodego Mar 15, 2024
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
1 change: 1 addition & 0 deletions py-polars/docs/source/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ methods. All classes and functions exposed in ``polars.*`` namespace are public.
testing
sql
metadata
plugins
15 changes: 15 additions & 0 deletions py-polars/docs/source/reference/plugins.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
=======
Plugins
=======
.. currentmodule:: polars

Plugins allow for extending Polars' functionality. See the
`user guide <https://docs.pola.rs/user-guide/expressions/plugins/>`_ for more information
and resources.

Available plugin utility functions are:

.. automodule:: polars.plugins
:members:
:autosummary:
:autosummary-no-titles:
3 changes: 2 additions & 1 deletion py-polars/polars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

__register_startup_deps()

from polars import api
from polars import api, exceptions, plugins, selectors
stinodego marked this conversation as resolved.
Show resolved Hide resolved
from polars._utils.polars_version import get_polars_version as _get_polars_version

# TODO: remove need for importing wrap utils at top level
Expand Down Expand Up @@ -225,6 +225,7 @@
__all__ = [
"api",
"exceptions",
"plugins",
# exceptions/errors
"ArrowError",
"ColumnNotFoundError",
Expand Down
37 changes: 37 additions & 0 deletions py-polars/polars/plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import annotations

from pathlib import Path

from polars._utils.unstable import unstable

__all__ = ["get_shared_lib_location"]


@unstable()
def get_shared_lib_location(package_init_path: str) -> str:
"""
Get location of Shared Object file.
stinodego marked this conversation as resolved.
Show resolved Hide resolved

See the `user guide <https://docs.pola.rs/user-guide/expressions/plugins/>`_
for more information about plugins.

.. warning::
This functionality is considered **unstable**. It may be changed
at any point without it being considered a breaking change.

Parameters
----------
package_init_path
The ``__init__.py`` file of the plugin package.

Returns
-------
str
The location of the Shared Object file.
stinodego marked this conversation as resolved.
Show resolved Hide resolved
"""
directory = Path(package_init_path).parent
stinodego marked this conversation as resolved.
Show resolved Hide resolved
return str(next(path for path in directory.iterdir() if _is_shared_lib(path)))
stinodego marked this conversation as resolved.
Show resolved Hide resolved


def _is_shared_lib(file: Path) -> bool:
return file.name.endswith((".so", ".dll", ".pyd"))
7 changes: 7 additions & 0 deletions py-polars/polars/utils/udfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
import os
from typing import Any

from polars._utils.deprecation import issue_deprecation_warning

__all__ = ["_get_shared_lib_location"]


def _get_shared_lib_location(main_file: Any) -> str:
issue_deprecation_warning(
"polars.utils will be made private in a future release. Please use "
"`from polars.plugins import get_shared_lib_location` instead.",
version="0.20.14",
)
directory = os.path.dirname(main_file) # noqa: PTH120
return os.path.join( # noqa: PTH118
directory, next(filter(_is_shared_lib, os.listdir(directory)))
Expand Down
Loading