mkdocs-with-pdf
mkdocs-with-pdf copied to clipboard
AttributeError. Don't need a cover page.
Good day!
It is necessary to generate PDF without cover, but an error occurs: AttributeError: 'Options' object has no attribute '_cover_title' How can I fix it?
Site config mkdocs.yml:
- with-pdf:
cover: false
back_cover: false
headless_chrome_path: headless-chromium
output_path: document.pdf
debug_html: true
verbose: true
Log:
INFO - PDF count: 0
Traceback (most recent call last):
File "/var/mkdocs/.local/bin/mkdocs", line 8, in <module>
sys.exit(cli())
File "/var/mkdocs/.local/lib/python3.6/site-packages/click/core.py", line 1137, in __call__
return self.main(*args, **kwargs)
File "/var/mkdocs/.local/lib/python3.6/site-packages/click/core.py", line 1062, in main
rv = self.invoke(ctx)
File "/var/mkdocs/.local/lib/python3.6/site-packages/click/core.py", line 1668, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/var/mkdocs/.local/lib/python3.6/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/var/mkdocs/.local/lib/python3.6/site-packages/click/core.py", line 763, in invoke
return __callback(*args, **kwargs)
File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs/__main__.py", line 183, in build_command
build.build(config.load_config(**kwargs), dirty=not clean)
File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs/commands/build.py", line 309, in build
config['plugins'].run_event('post_build', config=config)
File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs/plugins.py", line 96, in run_event
result = method(**kwargs)
File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs_with_pdf/plugin.py", line 134, in on_post_build
self.generator.on_post_build(config, self.config['output_path'])
File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs_with_pdf/generator.py", line 122, in on_post_build
add_stylesheet(style_for_print(self._options))
File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs_with_pdf/styles/__init__.py", line 33, in style_for_print
"""
File "/var/mkdocs/.local/lib/python3.6/site-packages/mkdocs_with_pdf/options.py", line 122, in cover_title
return self._cover_title
AttributeError: 'Options' object has no attribute '_cover_title'
section_end:1632486121:step_script
Version: mkdocs-with-pdf==0.9.2
+1 I have the same issue.
+1
+1
+1
Have you found any workarounds?
Just a guess, but could it be due to different versions of Python? I will try downgrading
The problem is that self._cover_title
in Options.py gets only defined if self.cover=true
, but it is always read in line 28 of the init file.
So if you configure cover: false
in your mkdocs.yml, the init file attempts to read a non existing property.
In order to resolve this issue, one could either always define self._cover_title
in Options.py regardless of self.cover
:
# Cover
self.cover = local_config['cover']
self.back_cover = local_config['back_cover']
+ self._cover_title = None
if self.cover or self.back_cover:
self._cover_title = local_config['cover_title'] \
if local_config['cover_title'] else config['site_name']
self._cover_subtitle = local_config['cover_subtitle']
self._cover_logo = local_config['cover_logo']
Or remove the if-statement underneath altogether. The plugin works just fine if cover properties are defined but the cover is invisible.
+1
Also seeing this. Using mkdocs 1.5.3 and mkdocs-with-pdf 0.9.3. My config looks like:
site_name: My Docs
plugins:
- with-pdf:
cover: false
Running mkdocs build
produces the error "AttributeError: 'Options' object has no attribute '_cover_title'. Did you mean: 'cover_title'?".
I created a venv with python3 -m venv venv
and activated with source ./venv/bin/activate
. I can confirm that modifying venv/lib/python3.11/site-packages/mkdocs_with_pdf/options.py
as suggested by https://github.com/orzih/mkdocs-with-pdf/issues/80#issuecomment-1508444386 allows mkdocs build
to build succesfully when cover: false
.
Obviously, manually patching this file isn't a great solution, maybe someone can put up a PR if one doesn't already exist.