Skip to content

The plugin does not work without git #317

@requiem958

Description

@requiem958

Use case

I'm building a website with mkdocs-material+mkdocs_plugin_rss with gitlab CI.
I use python:3.10-alpine image on that CI, which does not seem to include git.

My mkdocs.yml section about rss is:

...
plugins:
  - rss:
      use_git: false
      match_path: blog/posts/.* 
      date_from_meta:
        as_creation: date
      categories:
        - categories
Traceback (most recent call last):
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/git/__init__.py", line 296, in <module>
    refresh()
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/git/__init__.py", line 287, in refresh
    if not Git.refresh(path=path):
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/git/cmd.py", line 631, in refresh
    raise ImportError(err)
ImportError: Bad git executable.
The git executable must be specified in one of the following ways:
    - be included in your $PATH
    - be set via $GIT_PYTHON_GIT_EXECUTABLE
    - explicitly set via git.refresh(<full-path-to-git-executable>)
All git commands will error until this is rectified.
This initial message can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:
    - quiet|q|silence|s|silent|none|n|0: for no message or exception
    - warn|w|warning|log|l|1: for a warning message (logging level CRITICAL, displayed by default)
    - error|e|exception|raise|r|2: for a raised exception
Example:
    export GIT_PYTHON_REFRESH=quiet
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/builds/testcy/cyber/.venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/mkdocs/__main__.py", line 281, in build_command
    cfg = config.load_config(**kwargs)
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/mkdocs/config/base.py", line 374, in load_config
    errors, warnings = cfg.validate()
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/mkdocs/config/base.py", line 231, in validate
    run_failed, run_warnings = self._validate()
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/mkdocs/config/base.py", line 188, in _validate
    self[key] = config_option.validate(value)
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/mkdocs/config/config_options.py", line 186, in validate
    return self.run_validation(value)
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/mkdocs/config/config_options.py", line 1075, in run_validation
    self.load_plugin_with_namespace(name, cfg)
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/mkdocs/config/config_options.py", line 1113, in load_plugin_with_namespace
    return (name, self.load_plugin(name, config))
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/mkdocs/config/config_options.py", line 1131, in load_plugin
    plugin_cls = self.installed_plugins[name].load()
  File "/usr/local/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/mkdocs_rss_plugin/plugin.py", line 37, in <module>
    from mkdocs_rss_plugin.util import Util
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/mkdocs_rss_plugin/util.py", line 24, in <module>
    from git import (
  File "/builds/testcy/cyber/.venv/lib/python3.10/site-packages/git/__init__.py", line 298, in <module>
    raise ImportError("Failed to initialize: {0}".format(_exc)) from _exc
ImportError: Failed to initialize: Bad git executable.
The git executable must be specified in one of the following ways:
    - be included in your $PATH
    - be set via $GIT_PYTHON_GIT_EXECUTABLE
    - explicitly set via git.refresh(<full-path-to-git-executable>)
All git commands will error until this is rectified.
This initial message can be silenced or aggravated in the future by setting the
$GIT_PYTHON_REFRESH environment variable. Use one of the following values:
    - quiet|q|silence|s|silent|none|n|0: for no message or exception
    - warn|w|warning|log|l|1: for a warning message (logging level CRITICAL, displayed by default)
    - error|e|exception|raise|r|2: for a raised exception
Example:
    export GIT_PYTHON_REFRESH=quiet
Cleaning up project directory and file based variables 00:00
ERROR: Job failed: command terminated with exit code 1

I don't know if you can import git if and only if the use_git option is enabled, but right now that plugin don't work without the git executable.

However, thank you for this plugin and all the work that you've done on it !

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions