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

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

Description

@michalismeng

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions