Compare commits
No commits in common. "main" and "v0.1.1" have entirely different histories.
@ -1 +1 @@
|
|||||||
__version__ = "0.1.4"
|
__version__ = "0.1.1"
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import click
|
|
||||||
import restructuredtext_lint
|
import restructuredtext_lint
|
||||||
from docutils.parsers.rst.directives import register_directive
|
|
||||||
from git import Repo
|
from git import Repo
|
||||||
|
|
||||||
formatter = logging.Formatter("%(name)s :: %(levelname)s :: %(message)s")
|
formatter = logging.Formatter("%(name)s :: %(levelname)s :: %(message)s")
|
||||||
@ -40,20 +39,12 @@ def select_by_extension(files, ext="rst"):
|
|||||||
# Rst linter
|
# Rst linter
|
||||||
|
|
||||||
|
|
||||||
def rst_lint(filename, ignore_directives=["big_button"]):
|
def rst_lint(filename):
|
||||||
with open(filename, "r") as f:
|
with open(filename, "r") as f:
|
||||||
errors = restructuredtext_lint.lint(f.read())
|
errors = restructuredtext_lint.lint(f.read())
|
||||||
filtered_errors = []
|
|
||||||
for e in errors:
|
for e in errors:
|
||||||
if "directive" in e.message and any(
|
logger.warning(f"{filename} \n{e.full_message}\n")
|
||||||
[i in e.message for i in ignore_directives]
|
return errors
|
||||||
):
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
logger.warning(f"{filename} \n{e.full_message}\n")
|
|
||||||
filtered_errors.append(e)
|
|
||||||
|
|
||||||
return filtered_errors
|
|
||||||
|
|
||||||
|
|
||||||
# Rst parameters normalize
|
# Rst parameters normalize
|
||||||
@ -124,10 +115,7 @@ NORMALIZERS_NEW = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
def main(argv: list[str] = None) -> int:
|
||||||
@click.argument("commited_files", nargs=-1)
|
|
||||||
def main(commited_files: list) -> int:
|
|
||||||
|
|
||||||
r = Repo()
|
r = Repo()
|
||||||
diff = get_commited_files(r)
|
diff = get_commited_files(r)
|
||||||
|
|
||||||
@ -136,10 +124,14 @@ def main(commited_files: list) -> int:
|
|||||||
|
|
||||||
# New files
|
# New files
|
||||||
for f in select_by_extension(diff["A"], "rst"):
|
for f in select_by_extension(diff["A"], "rst"):
|
||||||
|
errors += rst_lint(f)
|
||||||
modified += normalize_file(f, NORMALIZERS_NEW)
|
modified += normalize_file(f, NORMALIZERS_NEW)
|
||||||
|
r.index.add([f])
|
||||||
# Modified files
|
# Modified files
|
||||||
for f in select_by_extension(diff["M"], "rst"):
|
for f in select_by_extension(diff["M"], "rst"):
|
||||||
|
errors += rst_lint(f)
|
||||||
modified += normalize_file(f, NORMALIZERS_MODIFIED)
|
modified += normalize_file(f, NORMALIZERS_MODIFIED)
|
||||||
|
r.index.add([f])
|
||||||
|
|
||||||
return int(len(errors) > 0)
|
return int(len(errors) > 0)
|
||||||
|
|
||||||
|
19
poetry.lock
generated
19
poetry.lock
generated
@ -28,22 +28,11 @@ category = "dev"
|
|||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.6.1"
|
python-versions = ">=3.6.1"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "click"
|
|
||||||
version = "8.1.3"
|
|
||||||
description = "Composable command line interface toolkit"
|
|
||||||
category = "main"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.7"
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
colorama = {version = "*", markers = "platform_system == \"Windows\""}
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "colorama"
|
name = "colorama"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
description = "Cross-platform colored terminal text."
|
description = "Cross-platform colored terminal text."
|
||||||
category = "main"
|
category = "dev"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||||
|
|
||||||
@ -278,7 +267,7 @@ python-versions = "*"
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.10"
|
python-versions = "^3.10"
|
||||||
content-hash = "53a66536a5ce62f85d18096d9d1d6586fd4438774cc7f2136391de830081e51c"
|
content-hash = "f42f1e61719183591304472b3ed90dfbd50fb6ff8ecbd502c7c23c0cd85ce935"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
atomicwrites = [
|
atomicwrites = [
|
||||||
@ -292,10 +281,6 @@ cfgv = [
|
|||||||
{file = "cfgv-3.3.1-py2.py3-none-any.whl", hash = "sha256:c6a0883f3917a037485059700b9e75da2464e6c27051014ad85ba6aaa5884426"},
|
{file = "cfgv-3.3.1-py2.py3-none-any.whl", hash = "sha256:c6a0883f3917a037485059700b9e75da2464e6c27051014ad85ba6aaa5884426"},
|
||||||
{file = "cfgv-3.3.1.tar.gz", hash = "sha256:f5a830efb9ce7a445376bb66ec94c638a9787422f96264c98edc6bdeed8ab736"},
|
{file = "cfgv-3.3.1.tar.gz", hash = "sha256:f5a830efb9ce7a445376bb66ec94c638a9787422f96264c98edc6bdeed8ab736"},
|
||||||
]
|
]
|
||||||
click = [
|
|
||||||
{file = "click-8.1.3-py3-none-any.whl", hash = "sha256:bb4d8133cb15a609f44e8213d9b391b0809795062913b383c62be0ee95b1db48"},
|
|
||||||
{file = "click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"},
|
|
||||||
]
|
|
||||||
colorama = [
|
colorama = [
|
||||||
{file = "colorama-0.4.5-py2.py3-none-any.whl", hash = "sha256:854bf444933e37f5824ae7bfc1e98d5bce2ebe4160d46b5edf346a89358e99da"},
|
{file = "colorama-0.4.5-py2.py3-none-any.whl", hash = "sha256:854bf444933e37f5824ae7bfc1e98d5bce2ebe4160d46b5edf346a89358e99da"},
|
||||||
{file = "colorama-0.4.5.tar.gz", hash = "sha256:e6c6b4334fc50988a639d9b98aa429a0b57da6e17b9a44f0451f930b6967b7a4"},
|
{file = "colorama-0.4.5.tar.gz", hash = "sha256:e6c6b4334fc50988a639d9b98aa429a0b57da6e17b9a44f0451f930b6967b7a4"},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "clean-rst"
|
name = "clean-rst"
|
||||||
version = "0.1.4"
|
version = "0.1.1"
|
||||||
description = "pre-commit to clean rst index files"
|
description = "pre-commit to clean rst index files"
|
||||||
authors = ["Bertrand Benjamin <benjamin.bertrand@opytex.org>"]
|
authors = ["Bertrand Benjamin <benjamin.bertrand@opytex.org>"]
|
||||||
|
|
||||||
@ -11,7 +11,6 @@ clean-rst = "clean_rst.main:main"
|
|||||||
python = "^3.10"
|
python = "^3.10"
|
||||||
restructuredtext-lint = "^1.4.0"
|
restructuredtext-lint = "^1.4.0"
|
||||||
GitPython = "^3.1.27"
|
GitPython = "^3.1.27"
|
||||||
click = "^8.1.3"
|
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
pytest = "^5.2"
|
pytest = "^5.2"
|
||||||
|
@ -2,4 +2,4 @@ from clean_rst import __version__
|
|||||||
|
|
||||||
|
|
||||||
def test_version():
|
def test_version():
|
||||||
assert __version__ == "0.1.4"
|
assert __version__ == "0.1.1"
|
||||||
|
Loading…
Reference in New Issue
Block a user