[virt-tools-list] [virt-manager] [PATCH 1/2] setup: Integrate codespell

Radostin Stoyanov rstoyanov1 at gmail.com
Mon May 21 19:42:49 UTC 2018


Codespell is a tool for checking misspelled words in source code [1].
Integrating this tool will enable automated spell check of the code
base.

Usage example:
        ./setup.py codespell

[1] https://github.com/codespell-project/codespell

Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
---
 HACKING.md               |  8 ++++++--
 setup.py                 | 27 +++++++++++++++++++++++++++
 tests/codespell_dict.txt |  2 ++
 3 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 tests/codespell_dict.txt

diff --git a/HACKING.md b/HACKING.md
index b28ec075..771f20f9 100644
--- a/HACKING.md
+++ b/HACKING.md
@@ -4,10 +4,14 @@ The following commands will be useful for anyone writing patches:
 ```sh
 ./setup.py test      # Run local unit test suite
 ./setup.py pylint    # Run a pylint script against the codebase
+./setup.py codespell # Run a codespell script against the codebase
 ```
 
-Any patches shouldn't change the output of 'test' or 'pylint'. The
-'pylint' requires `pylint` and `pycodestyle` to be installed.
+Any patches shouldn't change the output of 'test', 'pylint' or 'codespell'. The
+'pylint' requires [`pylint`](https://github.com/PyCQA/pylint) and
+[`pycodestyle`](https://github.com/pycqa/pycodestyle) to be installed. The
+'codespell' requires
+[`codespell`](https://github.com/codespell-project/codespell) to be installed.
 
 Our pylint script uses a blacklist rather than a whitelist approach,
 so it could throw some false positives or useless messages. If you think
diff --git a/setup.py b/setup.py
index 50f97f07..17167e27 100755
--- a/setup.py
+++ b/setup.py
@@ -570,6 +570,32 @@ class TestDist(TestBaseCommand):
         TestBaseCommand.run(self)
 
 
+class CheckSpell(distutils.core.Command):
+    user_options = []
+    description = "Check code for common misspellings"
+
+    def initialize_options(self):
+        pass
+
+    def finalize_options(self):
+        pass
+
+    def run(self):
+        try:
+            import codespell_lib
+        except ImportError:
+            raise ImportError('codespell is not installed')
+
+        files = ["setup.py", "virt-install", "virt-clone",
+                 "virt-convert", "virt-xml", "virt-manager",
+                 "virtcli", "virtinst", "virtconv", "virtManager",
+                 "tests"]
+        # pylint: disable=protected-access
+        codespell_lib._codespell.main(
+            '-I', 'tests/codespell_dict.txt',
+            '--skip', '*.pyc,*.zip,*.vmdk,*.iso,*.xml', *files)
+
+
 class CheckPylint(distutils.core.Command):
     user_options = [
         ("jobs=", "j", "use multiple processes to speed up Pylint"),
@@ -688,6 +714,7 @@ distutils.core.setup(
         'configure': configure,
 
         'pylint': CheckPylint,
+        'codespell': CheckSpell,
         'rpm': my_rpm,
         'test': TestCommand,
         'test_ui': TestUI,
diff --git a/tests/codespell_dict.txt b/tests/codespell_dict.txt
new file mode 100644
index 00000000..e64d127a
--- /dev/null
+++ b/tests/codespell_dict.txt
@@ -0,0 +1,2 @@
+matchs
+doubleclick
-- 
2.17.0




More information about the virt-tools-list mailing list