A Python plugin and module introspection library.
Project description
Pronounced, “Pensive”
This is a simple plugin library that uses the sys.meta_path list along with custom finder and loader definitions to hook into the Python import process.
For more information on the import process hooks, please see:
Latest Release Notes
This version has the following changes from release version <=0.1.4
discover_classes was renamed to rlist_classes
discover_modules was renamed to list_modules
Documentation
Examples
Creating a Plugin Context
The plugin context is a nice way of managing what directories you’ve plugged into the sys.meta_path variable. Managers may be destroyed when no longer needed. Destroying a manager removes all directories that the manager plugged into from the sys.meta_path variable.
import pynsive
plugin_manager = pynsive.PluginManager()
plugin_manager.plug_into('/some/path')
try:
# Some code goes here
finally:
plugin_manager.destroy()
Dynamically Listing Submodules
import pynsive
import test_module
plugin_manager = pynsive.PluginManager()
plugin_manager.plug_into('/some/path')
try:
found_modules = pynsive.list_modules('ext.plugins')
finally:
plugin_manager.destroy()
Dynamically Finding Classes in a Module
import pynsive
import test_module
plugin_manager = pynsive.PluginManager()
plugin_manager.plug_into('/some/path')
try:
def subclasses_only(type_to_test):
same = type_to_test is not test_module.MyClass
is_subclass = issubclass(type_to_test, test_module.MyClass)
return not same and is_subclass
classes = pynsive.list_classes('ext.plugins', subclasses_only)
finally:
plugin_manager.destroy()
Dynamically Finding Classes in a Module Tree
import pynsive
import test_module
plugin_manager = pynsive.PluginManager()
plugin_manager.plug_into('/some/path')
try:
def subclasses_only(type_to_test):
same = type_to_test is not test_module.MyClass
is_subclass = issubclass(type_to_test, test_module.MyClass)
return not same and is_subclass
# Recursively find classes
classes = pynsive.rlist_classes('ext.plugins', subclasses_only)
finally:
plugin_manager.destroy()
Unit Tests
Beginner’s Tutorial
That Legal Thing…
This software library is released to you under the Apache License, Version 2.0 . See LICENSE for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pynsive-0.1.9.tar.gz.
File metadata
- Download URL: pynsive-0.1.9.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0309d06bc2e236f36dff19f89c8fa71f82285df9d4d5657c4124030488d2c1d
|
|
| MD5 |
63021e889ed22e72a85f1f2f834842fd
|
|
| BLAKE2b-256 |
d943c7e264927af4cc0e8ef29692d081294db3515f20255d64572b583595c791
|