From 502ce7256fba473c8f8bb6a3f8e6980afd1e8094 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sun, 2 Oct 2022 15:13:33 +0200 Subject: [PATCH 1/9] Switch to Hatch build, add pyproject.toml --- .github/workflows/deploy-release.yml | 16 ++--- pyproject.toml | 93 ++++++++++++++++++++++++++++ setup.cfg | 13 ---- tox.ini | 2 +- 4 files changed, 102 insertions(+), 22 deletions(-) create mode 100644 pyproject.toml diff --git a/.github/workflows/deploy-release.yml b/.github/workflows/deploy-release.yml index 3cc3f4f8d1..5de20df578 100644 --- a/.github/workflows/deploy-release.yml +++ b/.github/workflows/deploy-release.yml @@ -14,20 +14,20 @@ jobs: - name: Setup Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.9 - name: Install dependencies run: | - python -m pip install --upgrade pip setuptools wheel babel + python -m pip install -U wheel hatch babel - name: Compile localization message files run: | python setup.py compile_catalog -t mkdocs python setup.py compile_catalog -t readthedocs - name: Build run: | - python setup.py bdist_wheel sdist --formats gztar + hatch build - name: Publish - if: success() - uses: pypa/gh-action-pypi-publish@v1.4.1 - with: - user: __token__ - password: ${{ secrets.PYPI_PASSWORD }} + run: | + hatch publish + env: + HATCH_INDEX_USER: __token__ + HATCH_INDEX_AUTH: ${{ secrets.PYPI_PASSWORD }} diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..75e18287d7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,93 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "mkdocs" +description = "Project documentation with Markdown." +readme = "README.md" +# license = "BSD-2-Clause" +authors = [ + {name = "Tom Christie", email = "tom@tomchristie.com"}, +] +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Environment :: Web Environment", + "Intended Audience :: Developers", + "License :: OSI Approved :: BSD License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "Topic :: Documentation", + "Topic :: Text Processing", +] +dynamic = ["version", "license"] +requires-python = ">=3.7" +dependencies = [ + "click >=7.0", + "Jinja2 >=2.11.1", + "Markdown >=3.2.1, <3.4", + "PyYAML >=5.1", + "watchdog >=2.0", + "ghp-import >=1.0", + "pyyaml_env_tag >=0.1", + "importlib_metadata >=4.3; python_version < '3.10'", + "typing_extensions >=3.10; python_version < '3.8'", + "packaging >=20.5", + "mergedeep >=1.3.4", + "colorama >=0.4; platform_system == 'Windows'", +] +[project.optional-dependencies] +i18n = [ + "babel >=2.9.0", +] + +[project.urls] +Documentation = "https://www.mkdocs.org/" +Source = "https://github.com/mkdocs/mkdocs" +Issues = "https://github.com/mkdocs/mkdocs/issues" +History = "https://www.mkdocs.org/about/release-notes/" + +[project.scripts] +mkdocs = "mkdocs.__main__:cli" + +[project.entry-points."mkdocs.themes"] +mkdocs = "mkdocs.themes.mkdocs" +readthedocs = "mkdocs.themes.readthedocs" + +[project.entry-points."mkdocs.plugins"] +search = "mkdocs.contrib.search:SearchPlugin" + +[tool.hatch.build] +include = ["/mkdocs"] +artifacts = ["/mkdocs/**/*.mo"] + +[tool.hatch.build.targets.wheel] +exclude = ["/mkdocs/tests/integration", "*.po", "*.pot", "babel.cfg"] + +[tool.hatch.version] +path = "mkdocs/__init__.py" + +[tool.black] +line-length = 100 +target-version = ["py37"] +skip-string-normalization = true + +[tool.isort] +profile = "black" +line_length = 100 + +[tool.mypy] +ignore_missing_imports = true +warn_unreachable = true +no_implicit_optional = true +show_error_codes = true diff --git a/setup.cfg b/setup.cfg index 60109b65cb..b70893f396 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,20 +1,7 @@ -[metadata] -license_files = LICENSE - [flake8] max-line-length = 119 extend-ignore = E203 -[isort] -profile = black -line_length = 100 - -[mypy] -ignore_missing_imports = true -warn_unreachable = true -no_implicit_optional = true -show_error_codes = true - [compile_catalog] statistics = True domain = messages diff --git a/tox.ini b/tox.ini index bac7c3fbc8..adb98e51ed 100644 --- a/tox.ini +++ b/tox.ini @@ -19,7 +19,7 @@ commands= [testenv:black] deps=black skip_install=true -commands={envbindir}/black -l100 -tpy37 --skip-string-normalization mkdocs +commands={envbindir}/black mkdocs [testenv:isort] deps=isort From cc5c82ce8d748cf3522eae73b99ad95eef3c8c7b Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sun, 2 Oct 2022 23:43:42 +0200 Subject: [PATCH 2/9] Remove pybabel setuptools integration --- .github/workflows/deploy-release.yml | 4 +- .github/workflows/tox.yml | 4 +- docs/about/contributing.md | 2 +- docs/dev-guide/themes.md | 157 +---------- docs/dev-guide/translations.md | 14 +- mkdocs/commands/babel.py | 5 + mkdocs/commands/setup.py | 16 -- mkdocs/tests/babel_cmd_tests.py | 372 --------------------------- setup.cfg | 19 -- setup.py | 24 -- 10 files changed, 23 insertions(+), 594 deletions(-) delete mode 100644 mkdocs/commands/setup.py delete mode 100644 mkdocs/tests/babel_cmd_tests.py diff --git a/.github/workflows/deploy-release.yml b/.github/workflows/deploy-release.yml index 3cc3f4f8d1..b8ea99519f 100644 --- a/.github/workflows/deploy-release.yml +++ b/.github/workflows/deploy-release.yml @@ -20,8 +20,8 @@ jobs: python -m pip install --upgrade pip setuptools wheel babel - name: Compile localization message files run: | - python setup.py compile_catalog -t mkdocs - python setup.py compile_catalog -t readthedocs + pybabel compile --statistics --directory mkdocs/themes/mkdocs/locales + pybabel compile --statistics --directory mkdocs/themes/readthedocs/locales - name: Build run: | python setup.py bdist_wheel sdist --formats gztar diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 7c8e56d60b..d6a90d3702 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -106,5 +106,5 @@ jobs: python -m pip install setuptools babel - name: Compile localization message files run: | - python setup.py compile_catalog -t mkdocs - python setup.py compile_catalog -t readthedocs + pybabel compile --statistics --directory mkdocs/themes/mkdocs/locales + pybabel compile --statistics --directory mkdocs/themes/readthedocs/locales diff --git a/docs/about/contributing.md b/docs/about/contributing.md index ad302a3eab..3f09efed85 100644 --- a/docs/about/contributing.md +++ b/docs/about/contributing.md @@ -90,7 +90,7 @@ updated by running the `extract_messages` command. For example, to update the `pot` file of the `mkdocs` theme, run the following command: ```bash -python setup.py extract_messages -t mkdocs +pybabel extract --project=MkDocs --copyright-holder=MkDocs --msgid-bugs-address='https://github.com/mkdocs/mkdocs/issues' --no-wrap --version="$(grep -Eo "\\b[123][^']+" mkdocs/__init__.py)" --mapping-file mkdocs/themes/babel.cfg --output-file mkdocs/themes/mkdocs/messages.pot mkdocs/themes/mkdocs ``` The updated `pot` file should be included in a PR with the updated template. diff --git a/docs/dev-guide/themes.md b/docs/dev-guide/themes.md index 771d2519c7..46bfaaf7f4 100644 --- a/docs/dev-guide/themes.md +++ b/docs/dev-guide/themes.md @@ -964,142 +964,24 @@ same commands utilized by MkDocs. [localization/translation]: ../user-guide/localizing-your-theme.md -### Enabling the Localization/Translation commands - -MkDocs includes some helper commands which are light wrappers around [pybabel's -commands][pybabel]. To use the commands on your own theme, add the following to -your theme's `setup.py` script: - -```python -from mkdocs.commands.setup import babel_cmdclass - -setup( - ... - cmdclass=babel_cmdclass -) -``` - -Note that `cmdclass=babel_cmdclass` was added an a parameter passed to -the `setup` function. +### Using the Localization/Translation commands WARNING: -As **pybabel is not installed by default** and most users will not have +As **[pybabel] is not installed by default** and most users will not have pybabel installed, theme developers and/or translators should make sure to have installed the necessary dependencies (using `pip install mkdocs[i18n]`) in order for the commands to be available for use. -[pybabel]: https://babel.pocoo.org/en/latest/setup.html - -### Using the Localization/Translation commands - -Since the translation commands are embedded in the `setup.py` script of your -custom theme they should be called from the root of your theme's working -tree as follows: - -```bash -python setup.py [OPTIONS] -``` - -Each command provides a detailed list of options available with the `-h/--help` -option. +The translation commands should be called from the root of your theme's working tree. For an overview of the workflow used by MkDocs to translate the built-in themes, see the appropriate [section] of the Contributing Guide and the [Translation Guide]. -Default values for many of the options to the commands can be defined in a -`setup.cfg` file. Create a section using the command name as the section name, -and the long option name as the key. See MkDocs' own [setup.cfg] file for an -example. - -A summary of changes/additions to the behavior and options of the upstream -[pybabel commands][pybabel] are summarized below. - +[pybabel]: https://babel.pocoo.org/en/latest/setup.html [section]: ../about/contributing.md#submitting-changes-to-the-builtin-themes [Translation Guide]: translations.md -[setup.cfg]: https://github.com/mkdocs/mkdocs/blob/master/setup.cfg - -#### compile_catalog - -The `-t/--theme` option has been added to this command. The `theme` specified -must be a `theme` defined as a entry point in the same `setup.py` script. Other -themes will not be recognized. If only one `theme` has been defined as an entry -point, then that `theme` will be used as the default if none is specified by -this option. If more than one `theme` is defined as entry points, then no -default is set and a `theme` must be specified by this option. The command only -operates on one theme at a time. Therefore, the command needs to be run once -for each theme included in a package. - -When a `theme` is specified, the directory of that `theme` as defined in the -entry point is used to define a default value of the `-d/--directory` option. -The `--directory` option is set to `{theme_dir}/locales`. If a `directory` is -passed to the `--directory` option, then the `theme` option is ignored. - -#### extract_messages - -The `-t/--theme` option has been added to this command. The `theme` specified -must be a `theme` defined as a entry point in the same `setup.py` script. Other -themes will not be recognized. If only one `theme` has been defined as an entry -point, then that `theme` will be used as the default if none is specified by -this option. If more than one `theme` is defined as entry points, then no -default is set and a `theme` must be specified by this option. The command only -operates on one theme at a time. Therefore, the command needs to be run once -for each theme included in a package. - -When a `theme` is specified, the directory of that `theme` as defined in the -entry point is used to define a default value for the `--input-dirs` and -`--output-file` options. The `--input-dirs` option is set to the `theme` -directory and `--output-file` is set to `{theme_dir}/{domain}.pot`. If a path -is provided to either option, then the `theme` option is ignored for that -option. - -The `--domain` option has been added to this command and can be used to -override the `domain` used for the `output-file` based on the `theme`. -Defaults to `messages`. - -The `-F/--mapping-file` option defaults to the [mapping file] used by MkDocs' -built-in themes. However, if that mapping file does not meet your theme's needs -to can override it by providing your own and passing the path of that file into -the option. - -[mapping file]: https://github.com/mkdocs/mkdocs/tree/master/mkdocs/themes/babel.cfg - -#### init_catalog - -The `-t/--theme` option has been added to this command. The `theme` specified -must be a `theme` defined as a entry point in the same `setup.py` script. Other -themes will not be recognized. If only one `theme` has been defined as an entry -point, then that `theme` will be used as the default if none is specified by -this option. If more than one `theme` is defined as entry points, then no -default is set and a `theme` must be specified by this option. The command only -operates on one theme at a time. Therefore, the command needs to be run once -for each theme included in a package. - -When a `theme` is specified, the directory of that `theme` as defined in the -entry point is used to define a default value for the `-i/--input-file` and -`-d/--output-dir` options. The `--input-file` option is set to -`{theme_dir}/{domain}.pot` (`domain` defaults to `messages`) and `--output-dir` -is set to `{theme_dir}/locales`. If a path is provided to either option, then -the `theme` option is ignored for that option. - -#### update_catalog - -The `-t/--theme` option has been added to this command. The `theme` specified -must be a `theme` defined as a entry point in the same `setup.py` script. Other -themes will not be recognized. If only one `theme` has been defined as an entry -point, then that `theme` will be used as the default if none is specified by -this option. If more than one `theme` is defined as entry points, then no -default is set and a `theme` must be specified by this option. The command only -operates on one theme at a time. Therefore, the command needs to be run once -for each theme included in a package. - -When a `theme` is specified, the directory of that `theme` as defined in the -entry point is used to define a default value for the `-i/--input-file` and -`-d/--output-dir` options. The `--input-file` option is set to -`{theme_dir}/{domain}.pot` (`domain` defaults to `messages`) and `--output-dir` -is set to `{theme_dir}/locales`. If a path is provided to either option, then -the `theme` option is ignored for that option. ### Example custom theme Localization/Translation workflow @@ -1114,28 +996,7 @@ the `theme` option is ignored for that option. Let's suppose that you're working on your own fork of the [mkdocs-basic-theme][basic theme] and want to add translations to it. -You would first modify the `setup.py` like this: - -```diff ---- a/setup.py -+++ b/setup.py -@@ -1,4 +1,5 @@ - from setuptools import setup, find_packages -+from mkdocs.commands.setup import babel_cmdclass - - VERSION = '1.1' - -@@ -18,5 +19,6 @@ setup( - 'basictheme = basic_theme', - ] - }, -- zip_safe=False -+ zip_safe=False, -+ cmdclass=babel_cmdclass - ) -``` - -Next, you would edit the templates by wrapping text in your HTML sources with +Edit the templates by wrapping text in your HTML sources with `{% trans %}` and `{% endtrans %}` as follows: ```diff @@ -1163,12 +1024,8 @@ While the Portable Object Template (`pot`) file created by the editing translations, they are not used by MkDocs directly and do not need to be included in a packaged release of a theme. When MkDocs builds a site with translations, it only makes use of the binary `mo` files(s) for the specified -locale. Therefore, when [packaging a theme], you would need to make the -following addition to your `MANIFEST.in` file: - -```text -recursive-include theme_name *.mo -``` +locale. Therefore, when [packaging a theme], make sure to include it in the +"wheels", using a `MANIFEST.in` file or otherwise. Then, before building your Python package, you will want to ensure that the binary `mo` file for each locale is up-to-date by running the `compile_catalog` diff --git a/docs/dev-guide/translations.md b/docs/dev-guide/translations.md index 546ceeb951..9763b06718 100644 --- a/docs/dev-guide/translations.md +++ b/docs/dev-guide/translations.md @@ -28,10 +28,8 @@ internationalization/localization plugin. ## Localization tooling prerequisites Theme localization makes use of the [babel][babel] project for generation and -compilation of localization files. Custom commands are available from the -MkDocs' `setup.py` script as described below to assist with the process of -updating and contributing translations. You will need to be working from the -git working tree on your local machine to make use of the helper scripts. +compilation of localization files. You will need to be working from the +git working tree on your local machine to make use of the translation commands. See the [Contributing Guide] for direction on how to [Install for Development] and [Submit a Pull Request]. The instructions in this document assume that you @@ -81,12 +79,12 @@ Initializing a catalog consists of running a command which will create a directory structure for your desired language and prepare a Portable Object (`messages.po`) file derived from the `pot` file of the theme. -Use the `init_catalog` command on each theme (`-t `) and provide the +Use the `init_catalog` command on each theme's directory and provide the appropriate language code (`-l `). For example, to add a translation for the Spanish `es` language to the `mkdocs` theme, run the following command: ```bash -python setup.py init_catalog -t mkdocs -l es +pybabel init --input-file mkdocs/themes/mkdocs/messages.pot --output-dir mkdocs/themes/mkdocs/locales --locale es ``` The above command will create the following file structure: @@ -123,7 +121,7 @@ To update the `fr` translation catalog of the `mkdocs` theme, use the following command: ```bash -python setup.py update_catalog -t mkdocs -l fr +pybabel update --ignore-obsolete --update-header-comment --input-file mkdocs/themes/mkdocs/messages.pot --output-dir mkdocs/themes/mkdocs/locales --locale fr ``` You can now move on to the next step and [add a translation] for every updated @@ -155,7 +153,7 @@ files of your theme into `messages.mo` files. The following command will compile the `es` translation for the `mkdocs` theme. ```bash -python setup.py compile_catalog -t mkdocs -l es +pybabel compile --statistics --directory mkdocs/themes/mkdocs/locales --locale es ``` The above command results in the following file structure: diff --git a/mkdocs/commands/babel.py b/mkdocs/commands/babel.py index 9de5be8f1f..b858e845b4 100644 --- a/mkdocs/commands/babel.py +++ b/mkdocs/commands/babel.py @@ -1,12 +1,17 @@ from __future__ import annotations import sys +import warnings from distutils.errors import DistutilsOptionError from os import path from babel.messages import frontend as babel from pkg_resources import EntryPoint +warnings.warn( + "mkdocs.commands.babel is never used in MkDocs and will be removed soon.", DeprecationWarning +) + DEFAULT_MAPPING_FILE = path.normpath( path.join(path.abspath(path.dirname(__file__)), '../themes/babel.cfg') ) diff --git a/mkdocs/commands/setup.py b/mkdocs/commands/setup.py deleted file mode 100644 index f68e36838b..0000000000 --- a/mkdocs/commands/setup.py +++ /dev/null @@ -1,16 +0,0 @@ -try: - from mkdocs.commands.babel import ( - compile_catalog, - extract_messages, - init_catalog, - update_catalog, - ) - - babel_cmdclass = { - 'compile_catalog': compile_catalog, - 'extract_messages': extract_messages, - 'init_catalog': init_catalog, - 'update_catalog': update_catalog, - } -except ImportError: - babel_cmdclass = {} diff --git a/mkdocs/tests/babel_cmd_tests.py b/mkdocs/tests/babel_cmd_tests.py deleted file mode 100644 index c0db34a319..0000000000 --- a/mkdocs/tests/babel_cmd_tests.py +++ /dev/null @@ -1,372 +0,0 @@ -import functools -import unittest -from distutils.dist import Distribution -from distutils.errors import DistutilsOptionError -from os import path - -from mkdocs.commands import babel - -BASE_DIR = path.normpath(path.join(path.abspath(path.dirname(__file__)), '../../')) - - -@functools.lru_cache(maxsize=None) -def _distribution(**kwargs): - return Distribution(kwargs) - - -class ThemeMixinTests(unittest.TestCase): - def test_dict_entry_point(self): - inst = babel.ThemeMixin() - inst.distribution = _distribution() - inst.distribution.entry_points = { - 'mkdocs.themes': [ - 'mkdocs = mkdocs.themes.mkdocs', - ], - } - inst.theme = 'mkdocs' - self.assertEqual(inst.get_theme_dir(), path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs')) - - def test_ini_entry_point(self): - inst = babel.ThemeMixin() - inst.distribution = _distribution() - inst.distribution.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - inst.theme = 'mkdocs' - self.assertEqual(inst.get_theme_dir(), path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs')) - - def test_one_entry_point_as_default(self): - inst = babel.ThemeMixin() - inst.distribution = _distribution() - inst.distribution.entry_points = { - 'mkdocs.themes': [ - 'mkdocs = mkdocs.themes.mkdocs', - ], - } - inst.theme = None - self.assertEqual(inst.get_theme_dir(), path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs')) - - def test_multiple_entry_points(self): - inst = babel.ThemeMixin() - inst.distribution = _distribution() - inst.distribution.entry_points = { - 'mkdocs.themes': [ - 'mkdocs = mkdocs.themes.mkdocs', - 'readthedocs = mkdocs.themes.readthedocs', - ], - } - inst.theme = 'readthedocs' - self.assertEqual( - inst.get_theme_dir(), path.join(BASE_DIR, 'mkdocs', 'themes', 'readthedocs') - ) - - def test_multiple_entry_points_no_default(self): - inst = babel.ThemeMixin() - inst.distribution = _distribution() - inst.distribution.entry_points = { - 'mkdocs.themes': [ - 'mkdocs = mkdocs.themes.mkdocs', - 'readthedocs = mkdocs.themes.readthedocs', - ], - } - inst.theme = None - self.assertRaises(DistutilsOptionError, inst.get_theme_dir) - - def test_no_entry_points(self): - inst = babel.ThemeMixin() - inst.distribution = _distribution() - inst.distribution.entry_points = {} - inst.theme = 'mkdocs' - self.assertRaises(DistutilsOptionError, inst.get_theme_dir) - - def test_undefined_entry_point(self): - inst = babel.ThemeMixin() - inst.distribution = _distribution() - inst.distribution.entry_points = { - 'mkdocs.themes': [ - 'mkdocs = mkdocs.themes.mkdocs', - ], - } - inst.theme = 'undefined' - self.assertRaises(DistutilsOptionError, inst.get_theme_dir) - - -class CommandTests(unittest.TestCase): - def test_compile_catalog(self): - dist = _distribution() - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.compile_catalog(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.finalize_options() - self.assertEqual(cmd.directory, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/locales')) - - def test_compile_catalog_default_theme(self): - dist = _distribution() - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.compile_catalog(dist) - cmd.initialize_options() - self.assertIsNone(cmd.theme) - cmd.finalize_options() - self.assertEqual(cmd.theme, 'mkdocs') - self.assertEqual(cmd.directory, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/locales')) - - def test_compile_catalog_ignore_theme(self): - dist = _distribution() - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.compile_catalog(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.directory = 'foo/bar' - cmd.finalize_options() - self.assertEqual(cmd.directory, 'foo/bar') - - def test_extract_messages(self): - dist = _distribution(name='foo', version='1.2') - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.extract_messages(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.finalize_options() - self.assertEqual(cmd.input_paths, [path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs')]) - self.assertEqual( - cmd.output_file, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/messages.pot') - ) - self.assertEqual(cmd.mapping_file, babel.DEFAULT_MAPPING_FILE) - self.assertEqual(cmd.project, 'foo') - self.assertEqual(cmd.version, '1.2') - - def test_extract_messages_default_theme(self): - dist = _distribution(name='foo', version='1.2') - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.extract_messages(dist) - cmd.initialize_options() - self.assertIsNone(cmd.theme) - cmd.finalize_options() - self.assertEqual(cmd.theme, 'mkdocs') - self.assertEqual(cmd.input_paths, [path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs')]) - self.assertEqual( - cmd.output_file, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/messages.pot') - ) - - def test_extract_messages_ingore_theme(self): - dist = _distribution(name='foo', version='1.2') - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.extract_messages(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.input_paths = 'mkdocs/tests' - cmd.output_file = 'foo/bar/messages.pot' - cmd.finalize_options() - self.assertEqual(cmd.input_paths, ['mkdocs/tests']) - self.assertEqual(cmd.output_file, 'foo/bar/messages.pot') - - def test_extract_messages_ingore_theme_for_input(self): - dist = _distribution(name='foo', version='1.2') - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.extract_messages(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.input_paths = 'mkdocs/tests' - cmd.finalize_options() - self.assertEqual(cmd.input_paths, ['mkdocs/tests']) - self.assertEqual( - cmd.output_file, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/messages.pot') - ) - - def test_extract_messages_ingore_theme_for_output(self): - dist = _distribution(name='foo', version='1.2') - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.extract_messages(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.output_file = 'foo/bar/messages.pot' - cmd.finalize_options() - self.assertEqual(cmd.input_paths, [path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs')]) - self.assertEqual(cmd.output_file, 'foo/bar/messages.pot') - - def test_init_catalog(self): - dist = _distribution() - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.init_catalog(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.locale = 'en' - cmd.finalize_options() - self.assertEqual( - cmd.input_file, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/messages.pot') - ) - self.assertEqual(cmd.output_dir, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/locales')) - - def test_init_catalog_default_theme(self): - dist = _distribution() - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.init_catalog(dist) - cmd.initialize_options() - cmd.locale = 'en' - self.assertIsNone(cmd.theme) - cmd.finalize_options() - self.assertEqual(cmd.theme, 'mkdocs') - self.assertEqual( - cmd.input_file, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/messages.pot') - ) - self.assertEqual(cmd.output_dir, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/locales')) - - def test_init_catalog_ignore_theme(self): - dist = _distribution() - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.init_catalog(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.locale = 'en' - cmd.input_file = 'mkdocs/themes/mkdocs/messages.pot' - cmd.output_dir = 'foo/bar' - cmd.finalize_options() - self.assertEqual(cmd.input_file, 'mkdocs/themes/mkdocs/messages.pot') - self.assertEqual(cmd.output_dir, 'foo/bar') - - def test_init_catalog_ignore_theme_for_input(self): - dist = _distribution() - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.init_catalog(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.locale = 'en' - cmd.input_file = 'mkdocs/themes/mkdocs/messages.pot' - cmd.finalize_options() - self.assertEqual(cmd.input_file, 'mkdocs/themes/mkdocs/messages.pot') - self.assertEqual(cmd.output_dir, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/locales')) - - def test_init_catalog_ignore_theme_for_output(self): - dist = _distribution() - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.init_catalog(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.locale = 'en' - cmd.output_dir = 'foo/bar' - cmd.finalize_options() - self.assertEqual( - cmd.input_file, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/messages.pot') - ) - self.assertEqual(cmd.output_dir, 'foo/bar') - - def test_update_catalog(self): - dist = _distribution() - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.update_catalog(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.finalize_options() - self.assertEqual( - cmd.input_file, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/messages.pot') - ) - self.assertEqual(cmd.output_dir, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/locales')) - - def test_update_catalog_default_theme(self): - dist = _distribution() - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.update_catalog(dist) - cmd.initialize_options() - cmd.locale = 'en' - self.assertIsNone(cmd.theme) - cmd.finalize_options() - self.assertEqual(cmd.theme, 'mkdocs') - self.assertEqual( - cmd.input_file, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/messages.pot') - ) - self.assertEqual(cmd.output_dir, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/locales')) - - def test_update_catalog_ignore_theme(self): - dist = _distribution() - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.update_catalog(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.locale = 'en' - cmd.input_file = 'mkdocs/themes/readthedocs/messages.pot' - cmd.output_dir = 'foo/bar' - cmd.finalize_options() - self.assertEqual(cmd.input_file, 'mkdocs/themes/readthedocs/messages.pot') - self.assertEqual(cmd.output_dir, 'foo/bar') - - def test_update_catalog_ignore_theme_for_input(self): - dist = _distribution() - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.update_catalog(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.locale = 'en' - cmd.input_file = 'mkdocs/themes/mkdocs/messages.pot' - cmd.finalize_options() - self.assertEqual(cmd.input_file, 'mkdocs/themes/mkdocs/messages.pot') - self.assertEqual(cmd.output_dir, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/locales')) - - def test_update_catalog_ignore_theme_for_output(self): - dist = _distribution() - dist.entry_points = ''' - [mkdocs.themes] - mkdocs = mkdocs.themes.mkdocs - ''' - cmd = babel.update_catalog(dist) - cmd.initialize_options() - cmd.theme = 'mkdocs' - cmd.locale = 'en' - cmd.output_dir = 'foo/bar' - cmd.finalize_options() - self.assertEqual( - cmd.input_file, path.join(BASE_DIR, 'mkdocs', 'themes', 'mkdocs/messages.pot') - ) - self.assertEqual(cmd.output_dir, 'foo/bar') diff --git a/setup.cfg b/setup.cfg index 60109b65cb..5aa7537760 100644 --- a/setup.cfg +++ b/setup.cfg @@ -14,22 +14,3 @@ ignore_missing_imports = true warn_unreachable = true no_implicit_optional = true show_error_codes = true - -[compile_catalog] -statistics = True -domain = messages - -[extract_messages] -copyright_holder = MkDocs -domain = messages -msgid_bugs_address = "https://github.com/mkdocs/mkdocs/issues" -project = MkDocs -no_wrap = True - -[init_catalog] -domain = messages - -[update_catalog] -ignore_obsolete = True -update_header_comment = True -domain = messages diff --git a/setup.py b/setup.py index 05860e7801..b5ef3f05ea 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,6 @@ import os import sys -from mkdocs.commands.setup import babel_cmdclass with open('README.md') as f: long_description = f.read() @@ -25,28 +24,6 @@ def get_packages(package): if os.path.exists(os.path.join(dirpath, '__init__.py'))] -if sys.argv[-1] == 'publish': - if os.system("pip freeze | grep wheel"): - print("wheel not installed.\nUse `pip install wheel`.\nExiting.") - sys.exit() - if os.system("pip freeze | grep twine"): - print("twine not installed.\nUse `pip install twine`.\nExiting.") - sys.exit() - if os.system("pip freeze | grep Babel"): - print("babel not installed.\nUse `pip install babel`.\nExiting.") - sys.exit() - for locale in os.listdir("mkdocs/themes/mkdocs/locales"): - os.system(f"python setup.py compile_catalog -t mkdocs -l {locale}") - os.system(f"python setup.py compile_catalog -t readthedocs -l {locale}") - os.system("python setup.py sdist bdist_wheel") - os.system("twine upload dist/*") - print("You probably want to also tag the version now:") - version = get_version("mkdocs") - print(f" git tag -a {version} -m 'version {version}'") - print(" git push --tags") - sys.exit() - - setup( name="mkdocs", version=get_version("mkdocs"), @@ -112,7 +89,6 @@ def get_packages(package): 'Topic :: Text Processing', ], zip_safe=False, - cmdclass=babel_cmdclass, ) # (*) Please direct queries to the discussion group: From 64ec379d3215a38f080537112dd6afa3c459f572 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sun, 2 Oct 2022 23:52:50 +0200 Subject: [PATCH 3/9] Continue migration --- .flake8 | 3 +++ MANIFEST.in | 5 ----- pyproject.toml | 4 ++-- tox.ini | 1 + 4 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 .flake8 delete mode 100644 MANIFEST.in diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000..564a578cf1 --- /dev/null +++ b/.flake8 @@ -0,0 +1,3 @@ +[flake8] +max-line-length = 119 +extend-ignore = E203 diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 032a060c09..0000000000 --- a/MANIFEST.in +++ /dev/null @@ -1,5 +0,0 @@ -include README.md -include LICENSE -recursive-include mkdocs *.ico *.js *.css *.png *.html *.eot *.svg *.ttf *.woff *.woff2 *.xml *.mustache *mkdocs_theme.yml *.mo -recursive-exclude * __pycache__ -recursive-exclude * *.py[co] diff --git a/pyproject.toml b/pyproject.toml index 75e18287d7..88adeff72c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "hatchling.build" name = "mkdocs" description = "Project documentation with Markdown." readme = "README.md" -# license = "BSD-2-Clause" +license = "BSD-2-Clause" authors = [ {name = "Tom Christie", email = "tom@tomchristie.com"}, ] @@ -30,7 +30,7 @@ classifiers = [ "Topic :: Documentation", "Topic :: Text Processing", ] -dynamic = ["version", "license"] +dynamic = ["version"] requires-python = ">=3.7" dependencies = [ "click >=7.0", diff --git a/tox.ini b/tox.ini index adb98e51ed..1b181c349d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,4 +1,5 @@ [tox] +isolated_build = true envlist = py{37,38,39,310,py3}-{unittests,min-req,integration,integration-no-babel}, black, isort, flake8, markdown-lint, linkchecker, jshint, csslint, nobabel, codespell From 5cdb194b84291d515cbf1f6626df777be9753eb1 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Sun, 2 Oct 2022 23:58:56 +0200 Subject: [PATCH 4/9] Remove setup files --- setup.cfg | 3 -- setup.py | 95 ------------------------------------------------------- 2 files changed, 98 deletions(-) delete mode 100644 setup.cfg delete mode 100755 setup.py diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 564a578cf1..0000000000 --- a/setup.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[flake8] -max-line-length = 119 -extend-ignore = E203 diff --git a/setup.py b/setup.py deleted file mode 100755 index b5ef3f05ea..0000000000 --- a/setup.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env python - -from setuptools import setup -import re -import os -import sys - - -with open('README.md') as f: - long_description = f.read() - - -def get_version(package): - """Return package version as listed in `__version__` in `init.py`.""" - with open(os.path.join(package, '__init__.py')) as f: - init_py = f.read() - return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1) - - -def get_packages(package): - """Return root package and all sub-packages.""" - return [dirpath - for dirpath, dirnames, filenames in os.walk(package) - if os.path.exists(os.path.join(dirpath, '__init__.py'))] - - -setup( - name="mkdocs", - version=get_version("mkdocs"), - url='https://www.mkdocs.org', - project_urls={ - 'Source': 'https://github.com/mkdocs/mkdocs', - }, - license='BSD', - description='Project documentation with Markdown.', - long_description=long_description, - long_description_content_type='text/markdown', - author='Tom Christie', - author_email='tom@tomchristie.com', # SEE NOTE BELOW (*) - packages=get_packages("mkdocs"), - include_package_data=True, - package_data={'mkdocs': ['py.typed']}, - install_requires=[ - 'click>=7.0', - 'Jinja2>=2.11.1', - 'Markdown>=3.2.1,<3.4', - 'PyYAML>=5.1', - 'watchdog>=2.0', - 'ghp-import>=1.0', - 'pyyaml_env_tag>=0.1', - 'importlib_metadata>=4.3; python_version < "3.10"', - 'typing_extensions>=3.10; python_version < "3.8"', - 'packaging>=20.5', - 'mergedeep>=1.3.4', - 'colorama>=0.4; platform_system == "Windows"', - ], - extras_require={"i18n": ['babel>=2.9.0']}, - python_requires='>=3.7', - entry_points={ - 'console_scripts': [ - 'mkdocs = mkdocs.__main__:cli', - ], - 'mkdocs.themes': [ - 'mkdocs = mkdocs.themes.mkdocs', - 'readthedocs = mkdocs.themes.readthedocs', - ], - 'mkdocs.plugins': [ - 'search = mkdocs.contrib.search:SearchPlugin', - ], - }, - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Environment :: Console', - 'Environment :: Web Environment', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3 :: Only', - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - 'Topic :: Documentation', - 'Topic :: Text Processing', - ], - zip_safe=False, -) - -# (*) Please direct queries to the discussion group: -# https://groups.google.com/forum/#!forum/mkdocs From 0d9c0cd30a7acd9c6c8f79d7d5dde2702d5b89a0 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Mon, 3 Oct 2022 19:35:42 +0200 Subject: [PATCH 5/9] Can use `hatch version` --- docs/about/contributing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/about/contributing.md b/docs/about/contributing.md index 3f09efed85..8d21e43476 100644 --- a/docs/about/contributing.md +++ b/docs/about/contributing.md @@ -90,7 +90,7 @@ updated by running the `extract_messages` command. For example, to update the `pot` file of the `mkdocs` theme, run the following command: ```bash -pybabel extract --project=MkDocs --copyright-holder=MkDocs --msgid-bugs-address='https://github.com/mkdocs/mkdocs/issues' --no-wrap --version="$(grep -Eo "\\b[123][^']+" mkdocs/__init__.py)" --mapping-file mkdocs/themes/babel.cfg --output-file mkdocs/themes/mkdocs/messages.pot mkdocs/themes/mkdocs +pybabel extract --project=MkDocs --copyright-holder=MkDocs --msgid-bugs-address='https://github.com/mkdocs/mkdocs/issues' --no-wrap --version="$(hatch version)" --mapping-file mkdocs/themes/babel.cfg --output-file mkdocs/themes/mkdocs/messages.pot mkdocs/themes/mkdocs ``` The updated `pot` file should be included in a PR with the updated template. From b7244d1c0f3a0e13f313a7649ff746f2a098c8d0 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Mon, 3 Oct 2022 22:35:09 +0200 Subject: [PATCH 6/9] Tweak build include --- pyproject.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 88adeff72c..41d6fc56a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,16 +67,16 @@ readthedocs = "mkdocs.themes.readthedocs" [project.entry-points."mkdocs.plugins"] search = "mkdocs.contrib.search:SearchPlugin" +[tool.hatch.version] +path = "mkdocs/__init__.py" + [tool.hatch.build] -include = ["/mkdocs"] artifacts = ["/mkdocs/**/*.mo"] - +[tool.hatch.build.targets.sdist] +include = ["/mkdocs", "/LICENSE", "/pyproject.toml", "/README.md"] [tool.hatch.build.targets.wheel] exclude = ["/mkdocs/tests/integration", "*.po", "*.pot", "babel.cfg"] -[tool.hatch.version] -path = "mkdocs/__init__.py" - [tool.black] line-length = 100 target-version = ["py37"] From ffce01c46c429d52a894f881ba0f14ca25a4b9d9 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Mon, 3 Oct 2022 22:39:17 +0200 Subject: [PATCH 7/9] Add back a fake setup.py --- setup.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000000..4d5ce0a930 --- /dev/null +++ b/setup.py @@ -0,0 +1,13 @@ +"""Installation using setup.py is no longer supported. +Use `python -m pip install .` instead.""" + +import sys + +from setuptools import setup + +sys.exit(__doc__) + +# Fake reference so GitHub still considers it a real package for statistics purposes. +setup( + name="mkdocs", +) From 709c450683cc1623ad0536b4034ef7874efea310 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Tue, 4 Oct 2022 18:13:59 +0200 Subject: [PATCH 8/9] Address comments --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 41d6fc56a5..f80be6c62e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,6 @@ classifiers = [ "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", @@ -73,7 +72,7 @@ path = "mkdocs/__init__.py" [tool.hatch.build] artifacts = ["/mkdocs/**/*.mo"] [tool.hatch.build.targets.sdist] -include = ["/mkdocs", "/LICENSE", "/pyproject.toml", "/README.md"] +include = ["/mkdocs"] [tool.hatch.build.targets.wheel] exclude = ["/mkdocs/tests/integration", "*.po", "*.pot", "babel.cfg"] From 7e985f3e5864e86097080481dab3ab9ee2c0e295 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Tue, 4 Oct 2022 18:50:55 +0200 Subject: [PATCH 9/9] Don't need wheel --- .github/workflows/deploy-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-release.yml b/.github/workflows/deploy-release.yml index 9e3e2a8610..053986ddee 100644 --- a/.github/workflows/deploy-release.yml +++ b/.github/workflows/deploy-release.yml @@ -17,7 +17,7 @@ jobs: python-version: 3.9 - name: Install dependencies run: | - python -m pip install -U wheel hatch babel + python -m pip install -U hatch babel - name: Compile localization message files run: | pybabel compile --statistics --directory mkdocs/themes/mkdocs/locales