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

Cant override base.html #1849

Closed
Jonesie opened this issue Aug 22, 2019 · 18 comments · Fixed by #1857
Closed

Cant override base.html #1849

Jonesie opened this issue Aug 22, 2019 · 18 comments · Fixed by #1857
Labels

Comments

@Jonesie
Copy link

@Jonesie Jonesie commented Aug 22, 2019

Description

Iv'e tried to override base.html as per the instructions but all I get is:

AttributeError: 'Theme' object has no attribute 'name'

Expected behavior

It should just work.

Actual behavior

AttributeError: 'Theme' object has no attribute 'name'

Steps to reproduce the bug

  1. Add a custom_dir to the mkdocs.yml
  2. Create the directory specified in custom_dir
  3. Copy base.html from material theme source to custom dir
  4. Modify base.html
  5. Build or Serve

Package versions

  • Python: 3.7.4
  • MkDocs: 1.0.4
  • Material: 4.4.0

Project configuration

site_name: xxxxx
nav:
    - Welcome: index.md
    - Setup: setup.md 
    - Documents: docs.md
    - Data: data.md
    - Agent: agent.md
    - About: about.md
theme: 
  name: 'material'
  custom_dir: 'theme'
  palette:
    primary: 'lime'
    accent: 'amber'
  font:
    text: 'Roboto'
    code: 'Roboto Mono'
  favicon: 'images/favicon.ico'
extra_css: 
  - 'styles/extra.css'   
#extra_javascript: 
#  - 'scripts/startup.js'
use_directory_urls: false 
site_dir: ../../../src/xxx/src/help

System information

  • OS: Windows 10
  • Browser: Chrome
@Jonesie
Copy link
Author

@Jonesie Jonesie commented Aug 22, 2019

Moved this issue from Material theme as it's also failing on standard theme.

@waylan
Copy link
Member

@waylan waylan commented Aug 22, 2019

Just a guess, but I wonder if using the name theme for your custom_dir is causing a naming conflict. Try using a different name for the custom_dir. If that is the cause, then we should either blacklist that name (and document it) or provide a fix which avoids the conflict.

@Jonesie
Copy link
Author

@Jonesie Jonesie commented Aug 22, 2019

Nice guess, but no sorry. I changed it to theme_customisation, same result. Have also tried the full theme with name: null.

Here's the full stack trace:

Traceback (most recent call last):                                                                                        
File "c:\python37\lib\runpy.py", line 193, in _run_module_as_main    "__main__", mod_spec)                                                                                                 
File "c:\python37\lib\runpy.py", line 85, in _run_code exec(code, run_globals)                                                                                               
File "C:\Python37\Scripts\mkdocs.exe\__main__.py", line 9, in <module>
File "c:\python37\lib\site-packages\click\core.py", line 764, in __call__  return self.main(*args, **kwargs)                                                                                     
File "c:\python37\lib\site-packages\click\core.py", line 717, in main rv = self.invoke(ctx) 
File "c:\python37\lib\site-packages\click\core.py", line 1137, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\python37\lib\site-packages\click\core.py", line 956, in invoke return ctx.invoke(self.callback, **ctx.params)
File "c:\python37\lib\site-packages\click\core.py", line 555, in invoke return callback(*args, **kwargs)
File "c:\python37\lib\site-packages\mkdocs\__main__.py", line 162, in build_command site_dir=site_dir    
File "c:\python37\lib\site-packages\mkdocs\config\base.py", line 197, in load_config errors, warnings = cfg.validate()                                                                                     
File "c:\python37\lib\site-packages\mkdocs\config\base.py", line 115, in validate post_failed, post_warnings = self._post_validate()                                                                    
File "c:\python37\lib\site-packages\mkdocs\config\base.py", line 95, in _post_validate config_option.post_validation(self, key_name=key)                                                                     
File "c:\python37\lib\site-packages\mkdocs\config\config_options.py", line 430, in post_validation format(path=theme_config['custom_dir'], name=self.name))

AttributeError: 'Theme' object has no attribute 'name'                     

@Jonesie
Copy link
Author

@Jonesie Jonesie commented Aug 24, 2019

Also, I've switched to using the squidfunk/mkdocs-material container and it has the same issue.

@waylan
Copy link
Member

@waylan waylan commented Aug 26, 2019

Thanks for the feedback. I'll need to investigate this when I have some time. I'm in the middle of a move and have limited connectivity right now so it will be a few days at least.

@Jonesie
Copy link
Author

@Jonesie Jonesie commented Aug 26, 2019

No hurry at my end. Have fun!

@waylan
Copy link
Member

@waylan waylan commented Sep 2, 2019

The problem is that it is trying to raise a ValidationError as your config is not valid. It would appear that the value you provided to custom_dir does not exist as a directory. However, it encounters a error in the code when attempting to create the message which tells you that. It is the second error which you are seeing. If you can point custom_dir to a directory which actually exists, the problem will go away for you.

In the meantime, we have a bug to fix. We need to replace self.name with key_name. Not sure where self.name came from there. And apparently, we need to add a test for this.

@waylan
Copy link
Member

@waylan waylan commented Sep 2, 2019

We already have a test for this. Not sure how that it not catching the problem.

@Jonesie
Copy link
Author

@Jonesie Jonesie commented Sep 3, 2019

The problem is that it is trying to raise a ValidationError as your config is not valid. It would appear that the value you provided to custom_dir does not exist as a directory. However, it encounters a error in the code when attempting to create the message which tells you that. It is the second error which you are seeing. If you can point custom_dir to a directory which actually exists, the problem will go away for you.

In the meantime, we have a bug to fix. We need to replace self.name with key_name. Not sure where self.name came from there. And apparently, we need to add a test for this.

The directory definitely exists so I dont think this is the solution.
Unless.. maybe I need a relative path or full path, not just the name?

theme: 
  name: 'material'
  custom_dir: 'theme_customisations'

image

@Jonesie
Copy link
Author

@Jonesie Jonesie commented Sep 3, 2019

I can send you the entire source if you like.

@waylan
Copy link
Member

@waylan waylan commented Sep 3, 2019

I was able to replicate the error you were having simply by assigning a value to custom_dir which did not exist. And the bit of code which is raising the error is inside a conditional which only gets called when custom_dir does not exist. Therefore, I am certain that MkDocs cannot find the directory.

Note that the path must be relative to the location of the mkdocs.yml config file. My assumption is that that you may have the directory nested a level or something. Without the full file listing I can't be sure.

@waylan
Copy link
Member

@waylan waylan commented Sep 3, 2019

Interestingly, if the error didn't exist, you would get an error message which would include the full path to the location MkDocs is looking and it would be easy to see what adjustment needed to be made.

@Jonesie
Copy link
Author

@Jonesie Jonesie commented Sep 3, 2019

Interestingly, if the error didn't exist, you would get an error message which would include the full path to the location MkDocs is looking and it would be easy to see what adjustment needed to be made.

I tried changing the config so the directory would not be found and I get the same error, which is not very helpful (python yuk)

Traceback (most recent call last):
  File "/usr/local/bin/mkdocs", line 11, in <module>
    load_entry_point('mkdocs==1.0.4', 'console_scripts', 'mkdocs')()
  File "/usr/local/lib/python3.6/site-packages/Click-7.0-py3.6.egg/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/Click-7.0-py3.6.egg/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/Click-7.0-py3.6.egg/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/Click-7.0-py3.6.egg/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/Click-7.0-py3.6.egg/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/mkdocs-1.0.4-py3.6.egg/mkdocs/__main__.py", line 162, in build_command
    site_dir=site_dir
  File "/usr/local/lib/python3.6/site-packages/mkdocs-1.0.4-py3.6.egg/mkdocs/config/base.py", line 197, in load_config
    errors, warnings = cfg.validate()
  File "/usr/local/lib/python3.6/site-packages/mkdocs-1.0.4-py3.6.egg/mkdocs/config/base.py", line 115, in validate
    post_failed, post_warnings = self._post_validate()
  File "/usr/local/lib/python3.6/site-packages/mkdocs-1.0.4-py3.6.egg/mkdocs/config/base.py", line 95, in _post_validate
    config_option.post_validation(self, key_name=key)
  File "/usr/local/lib/python3.6/site-packages/mkdocs-1.0.4-py3.6.egg/mkdocs/config/config_options.py", line 430, in post_validation
    format(path=theme_config['custom_dir'], name=self.name))
AttributeError: 'Theme' object has no attribute 'name'

@waylan
Copy link
Member

@waylan waylan commented Sep 4, 2019

Yes, I know. The fix I created in #1875 fixes that problem. Of course, it won't be available until we do a release. If you could give me a file listing which includes the config file and the relative location of the directory, I can tell you what your custom_dir setting should be.

@Jonesie
Copy link
Author

@Jonesie Jonesie commented Sep 4, 2019

This is the full structure:
image

@Jonesie
Copy link
Author

@Jonesie Jonesie commented Sep 4, 2019

OMG. Im sorry. I realise now it's in docs so path should be ./docs/theme_customisations. Im a dick.

That's better but now getting:

jinja2.exceptions.TemplateSyntaxError: unexpected char '$' at 12825

@waylan
Copy link
Member

@waylan waylan commented Sep 4, 2019

Glad you figured it out. However, I would advise against placing the directory within your docs.

In any event, the new error is a syntax error within your template, which is a completely separate issue.

@Jonesie
Copy link
Author

@Jonesie Jonesie commented Sep 4, 2019

I was only trying to update the base in the theme to add a startup script but managed to get that working using extra scripts - same directory issue.

Cheers

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

Successfully merging a pull request may close this issue.

2 participants