diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..8074d1f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,43 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/python +{ + "name": "Python 3", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/python:0-3.10", + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/devcontainers-contrib/features/pipx-package:1": {}, + "ghcr.io/devcontainers-contrib/features/poetry:2": {}, + "ghcr.io/devcontainers-contrib/features/pre-commit:2": {} + }, + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + "forwardPorts": [ + 8000 + ], + "portsAttributes": { + "8000": { + "label": "mkdocs serve", + "onAutoForward": "notify" + } + }, + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "pip3 install --user -r requirements.txt", + "postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder} && pre-commit && poetry install", + "customizations": { + "vscode": { + "extensions": [ + "EditorConfig.EditorConfig", + "GitHub.vscode-pull-request-github", + "yzhang.markdown-all-in-one", + "ms-vscode-remote.vscode-remote-extensionpack" + ] + } + } + // Configure tool-specific properties. + // "customizations": {}, + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..2bcd70e --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 88 diff --git a/.github/workflows/workflow.pr.yml b/.github/workflows/workflow.pr.yml index 742b12a..8c7a211 100644 --- a/.github/workflows/workflow.pr.yml +++ b/.github/workflows/workflow.pr.yml @@ -30,9 +30,15 @@ jobs: - name: Install dependencies run: poetry install --only=dev + - name: Check imports sort + run: poetry run isort --check-only . + - name: Check formatting run: poetry run black --check . + - name: Check formatting + run: poetry run flake8 --count . + test: name: Test needs: lint diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..1432d96 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,13 @@ +repos: + - repo: https://github.com/psf/black + rev: 23.1.0 + hooks: + - id: black + - repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort + - repo: https://github.com/pycqa/flake8 + rev: 6.0.0 + hooks: + - id: flake8 diff --git a/dev.build.sh b/dev.build.sh index 8ab7b3b..5120871 100644 --- a/dev.build.sh +++ b/dev.build.sh @@ -1,7 +1,14 @@ #!/bin/bash rm -rf dist && rm -rf build && rm -rf site && rm -rf *.egg-info + +poetry run isort . poetry run black . +poetry run flake8 --count . + poetry build + pip uninstall -y mkdocs_file_filter_plugin pip install dist/mkdocs_file_filter_plugin-*.tar.gz + +poetry run mkdocs serve --verbose diff --git a/mkdocs.yml b/mkdocs.yml index 0c73971..a802e98 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,6 +1,6 @@ INHERIT: mkdocs.base.yml -dev_addr: 127.0.0.1:1357 +#! dev_addr: 127.0.0.1:1357 plugins: - search diff --git a/mkdocs_file_filter_plugin/external_config.py b/mkdocs_file_filter_plugin/external_config.py index a07b003..2d248a4 100644 --- a/mkdocs_file_filter_plugin/external_config.py +++ b/mkdocs_file_filter_plugin/external_config.py @@ -1,9 +1,11 @@ import os import pathlib + import yaml -from yaml_env_tag import construct_env_tag -from schema import Optional, Schema, SchemaError from mkdocs.exceptions import PluginError +from schema import Optional, Schema, SchemaError +from yaml_env_tag import construct_env_tag + from . import util as LOG diff --git a/mkdocs_file_filter_plugin/judger.py b/mkdocs_file_filter_plugin/judger.py index e0f39dc..551ab65 100644 --- a/mkdocs_file_filter_plugin/judger.py +++ b/mkdocs_file_filter_plugin/judger.py @@ -1,12 +1,14 @@ -import os import fnmatch -import re +import os import pathlib +import re + import igittigitt -from .plugin_config import PluginConfig +from mkdocs.config.defaults import MkDocsConfig from mkdocs.structure.files import File as MkDocsFile from mkdocs.structure.pages import Page as MkDocsPage -from mkdocs.config.defaults import MkDocsConfig + +from .plugin_config import PluginConfig class Judger: @@ -52,7 +54,7 @@ def evaluate(self, file: MkDocsFile): return True, "no rule" def __path_fix(self, src_path, abs_src_path): - if os.sep is not "/": + if os.sep != "/": src_path = src_path.replace(os.sep, "/") abs_src_path = abs_src_path.replace(os.sep, "/") return src_path, abs_src_path diff --git a/mkdocs_file_filter_plugin/plugin.py b/mkdocs_file_filter_plugin/plugin.py index a09f0ab..b156b5d 100644 --- a/mkdocs_file_filter_plugin/plugin.py +++ b/mkdocs_file_filter_plugin/plugin.py @@ -1,11 +1,13 @@ import pathlib -from mkdocs.plugins import BasePlugin as MkDocsPlugin + from mkdocs.config.defaults import MkDocsConfig -from mkdocs.structure.files import Files as MkDocsFiles from mkdocs.exceptions import PluginError as MkDocsPluginError +from mkdocs.plugins import BasePlugin as MkDocsPlugin +from mkdocs.structure.files import Files as MkDocsFiles + from . import util as LOG -from .judger import Judger from .external_config import ExternalConfig +from .judger import Judger from .plugin_config import PluginConfig @@ -19,7 +21,7 @@ def on_config(self, config: MkDocsConfig): file_filter_config = external_config.load(self.config.config) for k in self.config.keys(): - if k is not "config": + if k != "config": self.config[k] = file_filter_config.get(k, self.config[k]) config.watch.append(pathlib.Path(self.config.config)) diff --git a/mkdocs_file_filter_plugin/plugin_config.py b/mkdocs_file_filter_plugin/plugin_config.py index 07ca27d..645dfd1 100644 --- a/mkdocs_file_filter_plugin/plugin_config.py +++ b/mkdocs_file_filter_plugin/plugin_config.py @@ -1,5 +1,5 @@ -from mkdocs.config.base import Config as MkDocsConfigBase import mkdocs.config.config_options as MkDocsConfigOptions +from mkdocs.config.base import Config as MkDocsConfigBase class PluginConfig(MkDocsConfigBase): diff --git a/mkdocs_file_filter_plugin/util.py b/mkdocs_file_filter_plugin/util.py index 4c005da..f6936c9 100644 --- a/mkdocs_file_filter_plugin/util.py +++ b/mkdocs_file_filter_plugin/util.py @@ -1,4 +1,5 @@ import logging + from mkdocs.utils import warning_filter # ------------------------------------------ diff --git a/poetry.lock b/poetry.lock index f614153..e8b63ab 100644 --- a/poetry.lock +++ b/poetry.lock @@ -109,6 +109,18 @@ files = [ {file = "certifi-2022.12.7.tar.gz", hash = "sha256:35824b4c3a97115964b408844d64aa14db1cc518f6562e8d7261699d1350a9e3"}, ] +[[package]] +name = "cfgv" +version = "3.3.1" +description = "Validate configuration and produce human readable error messages." +category = "dev" +optional = false +python-versions = ">=3.6.1" +files = [ + {file = "cfgv-3.3.1-py2.py3-none-any.whl", hash = "sha256:c6a0883f3917a037485059700b9e75da2464e6c27051014ad85ba6aaa5884426"}, + {file = "cfgv-3.3.1.tar.gz", hash = "sha256:f5a830efb9ce7a445376bb66ec94c638a9787422f96264c98edc6bdeed8ab736"}, +] + [[package]] name = "charset-normalizer" version = "3.0.1" @@ -262,6 +274,18 @@ files = [ {file = "contextlib2-21.6.0.tar.gz", hash = "sha256:ab1e2bfe1d01d968e1b7e8d9023bc51ef3509bba217bb730cee3827e1ee82869"}, ] +[[package]] +name = "distlib" +version = "0.3.6" +description = "Distribution utilities" +category = "dev" +optional = false +python-versions = "*" +files = [ + {file = "distlib-0.3.6-py2.py3-none-any.whl", hash = "sha256:f35c4b692542ca110de7ef0bea44d73981caeb34ca0b9b6b2e6d7790dda8f80e"}, + {file = "distlib-0.3.6.tar.gz", hash = "sha256:14bad2d9b04d3a36127ac97f30b12a19268f211063d8f8ee4f47108896e11b46"}, +] + [[package]] name = "exceptiongroup" version = "1.1.0" @@ -277,6 +301,39 @@ files = [ [package.extras] test = ["pytest (>=6)"] +[[package]] +name = "filelock" +version = "3.9.0" +description = "A platform independent file lock." +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "filelock-3.9.0-py3-none-any.whl", hash = "sha256:f58d535af89bb9ad5cd4df046f741f8553a418c01a7856bf0d173bbc9f6bd16d"}, + {file = "filelock-3.9.0.tar.gz", hash = "sha256:7b319f24340b51f55a2bf7a12ac0755a9b03e718311dac567a0f4f7fabd2f5de"}, +] + +[package.extras] +docs = ["furo (>=2022.12.7)", "sphinx (>=5.3)", "sphinx-autodoc-typehints (>=1.19.5)"] +testing = ["covdefaults (>=2.2.2)", "coverage (>=7.0.1)", "pytest (>=7.2)", "pytest-cov (>=4)", "pytest-timeout (>=2.1)"] + +[[package]] +name = "flake8" +version = "6.0.0" +description = "the modular source code checker: pep8 pyflakes and co" +category = "dev" +optional = false +python-versions = ">=3.8.1" +files = [ + {file = "flake8-6.0.0-py2.py3-none-any.whl", hash = "sha256:3833794e27ff64ea4e9cf5d410082a8b97ff1a06c16aa3d2027339cd0f1195c7"}, + {file = "flake8-6.0.0.tar.gz", hash = "sha256:c61007e76655af75e6785a931f452915b371dc48f56efd765247c8fe68f2b181"}, +] + +[package.dependencies] +mccabe = ">=0.7.0,<0.8.0" +pycodestyle = ">=2.10.0,<2.11.0" +pyflakes = ">=3.0.0,<3.1.0" + [[package]] name = "ghp-import" version = "2.1.0" @@ -295,6 +352,21 @@ python-dateutil = ">=2.8.1" [package.extras] dev = ["flake8", "markdown", "twine", "wheel"] +[[package]] +name = "identify" +version = "2.5.17" +description = "File identification library for Python" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "identify-2.5.17-py2.py3-none-any.whl", hash = "sha256:7d526dd1283555aafcc91539acc061d8f6f59adb0a7bba462735b0a318bff7ed"}, + {file = "identify-2.5.17.tar.gz", hash = "sha256:93cc61a861052de9d4c541a7acb7e3dcc9c11b398a2144f6e52ae5285f5f4f06"}, +] + +[package.extras] +license = ["ukkonen"] + [[package]] name = "idna" version = "3.4" @@ -358,6 +430,24 @@ files = [ {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, ] +[[package]] +name = "isort" +version = "5.12.0" +description = "A Python utility / library to sort Python imports." +category = "dev" +optional = false +python-versions = ">=3.8.0" +files = [ + {file = "isort-5.12.0-py3-none-any.whl", hash = "sha256:f84c2818376e66cf843d497486ea8fed8700b340f308f076c6fb1229dff318b6"}, + {file = "isort-5.12.0.tar.gz", hash = "sha256:8bef7dde241278824a6d83f44a544709b065191b95b6e50894bdc722fcba0504"}, +] + +[package.extras] +colors = ["colorama (>=0.4.3)"] +pipfile-deprecated-finder = ["pip-shims (>=0.5.2)", "pipreqs", "requirementslib"] +plugins = ["setuptools"] +requirements-deprecated-finder = ["pip-api", "pipreqs"] + [[package]] name = "jinja2" version = "3.1.2" @@ -470,6 +560,18 @@ files = [ {file = "MarkupSafe-2.1.2.tar.gz", hash = "sha256:abcabc8c2b26036d62d4c746381a6f7cf60aafcc653198ad678306986b09450d"}, ] +[[package]] +name = "mccabe" +version = "0.7.0" +description = "McCabe checker, plugin for flake8" +category = "dev" +optional = false +python-versions = ">=3.6" +files = [ + {file = "mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"}, + {file = "mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"}, +] + [[package]] name = "mergedeep" version = "1.3.4" @@ -622,6 +724,21 @@ files = [ fast = ["fastnumbers (>=2.0.0)"] icu = ["PyICU (>=1.0.0)"] +[[package]] +name = "nodeenv" +version = "1.7.0" +description = "Node.js virtual environment builder" +category = "dev" +optional = false +python-versions = ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" +files = [ + {file = "nodeenv-1.7.0-py2.py3-none-any.whl", hash = "sha256:27083a7b96a25f2f5e1d8cb4b6317ee8aeda3bdd121394e5ac54e498028a042e"}, + {file = "nodeenv-1.7.0.tar.gz", hash = "sha256:e0e7f7dfb85fc5394c6fe1e8fa98131a2473e04311a45afb6508f7cf1836fa2b"}, +] + +[package.dependencies] +setuptools = "*" + [[package]] name = "packaging" version = "23.0" @@ -678,6 +795,25 @@ files = [ dev = ["pre-commit", "tox"] testing = ["pytest", "pytest-benchmark"] +[[package]] +name = "pre-commit" +version = "3.0.4" +description = "A framework for managing and maintaining multi-language pre-commit hooks." +category = "dev" +optional = false +python-versions = ">=3.8" +files = [ + {file = "pre_commit-3.0.4-py2.py3-none-any.whl", hash = "sha256:9e3255edb0c9e7fe9b4f328cb3dc86069f8fdc38026f1bf521018a05eaf4d67b"}, + {file = "pre_commit-3.0.4.tar.gz", hash = "sha256:bc4687478d55578c4ac37272fe96df66f73d9b5cf81be6f28627d4e712e752d5"}, +] + +[package.dependencies] +cfgv = ">=2.0.0" +identify = ">=1.0.0" +nodeenv = ">=0.11.1" +pyyaml = ">=5.1" +virtualenv = ">=20.10.0" + [[package]] name = "pycodestyle" version = "2.10.0" @@ -690,6 +826,18 @@ files = [ {file = "pycodestyle-2.10.0.tar.gz", hash = "sha256:347187bdb476329d98f695c213d7295a846d1152ff4fe9bacb8a9590b8ee7053"}, ] +[[package]] +name = "pyflakes" +version = "3.0.1" +description = "passive checker of Python programs" +category = "dev" +optional = false +python-versions = ">=3.6" +files = [ + {file = "pyflakes-3.0.1-py2.py3-none-any.whl", hash = "sha256:ec55bf7fe21fff7f1ad2f7da62363d749e2a470500eab1b555334b67aa1ef8cf"}, + {file = "pyflakes-3.0.1.tar.gz", hash = "sha256:ec8b276a6b60bd80defed25add7e439881c19e64850afd9b346283d4165fd0fd"}, +] + [[package]] name = "pygments" version = "2.14.0" @@ -977,6 +1125,23 @@ files = [ [package.dependencies] contextlib2 = ">=0.5.5" +[[package]] +name = "setuptools" +version = "67.1.0" +description = "Easily download, build, install, upgrade, and uninstall Python packages" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "setuptools-67.1.0-py3-none-any.whl", hash = "sha256:a7687c12b444eaac951ea87a9627c4f904ac757e7abdc5aac32833234af90378"}, + {file = "setuptools-67.1.0.tar.gz", hash = "sha256:e261cdf010c11a41cb5cb5f1bf3338a7433832029f559a6a7614bd42a967c300"}, +] + +[package.extras] +docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-hoverxref (<2)", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (==0.8.3)", "sphinx-reredirects", "sphinxcontrib-towncrier"] +testing = ["build[virtualenv]", "filelock (>=3.4.0)", "flake8 (<5)", "flake8-2020", "ini2toml[lite] (>=0.9)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pip (>=19.1)", "pip-run (>=8.8)", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)", "pytest-perf", "pytest-timeout", "pytest-xdist", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel"] +testing-integration = ["build[virtualenv]", "filelock (>=3.4.0)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "pytest", "pytest-enabler", "pytest-xdist", "tomli", "virtualenv (>=13.0.0)", "wheel"] + [[package]] name = "six" version = "1.16.0" @@ -1042,6 +1207,27 @@ brotli = ["brotli (>=1.0.9)", "brotlicffi (>=0.8.0)", "brotlipy (>=0.6.0)"] secure = ["certifi", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "ipaddress", "pyOpenSSL (>=0.14)", "urllib3-secure-extra"] socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] +[[package]] +name = "virtualenv" +version = "20.18.0" +description = "Virtual Python Environment builder" +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "virtualenv-20.18.0-py3-none-any.whl", hash = "sha256:9d61e4ec8d2c0345dab329fb825eb05579043766a4b26a2f66b28948de68c722"}, + {file = "virtualenv-20.18.0.tar.gz", hash = "sha256:f262457a4d7298a6b733b920a196bf8b46c8af15bf1fd9da7142995eff15118e"}, +] + +[package.dependencies] +distlib = ">=0.3.6,<1" +filelock = ">=3.4.1,<4" +platformdirs = ">=2.4,<3" + +[package.extras] +docs = ["furo (>=2022.12.7)", "proselint (>=0.13)", "sphinx (>=6.1.3)", "sphinx-argparse (>=0.4)", "sphinxcontrib-towncrier (>=0.2.1a0)", "towncrier (>=22.12)"] +test = ["covdefaults (>=2.2.2)", "coverage (>=7.1)", "coverage-enable-subprocess (>=1)", "flaky (>=3.7)", "packaging (>=23)", "pytest (>=7.2.1)", "pytest-env (>=0.8.1)", "pytest-freezegun (>=0.4.2)", "pytest-mock (>=3.10)", "pytest-randomly (>=3.12)", "pytest-timeout (>=2.1)"] + [[package]] name = "watchdog" version = "2.2.1" @@ -1116,5 +1302,5 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "2.0" -python-versions = ">=3.8,<3.11" -content-hash = "7bcdbe779427367e99675b94957fdf776e9108c3d4e14f9949f53f8ae457c808" +python-versions = ">=3.8.1,<3.11" +content-hash = "cdc969b22702f7a59977de2708323d24764976d63ad003c12deaaea5383c147d" diff --git a/pyproject.toml b/pyproject.toml index 405ba45..f3713e0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ description = 'A MkDocs plugin that lets you exclude/include docs files using gl authors = ["Dariusz Porowski"] homepage = "https://github.com/DariuszPorowski/mkdocs-file-filter-plugin" repository = "https://github.com/DariuszPorowski/mkdocs-file-filter-plugin" -documentation = "https://github.com/DariuszPorowski/mkdocs-file-filter-plugin/blob/main/README.md" +documentation = "https://dariusz.porowski.dev/mkdocs-file-filter-plugin" readme = "README.md" license = "MIT" keywords = ["mkdocs", "plugin", "exclude", "include", "glob", "regex", "gitignore", "markdown", "frontmatter", "metadata", "tags"] @@ -16,7 +16,6 @@ classifiers = [ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3 :: Only", "Operating System :: OS Independent", "License :: OSI Approved :: MIT License", @@ -34,14 +33,14 @@ History = "https://github.com/DariuszPorowski/mkdocs-file-filter-plugin/releases file-filter = "mkdocs_file_filter_plugin.plugin:FileFilter" [tool.poetry.dependencies] -python = ">=3.8,<3.11" +python = ">=3.8.1,<3.11" mkdocs = "^1.4.0" igittigitt = "^2.1.2" pyyaml = "^6.0" schema = "^0.7.5" pyyaml-env-tag = "^0.1" -[tool.poetry.dev-dependencies] +[tool.poetry.group.dev.dependencies] mkdocs-material="^9.0.11" mkdocs-awesome-pages-plugin="^2.8.0" mkdocs-monorepo-plugin="^1.0.4" @@ -49,6 +48,9 @@ mkdocs-literate-nav = "^0.6.0" pytest = "^7.2.1" autopep8 = "^2.0.1" black = "^23.1.0" +pre-commit = "^3.0.4" +isort = "^5.12.0" +flake8 = "^6.0.0" [build-system] requires = ["poetry-core"]