Skip to content

Allow setting custom self.env.globals #693

Description

@ahuang11

Is your feature request related to a problem? Please describe.

I think by allowing custom input kwargs in self.env.globals, custom templates can be more powerful.

For example, I want to extend client.py.jinja2 by using an additional global env var: auth_method=True:

        client_kwargs = self.client_kwargs.copy()
        {% if auth_method == "token" -%}
        token = self.token.get_secret_value()
        prefix = "Bearer"
        {% elif auth_method == "username_password" -%}
        # to authenticate with username password as a header, need to encode;
        # taken from https://stackoverflow.com/questions/6999565/
        token = b64encode(
            bytes(f"{self.username}:{self.password}", "utf-8")
        ).decode("ascii")

        client = AuthenticatedClient(
            base_url=base_url,
            token=token,
            prefix=prefix,
            timeout=timeout,
            **client_kwargs
        )

Describe the solution you'd like
A clear and concise description of what you want to happen.
In Project.__init__, a keyword:

custom_global_vars: Dict[str, Any] = None

If this is accepted, I'm happy to help contribute a PR

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Manually selecting the template on runtime

Additional context
Add any other context or screenshots about the feature request here.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions