diff --git a/.bumpversion.cfg b/.bumpversion.cfg index d4c43ec..418f73c 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.0.13 +current_version = 0.0.14 [bumpversion:file:mkdocs_mdpo_plugin/__init__.py] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 032030e..d5bf1c0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,9 @@ jobs: - 3.7 - 3.8 - 3.9 + mkdocs-version: + - 1.1.2 + - 1.2.1 steps: - uses: actions/checkout@v2 - name: Set up Python v${{ matrix.python-version }} @@ -29,7 +32,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip wheel coveralls - python -m pip install .[test] + python -m pip install .[test] mkdocs==${{ matrix.mkdocs-version }} pip list - name: Test with pytest run: pytest -svv --cov=mkdocs_mdpo_plugin --cov-config=setup.cfg diff --git a/mkdocs_mdpo_plugin/__init__.py b/mkdocs_mdpo_plugin/__init__.py index 585afe0..4f47f3c 100644 --- a/mkdocs_mdpo_plugin/__init__.py +++ b/mkdocs_mdpo_plugin/__init__.py @@ -1,3 +1,3 @@ """mkdocs-mdpo-plugin package""" -__version__ = '0.0.13' +__version__ = '0.0.14' diff --git a/mkdocs_mdpo_plugin/plugin.py b/mkdocs_mdpo_plugin/plugin.py index cb31014..19d5eb5 100644 --- a/mkdocs_mdpo_plugin/plugin.py +++ b/mkdocs_mdpo_plugin/plugin.py @@ -150,7 +150,10 @@ def on_config(self, config, **kwargs): elif not self.config['lc_messages']: self.config['lc_messages'] = '' - _using_material_theme = config['theme'].name == 'material' + try: + _using_material_theme = config['theme'].name == 'material' + except KeyError: + _using_material_theme = None # load language selection settings from material or mdpo configuration def _languages_required(): @@ -197,56 +200,68 @@ def _default_language_required(): default_language = self.config.get('default_language') if not default_language: # use mkdocs>=v1.2.0 theme localization setting - if hasattr(config['theme'], 'locale') and config['theme'].locale: + if ( + config.get('theme') + and hasattr(config['theme'], 'locale') + and config['theme'].locale + ): self.config['default_language'] = config['theme'].locale else: + if ( + not isinstance(self.config['languages'], list) + or not self.config['languages'] + ): + raise _languages_required() + self.config['default_language'] = self.config['languages'][0] # ---------------------------------------------------------- # extensions configuration + markdown_extensions = config.get('markdown_extensions') # configure MD4C extensions - if 'tables' not in config['markdown_extensions']: - if 'tables' in self._md4c_extensions: - self._md4c_extensions.remove('tables') - else: - if 'tables' not in self._md4c_extensions: - self._md4c_extensions.append('tables') - if 'wikilinks' not in config['markdown_extensions']: - if 'wikilinks' in self._md4c_extensions: - self._md4c_extensions.remove('wikilinks') - else: - if 'wikilinks' not in self._md4c_extensions: - self._md4c_extensions.append('wikilinks') - - # spaces after '#' are optional in Python-Markdown for headers, - # but the extension 'pymdownx.saneheaders' makes them mandatory - if 'pymdownx.saneheaders' in config['markdown_extensions']: - if 'permissive_atx_headers' in self._md4c_extensions: - self._md4c_extensions.remove('permissive_atx_headers') - else: - if 'permissive_atx_headers' not in self._md4c_extensions: - self._md4c_extensions.append('permissive_atx_headers') - - # 'pymdownx.tasklist' enables 'tasklists' MD4C extentsion - if 'pymdownx.tasklist' in config['markdown_extensions']: - if 'tasklists' not in self._md4c_extensions: - self._md4c_extensions.append('tasklists') - else: - if 'tasklists' in self._md4c_extensions: - self._md4c_extensions.remove('tasklists') - - # 'pymdownx.tilde' enables strikethrough syntax, but only works - # if the MD4C extension is disabled - if 'pymdownx.tilde' in config['markdown_extensions']: - if 'strikethrough' in self._md4c_extensions: - self._md4c_extensions.remove('strikethrough') - - # configure internal 'mkdocs.mdpo' extension - if 'mkdocs.mdpo' in config['markdown_extensions']: # pragma: no cover - config['markdown_extensions'].remove('mkdocs.mdpo') - config['markdown_extensions'].append('mkdocs.mdpo') + if markdown_extensions: + if 'tables' not in markdown_extensions: + if 'tables' in self._md4c_extensions: + self._md4c_extensions.remove('tables') + else: + if 'tables' not in self._md4c_extensions: + self._md4c_extensions.append('tables') + if 'wikilinks' not in markdown_extensions: + if 'wikilinks' in self._md4c_extensions: + self._md4c_extensions.remove('wikilinks') + else: + if 'wikilinks' not in self._md4c_extensions: + self._md4c_extensions.append('wikilinks') + + # spaces after '#' are optional in Python-Markdown for headers, + # but the extension 'pymdownx.saneheaders' makes them mandatory + if 'pymdownx.saneheaders' in markdown_extensions: + if 'permissive_atx_headers' in self._md4c_extensions: + self._md4c_extensions.remove('permissive_atx_headers') + else: + if 'permissive_atx_headers' not in self._md4c_extensions: + self._md4c_extensions.append('permissive_atx_headers') + + # 'pymdownx.tasklist' enables 'tasklists' MD4C extentsion + if 'pymdownx.tasklist' in markdown_extensions: + if 'tasklists' not in self._md4c_extensions: + self._md4c_extensions.append('tasklists') + else: + if 'tasklists' in self._md4c_extensions: + self._md4c_extensions.remove('tasklists') + + # 'pymdownx.tilde' enables strikethrough syntax, but only works + # if the MD4C extension is disabled + if 'pymdownx.tilde' in markdown_extensions: + if 'strikethrough' in self._md4c_extensions: + self._md4c_extensions.remove('strikethrough') + + # configure internal 'mkdocs.mdpo' extension + if 'mkdocs.mdpo' in markdown_extensions: # pragma: no cover + config['markdown_extensions'].remove('mkdocs.mdpo') + config['markdown_extensions'].append('mkdocs.mdpo') # ---------------------------------------------------------- diff --git a/setup.cfg b/setup.cfg index 73ef35e..656a780 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = mkdocs_mdpo_plugin -version = 0.0.13 +version = 0.0.14 description = Mkdocs plugin for translations using PO files. long_description = file: README.md long_description_content_type = text/markdown @@ -44,25 +44,25 @@ dev = flake8-implicit-str-concat==0.2.0 flake8-print==4.0.0 isort==5.8.0 - mkdocs==1.1.2 + mkdocs==1.2.1 mkdocs-exclude==1.0.2 mkdocs-include-markdown-plugin==3.1.0 mkdocs-material==7.1.2 mkdocs-material-relative-language-selector==1.1.0 - mkdocstrings==0.15.1 + mkdocstrings==0.15.2 pre-commit==2.12.1 pymdown-extensions==8.1.1 pytest==6.2.3 pytest-cov==2.11.1 yamllint==1.26.1 doc = - mkdocs==1.1.2 + mkdocs==1.2.1 mkdocs-exclude==1.0.2 mkdocs-include-markdown-plugin==3.1.0 mkdocs-material==7.1.2 mkdocs-material-relative-language-selector==1.1.0 mkdocs-minify-plugin==0.4.0 - mkdocstrings==0.15.1 + mkdocstrings==0.15.2 pymdown-extensions==8.1.1 lint = flake8==3.9.1 @@ -71,10 +71,9 @@ lint = isort==5.8.0 yamllint==1.26.1 test = - mkdocs==1.1.2 mkdocs-exclude==1.0.2 mkdocs-material==7.1.2 - mkdocstrings==0.15.1 + mkdocstrings==0.15.2 pymdown-extensions==8.1.1 pytest==6.2.3 pytest-cov==2.11.1 diff --git a/tests/conftest.py b/tests/conftest.py index a6ca991..1ed06e5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -51,6 +51,7 @@ def _mkdocs_build( mkdocs_config = { 'site_name': 'My site', + 'site_url': 'https://foo.bar', 'docs_dir': docs_dir, 'site_dir': site_dir, 'plugins': [], diff --git a/tests/test_plugin_config.py b/tests/test_plugin_config.py index a12ded7..d73221a 100644 --- a/tests/test_plugin_config.py +++ b/tests/test_plugin_config.py @@ -286,26 +286,14 @@ def test_config( 'languages': 5, }, None, - mkdocs.exceptions.ConfigurationError, + mkdocs.config.base.ValidationError, ( - "Plugin value: 'languages'. Error: Expected type:" - " but received: " + 'You must define the languages you will translate the content' + " into using the 'plugins.mdpo.languages' configuration" + ' setting.' ), id='languages:', ), - pytest.param( - { - 'languages': ['en', 'es'], - 'default_language': 5, - }, - None, - mkdocs.exceptions.ConfigurationError, - ( - "Plugin value: 'default_language'. Error: Expected type:" - " but received: " - ), - id='default_language:', - ), pytest.param( { 'default_language': 'es', @@ -412,6 +400,7 @@ def test_plugin_config_errors( mkdocs_config = { 'site_name': 'My site', + 'site_url': 'https://foo.bar', 'docs_dir': docs_dir, 'site_dir': site_dir, 'plugins': [