Skip to content

Commit

Permalink
Merge 62a5971 into a04e2b1
Browse files Browse the repository at this point in the history
  • Loading branch information
timgates42 committed May 18, 2021
2 parents a04e2b1 + 62a5971 commit 8021cd6
Show file tree
Hide file tree
Showing 28 changed files with 1,719 additions and 207 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -41,6 +41,7 @@ $ pip install meticulous
- colorama
- psycopg2
- ansi2html
- flask


## Download from PyPI.org
Expand Down
3 changes: 1 addition & 2 deletions app/Dockerfile
@@ -1,8 +1,7 @@
ARG PYVER
FROM python:${PYVER}-alpine
FROM python:${PYVER}-slim
ARG PYVER
ENV PYVER=${PYVER}
RUN apk add --no-cache bash
COPY install.sh /build/install.sh
COPY pip /build/pip
RUN /build/install.sh
Expand Down
20 changes: 16 additions & 4 deletions app/install.sh
Expand Up @@ -5,16 +5,28 @@ set -euxo pipefail
BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "${BASEDIR}"

apk add --no-cache \
build-base \
apt update
apt install -y --no-install-recommends \
build-essential \
aspell aspell-en \
hunspell hunspell-en \
hunspell hunspell-en-au \
shellcheck \
git \
libxslt-dev \
libffi-dev \
openssl-dev gcc musl-dev postgresql-dev
libssl-dev musl-dev libpq-dev \
pkg-config \
curl
RUSTUP_HOME=/rust
export RUSTUP_HOME
CARGO_HOME=/cargo
export CARGO_HOME
PATH=/cargo/bin:/rust/bin:$PATH
export PATH
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly --no-modify-path
rustup default nightly

"python${PYVER}" -m pip install -U pip setuptools wheel
cd "${BASEDIR}/pip/${PYVER}"
for reqfile in */requirements.txt ; do
if [ "$(wc -l < "${reqfile}")" -gt 0 ] ; then
Expand Down
10 changes: 5 additions & 5 deletions app/meticulous/_addrepo.py
Expand Up @@ -197,7 +197,7 @@ def spelling_check(repo, target):
"""
repodir = target / repo
jsonpath = repodir / "spelling.json"
procobj = subprocess.Popen( # noqa=S603 # nosec
with subprocess.Popen( # noqa=S603 # nosec
[
sys.executable,
"-m",
Expand All @@ -212,10 +212,10 @@ def spelling_check(repo, target):
stdout=subprocess.PIPE,
stdin=None,
stderr=subprocess.PIPE,
)
stdout, stderr = procobj.communicate()
if procobj.returncode not in (0, 1):
raise Exception(f"Error checking spelling:\n{stderr}\n{stdout}")
) as procobj:
stdout, stderr = procobj.communicate()
if procobj.returncode not in (0, 1):
raise Exception(f"Error checking spelling:\n{stderr}\n{stdout}")
with io.open(jsonpath, "r", encoding="utf-8") as fobj:
jsonobj = json.load(fobj)
jsonobj = update_json_results(repo, jsonobj)
Expand Down
2 changes: 1 addition & 1 deletion app/meticulous/_cleanup.py
Expand Up @@ -18,7 +18,7 @@ def remove_repo_for(repo, repodir, confirm=True):
try:
del repository_map[repo]
set_json_value(name, repository_map)
except KeyError:
except (KeyError, TypeError):
continue
if confirm:
option = make_simple_choice(["Yes", "No"], "Delete the directory?")
Expand Down
8 changes: 8 additions & 0 deletions app/meticulous/_constants.py
@@ -0,0 +1,8 @@
"""
Simple constants to import controlling behaviour
"""

MULTI_SAVE_KEY = "repository_saves_multi"
ALWAYS_BATCH_MODE = True
ALWAYS_ISSUE_AND_BRANCH = True
ALWAYS_PLAIN_PR = True
6 changes: 4 additions & 2 deletions app/meticulous/_input.py
Expand Up @@ -52,11 +52,13 @@ def check_cancel(result):
return result


def get_input(message):
def get_input(message, defaultval=""):
"""
Call PyInquirer/prompt-toolkit to make a simple input
"""
menu = [{"type": "input", "name": "option", "message": message}]
menu = [
{"type": "input", "name": "option", "message": message, "default": defaultval}
]
answers = prompt(menu)
return check_cancel(answers.get("option"))

Expand Down
78 changes: 76 additions & 2 deletions app/meticulous/_multiworker.py
Expand Up @@ -9,8 +9,8 @@
from meticulous._cleanup import remove_repo_for
from meticulous._controller import Controller
from meticulous._input_queue import get_input_queue
from meticulous._processrepo import processrepo_handlers
from meticulous._storage import get_json_value, set_json_value
from meticulous._processrepo import add_repo_save, processrepo_handlers
from meticulous._storage import get_json_value, set_json_value, set_multi_repo
from meticulous._submit import submit_handlers
from meticulous._threadpool import get_pool

Expand Down Expand Up @@ -75,6 +75,7 @@ def cleanup(context):

def handler():
reponame = context.taskjson["reponame"]
set_multi_repo(reponame, [])
repository_map = get_json_value("repository_map", {})
if reponame in repository_map:
reposave = repository_map[reponame]
Expand Down Expand Up @@ -163,6 +164,79 @@ class Interaction:
Base kinds of interaction
"""

# pylint: disable=no-self-use
def add_repo_save(self, repopath, newspell, word, file_paths):
"""
Default Implementation saves immediately rather than storing and
completing later
"""
add_repo_save(str(repopath), newspell, word, file_paths)

def complete_repo(self):
"""
Default implementation does not use as each update is saved immediately
but multi-commit interaction will store up all updates until this point
when repository is complete.
"""

def get_confirmation(self, message="Do you want to continue", defaultval=True):
"""
Simple confirmation
"""
raise NotImplementedError()

def get_input(self, message):
"""
Get arbitrary text input
"""
raise NotImplementedError()

def make_choice(self, choices, message="Please make a selection."):
"""
Get arbitrary choice input
"""
raise NotImplementedError()

def check_quit(self, controller):
"""
Check if time to quit
"""
raise NotImplementedError()

def send(self, message):
"""
Display a message to the user
"""
raise NotImplementedError()


class MultiSubmitInteraction(Interaction):
"""
Extends interaction to add storage of items until the repository is complete
and submits the items together
"""

# pylint: disable=no-self-use
def add_repo_save(self, repopath, newspell, word, file_paths):
"""
Default Implementation saves immediately rather than storing and
completing later
"""
key = "multiitem_submit"
saved_items = get_json_value(key, deflt=[])
saved_items.append(
{
"repopath": str(repopath),
}
)

def complete_repo(self):
"""
Default implementation does not use as each update is saved immediately
but multi-commit interaction will store up all updates until this point
when repository is complete.
"""

def get_confirmation(self, message="Do you want to continue", defaultval=True):
"""
Simple confirmation
Expand Down
11 changes: 8 additions & 3 deletions app/meticulous/_process.py
Expand Up @@ -17,14 +17,15 @@

from meticulous._addrepo import interactive_add_one_new_repo, spelling_check
from meticulous._cleanup import remove_repo_for
from meticulous._constants import ALWAYS_BATCH_MODE
from meticulous._exceptions import NoRepoException, ProcessingFailed
from meticulous._input import (
UserCancel,
get_confirmation,
make_choice,
make_simple_choice,
)
from meticulous._multiworker import clear_work_queue
from meticulous._multiworker import KeyboardInteraction, clear_work_queue
from meticulous._multiworker import main as multiworker_main
from meticulous._multiworker import show_work_queue
from meticulous._nonword import load_recent_non_words
Expand Down Expand Up @@ -131,7 +132,9 @@ def total_annihilation(target):
if not jsonpath.exists():
print("Checking spelling...")
spelling_check(repodir, target)
interactive_task_collect_nonwords(reponame, target, nonstop=True)
interactive_task_collect_nonwords(
KeyboardInteraction(), reponame, target, nonstop=True
)


def remove_repo_selection(target): # pylint: disable=unused-argument
Expand Down Expand Up @@ -275,7 +278,9 @@ def task_collect_nonwords(obj, eng): # pylint: disable=unused-argument
print(f"Unexpected number of repostories - {count}")
return
reponame = next(iter(repository_list.keys()))
interactive_task_collect_nonwords(reponame, obj.target)
interactive_task_collect_nonwords(
KeyboardInteraction(), reponame, obj.target, nonstop=ALWAYS_BATCH_MODE
)


def task_submit(obj, eng): # pylint: disable=unused-argument
Expand Down

0 comments on commit 8021cd6

Please sign in to comment.