Remove some more vistir usage (#5067)

* Removed usage of vistir.compat.JSONDecodeError

This is no longer needed since Python version 3.6. Earlier versions
didn't have json.JSONDecodeError and raised ValueError instead.

* Removed vistir.path.rmtree in favour of shutil.rmtree
This commit is contained in:
Oz N Tiram
2022-04-21 18:59:54 +02:00
committed by GitHub
parent 23851d8170
commit f0199ee47c
4 changed files with 20 additions and 26 deletions
+12 -10
View File
@@ -1,6 +1,7 @@
import json as simplejson
import logging
import os
import shutil
import sys
import time
import warnings
@@ -91,11 +92,11 @@ def do_clear(project):
from pip import locations
try:
vistir.path.rmtree(
shutil.rmtree(
project.s.PIPENV_CACHE_DIR, onerror=vistir.path.handle_remove_readonly
)
# Other processes may be writing into this directory simultaneously.
vistir.path.rmtree(
shutil.rmtree(
locations.USER_CACHE_DIR,
ignore_errors=environments.PIPENV_IS_CI,
onerror=vistir.path.handle_remove_readonly,
@@ -148,7 +149,7 @@ def cleanup_virtualenv(project, bare=True):
click.echo(crayons.red("Environment creation aborted."))
try:
# Delete the virtualenv.
vistir.path.rmtree(project.virtualenv_location)
shutil.rmtree(project.virtualenv_location)
except OSError as e:
click.echo(
"{} An error occurred while removing {}!".format(
@@ -1182,7 +1183,7 @@ def do_purge(project, bare=False, downloads=False, allow_global=False):
click.echo(
crayons.normal(fix_utf8("Clearing out downloads directory..."), bold=True)
)
vistir.path.rmtree(project.download_location)
shutil.rmtree(project.download_location)
return
# Remove comments from the output, if any.
@@ -2652,7 +2653,7 @@ def do_check(
quiet=False,
pypi_mirror=None,
):
from pipenv.vendor.vistir.compat import JSONDecodeError
import json
if not system:
# Ensure that virtualenv is available.
@@ -2689,7 +2690,7 @@ def do_check(
if c.returncode is not None:
try:
results = simplejson.loads(c.stdout.strip())
except JSONDecodeError:
except json.JSONDecodeError:
click.echo(
"{}\n{}\n{}".format(
crayons.white(
@@ -2763,7 +2764,7 @@ def do_check(
if output == "default":
try:
results = simplejson.loads(c.stdout)
except (ValueError, JSONDecodeError):
except (ValueError, json.JSONDecodeError):
raise exceptions.JSONParseError(c.stdout, c.stderr)
except Exception:
raise exceptions.PipenvCmdError(
@@ -2791,8 +2792,9 @@ def do_check(
def do_graph(project, bare=False, json=False, json_tree=False, reverse=False):
import json as jsonlib
from pipenv.vendor import pipdeptree
from pipenv.vendor.vistir.compat import JSONDecodeError
pipdeptree_path = pipdeptree.__file__.rstrip("cdo")
try:
@@ -2873,7 +2875,7 @@ def do_graph(project, bare=False, json=False, json_tree=False, reverse=False):
data = []
try:
parsed = simplejson.loads(c.stdout.strip())
except JSONDecodeError:
except jsonlib.JSONDecodeError:
raise exceptions.JSONParseError(c.stdout, c.stderr)
else:
for d in parsed:
@@ -2896,7 +2898,7 @@ def do_graph(project, bare=False, json=False, json_tree=False, reverse=False):
try:
parsed = simplejson.loads(c.stdout.strip())
except JSONDecodeError:
except jsonlib.JSONDecodeError:
raise exceptions.JSONParseError(c.stdout, c.stderr)
else:
data = traverse(parsed)
+2 -3
View File
@@ -300,8 +300,7 @@ class Environment:
:return: The :data:`sys.path` from the environment
:rtype: list
"""
from .vendor.vistir.compat import JSONDecodeError
import json
current_executable = Path(sys.executable).as_posix()
if not self.python or self.python == current_executable:
@@ -319,7 +318,7 @@ class Environment:
)
try:
path = json.loads(path.strip())
except JSONDecodeError:
except json.JSONDecodeError:
path = sys.path
return path
+2 -2
View File
@@ -946,7 +946,7 @@ def venv_resolve_deps(
from pipenv import resolver
from pipenv._compat import decode_for_output
from pipenv.vendor.vistir.compat import JSONDecodeError, NamedTemporaryFile, Path
from pipenv.vendor.vistir.compat import NamedTemporaryFile, Path
results = []
pipfile_section = "dev-packages" if dev else "packages"
@@ -1019,7 +1019,7 @@ def venv_resolve_deps(
try:
with open(target_file.name) as fh:
results = json.load(fh)
except (IndexError, JSONDecodeError):
except (IndexError, json.JSONDecodeError):
click_echo(c.stdout.strip(), err=True)
click_echo(c.stderr.strip(), err=True)
if os.path.exists(target_file.name):
+4 -11
View File
@@ -252,17 +252,10 @@ def is_virtual_environment(path):
def mkdir_p(newdir):
"""works the way a good mkdir should :)
<<<<<<< HEAD
- already exists, silently complete
- regular file in the way, raise an exception
- parent directory(ies) does not exist, make them as well
From: http://code.activestate.com/recipes/82465-a-friendly-mkdir/
=======
- already exists, silently complete
- regular file in the way, raise an exception
- parent directory(ies) does not exist, make them as well
From: http://code.activestate.com/recipes/82465-a-friendly-mkdir/
>>>>>>> main
- already exists, silently complete
- regular file in the way, raise an exception
- parent directory(ies) does not exist, make them as well
From: http://code.activestate.com/recipes/82465-a-friendly-mkdir/
"""
if os.path.isdir(newdir):
pass