properness

This commit is contained in:
2018-07-03 18:31:23 -04:00
parent a31f3427a0
commit 86f3dfdf0e
+52 -58
View File
@@ -144,7 +144,7 @@ def load_dot_env():
)
if os.path.isfile(denv):
click.echo(
crayons.normal("Loading .env environment variables...", bold=True),
crayons.normal("Loading .env environment variables", bold=True),
err=True,
)
dotenv.load_dotenv(denv, override=True)
@@ -211,7 +211,7 @@ def import_requirements(r=None, dev=False):
def ensure_environment():
# Skip this on Windows...
# Skip this on Windows
if os.name != "nt":
if "LANG" not in os.environ:
click.echo(
@@ -258,15 +258,15 @@ def ensure_pipfile(validate=True, skip_requirements=False, system=False):
err=True,
)
sys.exit(1)
# If there's a requirements file, but no Pipfile...
# If there's a requirements file, but no Pipfile
if project.requirements_exists and not skip_requirements:
click.echo(
crayons.normal(
u"requirements.txt found, instead of Pipfile! Converting...",
u"requirements.txt found, instead of Pipfile! Converting",
bold=True,
)
)
# Create a Pipfile...
# Create a Pipfile
project.create_pipfile(python=python)
with spinner():
# Import requirements.txt.
@@ -284,7 +284,7 @@ def ensure_pipfile(validate=True, skip_requirements=False, system=False):
)
else:
click.echo(
crayons.normal(u"Creating a Pipfile for this project...", bold=True),
crayons.normal(u"Creating a Pipfile for this project", bold=True),
err=True,
)
# Create the pipfile if it doesn't exist.
@@ -297,8 +297,7 @@ def ensure_pipfile(validate=True, skip_requirements=False, system=False):
# Write changes out to disk.
if changed:
click.echo(
crayons.normal(u"Fixing package names in Pipfile...", bold=True),
err=True,
crayons.normal(u"Fixing package names in Pipfile", bold=True), err=True
)
project.write_toml(p)
@@ -440,7 +439,7 @@ def ensure_python(three=None, python=None):
u"{0}: Python {1} {2}".format(
crayons.red("Warning", bold=True),
crayons.blue(python),
u"was not found on your system...",
u"was not found on your system",
),
err=True,
)
@@ -476,7 +475,7 @@ def ensure_python(three=None, python=None):
crayons.green("CPython {0}".format(version)),
"with pyenv?",
)
# Prompt the user to continue...
# Prompt the user to continue
if not (PIPENV_YES or click.confirm(s, default=True)):
abort()
else:
@@ -487,7 +486,7 @@ def ensure_python(three=None, python=None):
crayons.green(u"CPython {0}".format(version), bold=True),
crayons.normal(u"with pyenv", bold=True),
crayons.normal(u"(this may take a few minutes)"),
crayons.normal(u"...", bold=True),
crayons.normal(u"", bold=True),
)
)
with spinner():
@@ -497,14 +496,14 @@ def ensure_python(three=None, python=None):
timeout=PIPENV_INSTALL_TIMEOUT,
block=False,
)
# Wait until the process has finished...
# Wait until the process has finished
c.block()
try:
assert c.return_code == 0
except AssertionError:
click.echo(u"Something went wrong...")
click.echo(u"Something went wrong")
click.echo(crayons.blue(c.err), err=True)
# Print the results, in a beautiful blue...
# Print the results, in a beautiful blue
click.echo(crayons.blue(c.out), err=True)
# Add new paths to PATH.
activate_pyenv()
@@ -544,7 +543,7 @@ def ensure_virtualenv(three=None, python=None, site_packages=False, pypi_mirror=
if PIPENV_USE_SYSTEM:
click.echo(
crayons.red(
"You are attempting to re-create a virtualenv that "
"You are attempting to recreate a virtualenv that "
"Pipenv did not create. Aborting."
)
)
@@ -556,7 +555,7 @@ def ensure_virtualenv(three=None, python=None, site_packages=False, pypi_mirror=
# If interrupted, cleanup the virtualenv.
cleanup_virtualenv(bare=False)
sys.exit(1)
# If --three, --two, or --python were passed...
# If --three, --two, or --python were passed
elif (python) or (three is not None) or (site_packages is not False):
USING_DEFAULT_PYTHON = False
# Ensure python is installed before deleting existing virtual env
@@ -571,7 +570,7 @@ def ensure_virtualenv(three=None, python=None, site_packages=False, pypi_mirror=
):
abort()
click.echo(
crayons.normal(u"Removing existing virtualenv...", bold=True), err=True
crayons.normal(u"Removing existing virtualenv", bold=True), err=True
)
# Remove the virtualenv.
cleanup_virtualenv(bare=True)
@@ -723,7 +722,7 @@ def do_install_dependencies(
click.echo(crayons.yellow(c.out.strip()))
if verbose:
click.echo(crayons.blue(c.out or c.err))
# The Installation failed...
# The Installation failed
if c.return_code != 0:
# Save the Failed Dependency for later.
failed_deps_list.append((c.dep, c.ignore_hash))
@@ -742,7 +741,7 @@ def do_install_dependencies(
if skip_lock or only or not project.lockfile_exists:
if not bare:
click.echo(
crayons.normal(u"Installing dependencies from Pipfile...", bold=True)
crayons.normal(u"Installing dependencies from Pipfile", bold=True)
)
lockfile = split_file(project._lockfile)
else:
@@ -751,7 +750,7 @@ def do_install_dependencies(
if not bare:
click.echo(
crayons.normal(
u"Installing dependencies from Pipfile.lock ({0})...".format(
u"Installing dependencies from Pipfile.lock ({0})".format(
lockfile["_meta"].get("hash", {}).get("sha256")[-6:]
),
bold=True,
@@ -818,10 +817,10 @@ def do_install_dependencies(
cleanup_procs(procs, concurrent)
procs = []
cleanup_procs(procs, concurrent)
# Iterate over the hopefully-poorly-packaged dependencies...
# Iterate over the hopefully-poorly-packaged dependencies
if failed_deps_list:
click.echo(
crayons.normal(u"Installing initially failed dependencies...", bold=True)
crayons.normal(u"Installing initially failed dependencies", bold=True)
)
for dep, ignore_hash in progress.bar(failed_deps_list, label=INSTALL_LABEL2):
# Use a specific index, if specified.
@@ -838,7 +837,7 @@ def do_install_dependencies(
requirements_dir=requirements_dir,
extra_indexes=extra_indexes,
)
# The Installation failed...
# The Installation failed
if c.return_code != 0:
# We echo both c.out and c.err because pip returns error details on out.
click.echo(crayons.blue(format_pip_output(c.out)))
@@ -873,8 +872,7 @@ def convert_three_to_python(three, python):
def do_create_virtualenv(python=None, site_packages=False, pypi_mirror=None):
"""Creates a virtualenv."""
click.echo(
crayons.normal(u"Creating a virtualenv for this project...", bold=True),
err=True,
crayons.normal(u"Creating a virtualenv for this project", bold=True), err=True
)
click.echo(
u"Pipfile: {0}".format(crayons.red(project.pipfile_location, bold=True)),
@@ -889,7 +887,7 @@ def do_create_virtualenv(python=None, site_packages=False, pypi_mirror=None):
project.virtualenv_location,
"--prompt=({0})".format(project.name),
]
# Pass site-packages flag to virtualenv, if desired...
# Pass site-packages flag to virtualenv, if desired
if site_packages:
cmd.append("--system-site-packages")
else:
@@ -910,7 +908,7 @@ def do_create_virtualenv(python=None, site_packages=False, pypi_mirror=None):
u"{0} {1} {3} {2}".format(
crayons.normal("Using", bold=True),
crayons.red(python, bold=True),
crayons.normal(u"to create virtualenv...", bold=True),
crayons.normal(u"to create virtualenv", bold=True),
crayons.green("({0})".format(python_version(python))),
),
err=True,
@@ -936,10 +934,10 @@ def do_create_virtualenv(python=None, site_packages=False, pypi_mirror=None):
)
sys.exit(1)
click.echo(crayons.blue(c.out), err=True)
# Enable site-packages, if desired...
# Enable site-packages, if desired
if not project.is_venv_in_project() and site_packages:
click.echo(
crayons.normal(u"Making site-packages available...", bold=True), err=True
crayons.normal(u"Making site-packages available", bold=True), err=True
)
os.environ["VIRTUAL_ENV"] = project.virtualenv_location
delegator.run("pipenv run pewtwo toggleglobalsitepackages")
@@ -1053,7 +1051,7 @@ def do_lock(
u"{0} {1} {2}".format(
crayons.normal("Locking"),
crayons.red("[{0}]".format(settings["log_string"])),
crayons.normal("dependencies..."),
crayons.normal("dependencies…"),
),
err=True,
)
@@ -1120,7 +1118,7 @@ def do_lock(
vcs_lockfile.update(dep_lockfile)
lockfile[settings["lockfile_key"]].update(vcs_lockfile)
# Support for --keep-outdated...
# Support for --keep-outdated
if keep_outdated:
for section_name, section in (
("default", project.packages),
@@ -1160,9 +1158,7 @@ def do_purge(bare=False, downloads=False, allow_global=False, verbose=False):
if downloads:
if not bare:
click.echo(
crayons.normal(u"Clearing out downloads directory...", bold=True)
)
click.echo(crayons.normal(u"Clearing out downloads directory…", bold=True))
shutil.rmtree(project.download_location)
return
@@ -1191,9 +1187,7 @@ def do_purge(bare=False, downloads=False, allow_global=False, verbose=False):
actually_installed.append(dep)
if not bare:
click.echo(
u"Found {0} installed package(s), purging...".format(
len(actually_installed)
)
u"Found {0} installed package(s), purging".format(len(actually_installed))
)
command = "{0} uninstall {1} -y".format(
escape_grouped_arguments(which_pip(allow_global=allow_global)),
@@ -1259,9 +1253,9 @@ def do_init(
click.echo(
crayons.red(
u"Pipfile.lock ({0}) out of date, but installation "
u"uses {1}... re-building lockfile must happen in "
u"uses {1} re-building lockfile must happen in "
u"isolation. Please rebuild lockfile in a virtualenv. "
u"Continuing anyway...".format(
u"Continuing anyway".format(
crayons.white(old_hash[-6:]), crayons.white("--system")
),
bold=True,
@@ -1271,7 +1265,7 @@ def do_init(
else:
click.echo(
crayons.red(
u"Pipfile.lock ({0}) out of date, updating to ({1})...".format(
u"Pipfile.lock ({0}) out of date, updating to ({1})".format(
old_hash[-6:], new_hash[-6:]
),
bold=True,
@@ -1302,7 +1296,7 @@ def do_init(
sys.exit(1)
else:
click.echo(
crayons.normal(u"Pipfile.lock not found, creating...", bold=True),
crayons.normal(u"Pipfile.lock not found, creating", bold=True),
err=True,
)
do_lock(
@@ -1376,7 +1370,7 @@ def pip_install(
except (ParseException, ValueError) as e:
click.echo("{0}: {1}".format(crayons.red("WARNING"), e), err=True)
click.echo(
"{0}... You will have to reinstall any packages that failed to install.".format(
"{0} You will have to reinstall any packages that failed to install.".format(
crayons.red("ABORTING INSTALL")
),
err=True,
@@ -1511,7 +1505,7 @@ def system_which(command, mult=False):
_which = "which -a" if not os.name == "nt" else "where"
c = delegator.run("{0} {1}".format(_which, command))
try:
# Which Not found...
# Which Not found
if c.return_code == 127:
click.echo(
"{}: the {} system utility is required for Pipenv to find Python installations properly."
@@ -1650,7 +1644,7 @@ def ensure_lockfile(keep_outdated=False, pypi_mirror=None):
if new_hash != old_hash:
click.echo(
crayons.red(
u"Pipfile.lock ({0}) out of date, updating to ({1})...".format(
u"Pipfile.lock ({0}) out of date, updating to ({1})".format(
old_hash[-6:], new_hash[-6:]
),
bold=True,
@@ -1778,7 +1772,7 @@ def do_install(
# Download requirements file
click.echo(
crayons.normal(
u"Remote requirements file provided! Downloading...", bold=True
u"Remote requirements file provided! Downloading", bold=True
),
err=True,
)
@@ -1802,7 +1796,7 @@ def do_install(
error, traceback = None, None
click.echo(
crayons.normal(
u"Requirements file provided! Importing into Pipfile...", bold=True
u"Requirements file provided! Importing into Pipfile", bold=True
),
err=True,
)
@@ -1834,7 +1828,7 @@ def do_install(
sys.exit(1)
if code:
click.echo(
crayons.normal(u"Discovering imports from local codebase...", bold=True)
crayons.normal(u"Discovering imports from local codebase", bold=True)
)
for req in import_from_code(code):
click.echo(" Found {0}!".format(crayons.green(req)))
@@ -1931,7 +1925,7 @@ def do_install(
for package_name in package_names:
click.echo(
crayons.normal(
u"Installing {0}...".format(crayons.green(package_name, bold=True)),
u"Installing {0}".format(crayons.green(package_name, bold=True)),
bold=True,
)
)
@@ -1995,7 +1989,7 @@ def do_install(
crayons.green(package_name, bold=True),
crayons.normal("to Pipfile's", bold=True),
crayons.red("[dev-packages]" if dev else "[packages]", bold=True),
crayons.normal("...", bold=True),
crayons.normal("", bold=True),
)
)
# Add the package to the Pipfile.
@@ -2049,7 +2043,7 @@ def do_uninstall(
# Un-install all dependencies, if --all was provided.
if all is True:
click.echo(
crayons.normal(u"Un-installing all packages from virtualenv...", bold=True)
crayons.normal(u"Un-installing all packages from virtualenv", bold=True)
)
do_purge(allow_global=system, verbose=verbose)
sys.exit(0)
@@ -2065,7 +2059,7 @@ def do_uninstall(
sys.exit(0)
click.echo(
crayons.normal(
u"Un-installing {0}...".format(crayons.red("[dev-packages]")), bold=True
u"Un-installing {0}".format(crayons.red("[dev-packages]")), bold=True
)
)
package_names = project.dev_packages.keys()
@@ -2073,7 +2067,7 @@ def do_uninstall(
click.echo(crayons.red("No package provided!"), err=True)
sys.exit(1)
for package_name in package_names:
click.echo(u"Un-installing {0}...".format(crayons.green(package_name)))
click.echo(u"Un-installing {0}".format(crayons.green(package_name)))
cmd = "{0} uninstall {1} -y".format(
escape_grouped_arguments(which_pip(allow_global=system)), package_name
)
@@ -2095,7 +2089,7 @@ def do_uninstall(
continue
click.echo(
u"Removing {0} from Pipfile...".format(crayons.green(package_name))
u"Removing {0} from Pipfile".format(crayons.green(package_name))
)
# Remove package from both packages and dev-packages.
project.remove_package_from_pipfile(package_name, dev=True)
@@ -2141,7 +2135,7 @@ def inline_activate_virtualenv():
if not activate_this or not os.path.exists(activate_this):
click.echo(
u"{0}: activate_this.py not found. Your environment is most "
u"certainly not activated. Continuing anyway..."
u"certainly not activated. Continuing anyway"
u"".format(crayons.red("Warning", bold=True)),
err=True,
)
@@ -2152,7 +2146,7 @@ def inline_activate_virtualenv():
# Catch all errors, just in case.
except Exception:
click.echo(
u"{0}: There was an unexpected error while activating your virtualenv. Continuing anyway..."
u"{0}: There was an unexpected error while activating your virtualenv. Continuing anyway"
"".format(crayons.red("Warning", bold=True)),
err=True,
)
@@ -2261,7 +2255,7 @@ def do_check(
sys.exit(1)
else:
sys.exit(0)
click.echo(crayons.normal(u"Checking PEP 508 requirements...", bold=True))
click.echo(crayons.normal(u"Checking PEP 508 requirements", bold=True))
if system:
python = system_which("python")
else:
@@ -2297,7 +2291,7 @@ def do_check(
sys.exit(1)
else:
click.echo(crayons.green("Passed!"))
click.echo(crayons.normal(u"Checking installed package safety...", bold=True))
click.echo(crayons.normal(u"Checking installed package safety", bold=True))
path = pep508checker.__file__.rstrip("cdo")
path = os.sep.join(__file__.split(os.sep)[:-1] + ["patched", "safety.zip"])
if not system:
@@ -2558,7 +2552,7 @@ def do_clean(
else:
click.echo(
crayons.white(
"Uninstalling {0}...".format(repr(apparent_bad_package)), bold=True
"Uninstalling {0}".format(repr(apparent_bad_package)), bold=True
)
)
# Uninstall the package.