Skip to content

Commit

Permalink
fix: Run pre-commit before docker-build, check if not installed, add …
Browse files Browse the repository at this point in the history
…quit for confirm
  • Loading branch information
achillesrasquinha committed Feb 7, 2019
1 parent a8e0dbd commit b372e95
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -3,7 +3,7 @@ LABEL maintainer=achillesrasquinha@gmail.com

ENV PIPUPGRADEPATH=/usr/local/src/pipupgrade

RUN apk add --no-cache bash
RUN apk add --no-cache bash git

RUN mkdir -p $PIPUPGRADEPATH

Expand Down
8 changes: 6 additions & 2 deletions Makefile
Expand Up @@ -23,6 +23,7 @@ TOX = ${VENVBIN}/tox
COVERALLS = ${VENVBIN}/coveralls
IPYTHON = ${VENVBIN}/ipython
SAFETY = ${VENVBIN}/safety
PRECOMMIT = ${VENVBIN}/pre-commit

JOBS ?= $(shell $(PYTHON) -c "import multiprocessing as mp; print(mp.cpu_count())")
PYTHON_ENVIRONMENT = $(shell $(PYTHON) -c "import sys;v=sys.version_info;print('py%s%s'%(v.major,v.minor))")
Expand Down Expand Up @@ -133,10 +134,13 @@ shell: ## Launch an IPython shell.
$(IPYTHON) \
--no-banner

build: clean ## Build the Distribution.
build: clean ## Build the Distribution.
$(PYTHON) setup.py sdist bdist_wheel

docker-build: clean ## Build the Docker Image.
pre-commit: ## Perform Pre-Commit Tasks.
$(PRECOMMIT) run

docker-build: clean pre-commit ## Build the Docker Image.
$(call log,INFO,Building Docker Image)

@docker build $(BASEDIR) --tag $(DOCKER_HUB_USERNAME)/$(PROJECT)
Expand Down
17 changes: 12 additions & 5 deletions src/pipupgrade/cli/__init__.py
Expand Up @@ -3,13 +3,15 @@
from pipupgrade._compat import input

# imports - standard imports
import sys
import inspect

# imports - module imports
from pipupgrade.cli.parser import get_args
from pipupgrade.util.types import merge_dict, get_function_arguments

_ACCEPTABLE_YES_INPUTS = ("", "y", "Y")
_ACCEPTABLE_INPUTS_YES = ("", "y", "Y")
_ACCEPTABLE_INPUTS_QUIT = ("q", "Q")

_ANSI_FORMAT = "\033[{}m"
_format_ansi = lambda x: _ANSI_FORMAT.format(x)
Expand All @@ -21,11 +23,16 @@
CYAN = _format_ansi("0;96")
CLEAR = _format_ansi("0")

def confirm(query):
query = "{} [Y/n]: ".format(query)
output = input(query)
def confirm(query, quit_ = False):
choices = "[Y/n%s]" % ("/q" if quit_ else "")
query = "%s %s: " % (query, choices)
output = input(query)

return output in _ACCEPTABLE_YES_INPUTS
if quit_:
if output in _ACCEPTABLE_INPUTS_QUIT:
sys.exit(0)

return output in _ACCEPTABLE_INPUTS_YES

def format(string, type_):
string = "{}{}{}".format(type_, string, CLEAR)
Expand Down
4 changes: 2 additions & 2 deletions src/pipupgrade/commands/__init__.py
Expand Up @@ -196,7 +196,7 @@ def command(

table.insert([
cli_format(package.name, _SEMVER_COLOR_MAP.get(diff_type, cli.CLEAR)),
package.current_version,
package.current_version or "na",
_cli_format_semver(package.latest_version, diff_type),
cli_format(package.home_page, cli.CYAN)
])
Expand Down Expand Up @@ -226,7 +226,7 @@ def command(
spackages = pluralize("package", npackages) # Packages "string"
query = "Do you wish to update %s %s?" % (npackages, spackages)

if npackages and (yes or interactive or cli.confirm(query)):
if npackages and (yes or interactive or cli.confirm(query, quit_ = True)):
for i, package in enumerate(packages):
update = True

Expand Down

0 comments on commit b372e95

Please sign in to comment.