Skip to content

Commit

Permalink
Merge 5b2087d into 8facbe7
Browse files Browse the repository at this point in the history
  • Loading branch information
timgates42 committed Feb 23, 2020
2 parents 8facbe7 + 5b2087d commit 6d8fe46
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -36,6 +36,7 @@ $ pip install meticulous
- PyInquirer
- requests
- workflow
- colorama


## Download from PyPI.org
Expand Down
51 changes: 50 additions & 1 deletion app/meticulous/_process.py
Expand Up @@ -11,6 +11,7 @@
import sys
from pathlib import Path

from colorama import Fore, Style, init
from plumbum import FG, local
from PyInquirer import prompt
from spelling.check import process_results, run_spell_check
Expand Down Expand Up @@ -107,6 +108,7 @@ def run_invocation(target):
if not target.is_dir():
print(f"Target {target} is not a directory.", file=sys.stderr)
sys.exit(1)
init()
prepare()
if get_confirmation("Run automated process"):
automated_process(target)
Expand Down Expand Up @@ -592,12 +594,29 @@ def results_to_json(all_results):
for results in all_results:
if results.words:
for word in results.words:
filename = context_to_filename(results.context)
words.setdefault(word, []).append(
{"category": results.category, "file": results.context}
{"category": results.category, "file": filename}
)
return words


def context_to_filename(name):
"""
Turn a context line into the filepath.
"""
testname = name
if os.path.isfile(testname):
return testname
testname = testname.split(":", 1)[0]
if os.path.isfile(testname):
return testname
testname = testname.rsplit("(", 1)[0]
if os.path.isfile(testname):
return testname
raise Exception(f"Unable to get filepath for {name}")


def test(target): # pylint: disable=unused-argument
"""
Prompt for a organization and repository to test
Expand Down Expand Up @@ -726,6 +745,36 @@ def show_word(word, details): # pylint: disable=unused-argument
Display the word and its context.
"""
print(f"Checking word {word}")
files = sorted(set(context_to_filename(detail["file"]) for detail in details))
for filename in files:
print(f"{filename}:")
with io.open(filename, "r", encoding="utf-8") as fobj:
for line in fobj:
line = line.rstrip("\r\n")
output = get_colourized(line, word)
if output:
print(output)


def get_colourized(line, word):
"""
Highlight the matching word for lines it is found on.
"""
regex = re.compile(f"\\b({re.escape(word)})\\b")
if not regex.search(line):
return None
result = []
pos = 0
for match in regex.finditer(line):
match_start = match.start(1)
match_end = match.end(1)
result.append(line[pos:match_start])
result.append(Fore.YELLOW)
result.append(line[match_start:match_end])
result.append(Style.RESET_ALL)
pos = match_end
result.append(line[pos:])
return "".join(result)


def handle_nonword(word, details): # pylint: disable=unused-argument
Expand Down
1 change: 1 addition & 0 deletions app/pip/3.6/app/requirements.txt
Expand Up @@ -4,3 +4,4 @@ spelling
PyInquirer
requests
workflow
colorama
1 change: 1 addition & 0 deletions app/pip/3.7/app/requirements.txt
Expand Up @@ -4,3 +4,4 @@ spelling
PyInquirer
requests
workflow
colorama
1 change: 1 addition & 0 deletions app/pip/3.8/app/requirements.txt
Expand Up @@ -4,3 +4,4 @@ spelling
PyInquirer
requests
workflow
colorama
1 change: 1 addition & 0 deletions app/requirements.txt
Expand Up @@ -4,3 +4,4 @@ spelling
PyInquirer
requests
workflow
colorama
2 changes: 1 addition & 1 deletion cookiecutter.json
Expand Up @@ -25,7 +25,7 @@
"build_url": "https://dev.azure.com/{{ cookiecutter.azure_user }}/{{ cookiecutter.azure_project }}/_build/latest?definitionId={{ cookiecutter.azure_buildid }}&branchName=master",
"pypi_name": "{{ cookiecutter.project_name }}",
"readthedocs_name": "{{ cookiecutter.project_name }}",
"app_requirements": "PyGithub\nplumbum\nspelling\nPyInquirer\nrequests\nworkflow",
"app_requirements": "PyGithub\nplumbum\nspelling\nPyInquirer\nrequests\nworkflow\ncolorama",
"cov_fail_under": "0",
"travis_status_url": "https://travis-ci.org/{{ cookiecutter.github_org }}/{{ cookiecutter.github_repo }}.svg?branch=master",
"travis_build_url": "https://travis-ci.org/{{ cookiecutter.github_org }}/{{ cookiecutter.github_repo }}",
Expand Down

0 comments on commit 6d8fe46

Please sign in to comment.