File size: 871 Bytes
db5855f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import sys, os
import subprocess  # nosec - disable B404:import-subprocess check
from pathlib import Path

spellcheck_dir = Path(__file__).parent

spellcheck_config_filename = ".pyspelling.yml"

# Add spellcheck directory to PYTHONPATH to use custom PySpelling Plugin for Jupyter Notebooks
PYTHONPATH = ":".join([os.environ.get("PYTHONPATH") or "", str(spellcheck_dir)])

# Run PySpelling tool
result = subprocess.run(
    args=["pyspelling", "--config", f"{spellcheck_dir / spellcheck_config_filename}"],
    universal_newlines=True,
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    env=dict(os.environ, PYTHONPATH=PYTHONPATH),
)

result_output = result.stdout.strip("\n") if result.stdout else result.stderr.strip("\n")

print(result_output, file=sys.stderr if result.returncode else sys.stdout, flush=True)

exit(result.returncode)