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

Plugin incorrectly demands existence of define_env() in module #191

Closed
fralau opened this issue Nov 28, 2023 · 7 comments
Closed

Plugin incorrectly demands existence of define_env() in module #191

fralau opened this issue Nov 28, 2023 · 7 comments
Labels
bug Something isn't working fixed A fix has been submitted please test An updated was pushed. This needs to be tested stale No news, closing

Comments

@fralau
Copy link
Owner

fralau commented Nov 28, 2023

There is a requirement in the plugin.py file that the define_env() function should be present in the module file (main.py).

This was correct in the past, but nowadays it could also be on _pre_page_macros and others.

Workaround

Just add this function to the module file:

def define_env(env):
   pass
@fralau fralau added the bug Something isn't working label Nov 28, 2023
fralau pushed a commit that referenced this issue Nov 28, 2023
  - Now any of the standard functions is accepted (but still files
    if none is found).
  - Error message is explicit.
  - Created the no_module test case to validate that the error is
    properly raised.
@fralau
Copy link
Owner Author

fralau commented Nov 28, 2023

Any standard function is now accepted and the error is now explicit in case none is found:

NameError: None of the standard functions was found in module 'main':
['define_env', 'on_pre_page_macros', 'on_post_page_macros', 'on_post_build']

For good measure, the plugin also traces now the case when no module is found (it's not an error, just in case someone gave a wrong name to the module, or put it in the wrong place).

@fralau
Copy link
Owner Author

fralau commented Nov 28, 2023

This was detected in question #190.

@fralau
Copy link
Owner Author

fralau commented Nov 28, 2023

@Andre601 Could you please check that it works for you now?

@fralau fralau added info required Further information is requested fixed A fix has been submitted labels Nov 28, 2023
@Andre601
Copy link
Contributor

Can confirm that adding the def define_env(env): line with the pass key makes it work.

@Andre601
Copy link
Contributor

Tho, I have to add that in my case, the on_pre_page_macros call doesn't work right? Or at least not how I want it to?

I want it to add {% import 'game.md' as game %} to the markdown itself, so that I can them use macros without having to import them first, but either the markdown isn't modified, or the import statement isn't seen as such...

The full code I use, which is basically a copy of the docs:

def on_pre_page_macros(env):
    footer = "{% import 'game.md' as game %}"
    env.markdown += footer

I also tried putting it in front of the env.markdown (At the top) in hopes that it may be an issue with order, but no luck there.

It simply gives a "game is undefined" error...

@fralau
Copy link
Owner Author

fralau commented Dec 1, 2023

It depends on what your expectancy is of "to work".

It is a jinja2 statement, which will be executed immediately after. Indeed, it is executed (at least your error seems to be a jinja2 error). Your import statement seems incorrected formulated (see examples):

Shouldn't it be something like the following?

{% from 'game.md' import game %}

@Andre601
Copy link
Contributor

Andre601 commented Dec 1, 2023

I've used jinja2 more than enough to know that {% import ... as ... %} works here.

Also, my fault for not mentioning that it does work, but I had to add it at the top of the page due to how jinja2 parses things.

@fralau fralau added the stale No news, closing label Jan 24, 2024
@fralau fralau added please test An updated was pushed. This needs to be tested and removed info required Further information is requested labels Feb 17, 2024
@fralau fralau closed this as completed Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed A fix has been submitted please test An updated was pushed. This needs to be tested stale No news, closing
Projects
None yet
Development

No branches or pull requests

2 participants