Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

[Feature Request] Load custom filters from Python modules #71

Open
michalismeng opened this issue Jul 21, 2021 · 0 comments
Open

[Feature Request] Load custom filters from Python modules #71

michalismeng opened this issue Jul 21, 2021 · 0 comments

Comments

@michalismeng
Copy link

The current implementation allows loading custom filters from Python files by using the --filters argument.

My problem is I have compiled Python files, i.e Python bytecode (.pyc files) and passing them to --filters fails with the following error:

ValueError: source code string cannot contain null bytes

I understand the main reason for the above behavior is using Python's imp.load_source function, which can't read bytecode:

j2cli/j2cli/cli.py

Lines 72 to 74 in 26a67e9

def _import_functions(self, filename):
m = imp.load_source('imported-funcs', filename)
return dict((name, func) for name, func in inspect.getmembers(m) if inspect.isfunction(func))

A solution to the above would be to introduce a new argument, e.g --filters-modules MODULE, which will accept Python modules and load them using importlib.import_module.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant