Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add spinner during locking #2993

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2993.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enhanced CI detection to detect Azure Devops builds.
1 change: 1 addition & 0 deletions news/2993.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added a new spinner during ``pipenv lock`` to indicate that pipenv is still actively running.
11 changes: 5 additions & 6 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,7 @@ def pip_install(
trusted_hosts=None
):
from notpip._internal import logger as piplogger
from .vendor.urllib3.util import parse_url

src = []
if not trusted_hosts:
Expand Down Expand Up @@ -1344,7 +1345,8 @@ def pip_install(
index_source = index_source.copy()
except SourceNotFound:
src_name = project.src_name_from_url(index)
verify_ssl = True if index not in trusted_hosts else False
index_url = parse_url(index)
verify_ssl = True if index_url.host not in trusted_hosts else False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the following form is enough:

verify_ssl = index_url.host not in trusted_hosts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it is! thanks for the feedback :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bigger fish to fry on this one -- VCS installs are throwing permissions errors :(

index_source = {"url": index, "verify_ssl": verify_ssl, "name": src_name}
sources = [index_source.copy(),]
if extra_indexes:
Expand All @@ -1355,7 +1357,8 @@ def pip_install(
extra_src = project.find_source(idx)
except SourceNotFound:
src_name = project.src_name_from_url(idx)
verify_ssl = True if idx not in trusted_hosts else False
src_url = parse_url(idx)
verify_ssl = True if src_url.host not in trusted_hosts else False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verify_ssl = src_url.host not in trusted_hosts

extra_src = {"url": idx, "verify_ssl": verify_ssl, "name": extra_src}
if extra_src["url"] != index_source["url"]:
sources.append(extra_src)
Expand Down Expand Up @@ -1383,10 +1386,6 @@ def pip_install(
with open(r) as f:
if "--hash" not in f.read():
ignore_hashes = True
# trusted_hosts = [
# "--trusted-host={0}".format(source.get("url")) for source in sources
# if not source.get("verify_ssl", True)
# ]
pip_command = [which_pip(allow_global=allow_global), "install"]
if pre:
pip_command.append("--pre")
Expand Down
9 changes: 6 additions & 3 deletions pipenv/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# https://bugs.python.org/issue22490
os.environ.pop("__PYVENV_LAUNCHER__", None)

# Set as a shortcut to check if we are running a CI build
PIPENV_IS_CI = bool(os.environ.get("CI") or os.environ.get("TF_BUILD"))

# Load patched pip instead of system pip
os.environ["PIP_SHIMS_BASE_MODULE"] = fs_str("pipenv.patched.notpip")

Expand Down Expand Up @@ -68,7 +71,7 @@

Default is to show emojis. This is automatically set on Windows.
"""
if os.name == "nt":
if os.name == "nt" or PIPENV_IS_CI:
PIPENV_HIDE_EMOJIS = True

PIPENV_IGNORE_VIRTUALENVS = bool(os.environ.get("PIPENV_IGNORE_VIRTUALENVS"))
Expand All @@ -94,7 +97,7 @@

PIPENV_MAX_RETRIES = int(os.environ.get(
"PIPENV_MAX_RETRIES",
"1" if "CI" in os.environ else "0",
"1" if PIPENV_IS_CI else "0",
))
"""Specify how many retries Pipenv should attempt for network requests.

Expand Down Expand Up @@ -128,7 +131,7 @@
This can make the logs cleaner. Automatically set on Windows, and in CI
environments.
"""
if os.name == "nt" or "CI" in os.environ:
if os.name == "nt" or PIPENV_IS_CI:
PIPENV_NOSPIN = True

PIPENV_PIPFILE = os.environ.get("PIPENV_PIPFILE")
Expand Down
7 changes: 3 additions & 4 deletions pipenv/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def resolve(packages, pre, project, sources, clear, system):
if pypi_mirror_source
else project.pipfile_sources
)
print("using sources: %s" % sources)
results = resolve(
packages,
pre=do_pre,
Expand All @@ -89,11 +88,11 @@ def resolve(packages, pre, project, sources, clear, system):
clear=do_clear,
system=system,
)
print("RESULTS:")
sys.stdout.write("RESULTS:")
if results:
print(json.dumps(results))
sys.stdout.writelines(json.dumps(results))
else:
print(json.dumps([]))
sys.stdout.write(json.dumps([]))


if __name__ == "__main__":
Expand Down
41 changes: 22 additions & 19 deletions pipenv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,41 +343,44 @@ def venv_resolve_deps(
allow_global=False,
pypi_mirror=None,
):
from .vendor.vistir.misc import fs_str
from .vendor import delegator
from .vendor.vistir.misc import run, to_text
from .vendor.vistir.compat import Path
from . import resolver
import json

if not deps:
return []
resolver = escape_grouped_arguments(resolver.__file__.rstrip("co"))
cmd = "{0} {1} {2} {3} {4}".format(
escape_grouped_arguments(which("python", allow_global=allow_global)),
resolver,
"--pre" if pre else "",
"--clear" if clear else "",
"--system" if allow_global else "",
)
python_path = which("python", allow_global=allow_global)
resolver = Path(resolver.__file__.rstrip("co")).as_posix()
cmd = [Path(python_path).as_posix(), resolver]
if pre:
cmd.append("--pre")
if clear:
cmd.append("--clear")
if allow_global:
cmd.append("--system")
with temp_environ():
os.environ = {fs_str(k): fs_str(val) for k, val in os.environ.items()}
os.environ["PIP_SHIMS_BASE_MODULE"] = fs_str("pipenv.patched.notpip")
os.environ["PIPENV_PACKAGES"] = str("\n".join(deps))
if pypi_mirror:
os.environ["PIPENV_PYPI_MIRROR"] = str(pypi_mirror)
os.environ["PIPENV_VERBOSITY"] = str(environments.PIPENV_VERBOSITY)
c = delegator.run(cmd, block=True)
os.environ["PIPENV_PYPI_MIRROR"] = fs_str(pypi_mirror)
os.environ["PIPENV_VERBOSITY"] = fs_str(str(environments.PIPENV_VERBOSITY))
c = run(cmd, block=False, return_object=True, env=os.environ.copy(),
nospin=environments.PIPENV_NOSPIN, verbose=environments.is_verbose())
try:
assert c.return_code == 0
assert c.returncode == 0
except AssertionError:
if environments.is_verbose():
click_echo(c.out, err=True)
click_echo(c.err, err=True)
click_echo(to_text(c.out), err=True)
click_echo(to_text(c.err), err=True)
else:
click_echo(c.err[(int(len(c.err) / 2) - 1):], err=True)
sys.exit(c.return_code)
sys.exit(c.returncode)
if environments.is_verbose():
click_echo(c.out.split("RESULTS:")[0], err=True)
click_echo(to_text(c.out.split("RESULTS:")[0]), err=True)
try:
return json.loads(c.out.split("RESULTS:")[1].strip())
return json.loads(to_text(c.out.split("RESULTS:")[1].strip()))

except IndexError:
raise RuntimeError("There was a problem with locking.")
Expand Down
2 changes: 1 addition & 1 deletion pipenv/vendor/vistir/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def run(
)
else:
spinner = yaspin
animation = spinners.Spinners.bouncingBar
animation = spinners.Spinners.dots
else:

@contextmanager
Expand Down
13 changes: 13 additions & 0 deletions tasks/vendoring/patches/vendor/vistir-spinner.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/pipenv/vendor/vistir/misc.py b/pipenv/vendor/vistir/misc.py
index 723bb117..a18717f4 100644
--- a/pipenv/vendor/vistir/misc.py
+++ b/pipenv/vendor/vistir/misc.py
@@ -206,7 +206,7 @@ def run(
)
else:
spinner = yaspin
- animation = spinners.Spinners.bouncingBar
+ animation = spinners.Spinners.dots
else:

@contextmanager