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

Allow --config-file option in mkdocs #63

Closed
fgrbr opened this issue May 8, 2023 · 0 comments
Closed

Allow --config-file option in mkdocs #63

fgrbr opened this issue May 8, 2023 · 0 comments

Comments

@fgrbr
Copy link

fgrbr commented May 8, 2023

Hi,

First of all, thanks a lot for this great package!

I use another package that requires the option --config-file to bet set when building the documentation using mkdocs build --config-file mkdocs.yml. Unfortunately, in this case, a value error is reported ValueError: The project root dir is ambiguous ! Please report this issue to mkdocs-gallery.

In particular, when providing the absolute path mkdocs serve --config-file /workspaces/mkdocs-gallery/mkdocs.yml in noxfile.py instead of mkdocs serve, everything works as expected when running nox -s docs within the folder /workspaces/mkdocs-gallery/. However, when changing it to mkdocs serve --config-file mkdocs.yml, I get the following error:

nox -s docs
nox > Running session docs-3.9
nox > Re-using existing virtual environment at .nox/docs-3-9.
nox > 
A `pyproject.toml` file exists. Loading it.
nox > 
About to install *docs* requirements: ['mkdocs', 'matplotlib', 'seaborn', 'statsmodels', 'plotly', 'pillow'].
 Conda pkgs are ()
nox > [docs] Installing requirements with pip: ['mkdocs', 'matplotlib', 'seaborn', 'statsmodels', 'plotly', 'pillow']
nox > python -m pip install mkdocs matplotlib seaborn statsmodels plotly pillow
nox > python -m pip install .
nox > mkdocs serve --config-file mkdocs.yml
INFO     -  Building documentation...
WARNING  -  Please install 'memory_profiler' to enable peak memory measurements.
WARNING  -  optipng binaries not found, PNG images and thumbnails will not be optimized
INFO     -  generating gallery...
Traceback (most recent call last):
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/lib/python3.9/site-packages/mkdocs/__main__.py", line 234, in serve_command
    serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 83, in serve
    builder(config)
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/lib/python3.9/site-packages/mkdocs/commands/serve.py", line 76, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/lib/python3.9/site-packages/mkdocs/commands/build.py", line 273, in build
    config.plugins.run_event('pre_build', config=config)
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/lib/python3.9/site-packages/mkdocs/plugins.py", line 522, in run_event
    result = method(**kwargs)
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/lib/python3.9/site-packages/mkdocs_gallery/plugin.py", line 263, in on_pre_build
    galleries_tocs, self.md_to_src = generate_gallery_md(self.config, config)
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/lib/python3.9/site-packages/mkdocs_gallery/gen_gallery.py", line 418, in generate_gallery_md
    all_info = AllInformation.from_cfg(gallery_conf, mkdocs_conf)
  File "/workspaces/mkdocs-gallery/.nox/docs-3-9/lib/python3.9/site-packages/mkdocs_gallery/gen_data_model.py", line 905, in from_cfg
    raise ValueError("The project root dir is ambiguous ! Please report this issue to mkdocs-gallery.")
ValueError: The project root dir is ambiguous ! Please report this issue to mkdocs-gallery.
nox > Command mkdocs serve --config-file mkdocs.yml failed with exit code 1
nox > Session docs-3.9 failed.

I think the main problem is Path(mkdocs_conf['config_file_path']).parent in gen_data_model.py to get the project root, which is . if mkdocs serve --config-file mkdocs.yml was executed. The same is true for plugin.py.

I've created #64 to circumvent this path issue.

fgrbr pushed a commit to fgrbr/mkdocs-gallery that referenced this issue May 10, 2023
@smarie smarie closed this as completed in 804b19e May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant