Browse Source

Fixed errors in makerst pre-commit hook

(cherry picked from commit 619354fb2c9dd046d37221a3a5041dda47135e3e)
PouleyKetchoupp 5 years ago
parent
commit
d4c77e60c0
2 changed files with 9 additions and 2 deletions
  1. 1 1
      doc/tools/makerst.py
  2. 8 1
      misc/hooks/pre-commit-makerst

+ 1 - 1
doc/tools/makerst.py

@@ -341,7 +341,7 @@ def make_rst_class(class_def, state, dry_run, output_dir):  # type: (ClassDef, S
     class_name = class_def.name
 
     if dry_run:
-        f = open(os.devnull, "w")
+        f = open(os.devnull, "w", encoding="utf-8")
     else:
         f = open(os.path.join(output_dir, "class_" + class_name.lower() + '.rst'), 'w', encoding='utf-8')
 

+ 8 - 1
misc/hooks/pre-commit-makerst

@@ -2,4 +2,11 @@
 
 # Git pre-commit hook that checks the class reference syntax using makerst.py.
 
-doc/tools/makerst.py doc/classes modules --dry-run
+# Workaround because we can't execute the .py file directly on windows
+PYTHON=python
+py_ver=$($PYTHON -c "import sys; print(sys.version_info.major)")
+if [[ "$py_ver" != "3" ]]; then
+  PYTHON+=3
+fi
+
+$PYTHON doc/tools/makerst.py doc/classes modules --dry-run