From f0199ee47c88559de3ebd5eb7a222b7ae2fa8991 Mon Sep 17 00:00:00 2001 From: Oz N Tiram Date: Thu, 21 Apr 2022 18:59:54 +0200 Subject: [PATCH] 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 --- pipenv/core.py | 22 ++++++++++++---------- pipenv/environment.py | 5 ++--- pipenv/utils/resolver.py | 4 ++-- pipenv/utils/shell.py | 15 ++++----------- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/pipenv/core.py b/pipenv/core.py index 7b2d8433dc..74a79ae066 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -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 traverse(obj): try: parsed = simplejson.loads(c.stdout.strip()) - except JSONDecodeError: + except jsonlib.JSONDecodeError: raise exceptions.JSONParseError(c.stdout, c.stderr) else: data = traverse(parsed) diff --git a/pipenv/environment.py b/pipenv/environment.py index 0406130a63..fb5c2ffd8b 100644 --- a/pipenv/environment.py +++ b/pipenv/environment.py @@ -300,8 +300,7 @@ def sys_path(self): :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 @@ def sys_path(self): ) try: path = json.loads(path.strip()) - except JSONDecodeError: + except json.JSONDecodeError: path = sys.path return path diff --git a/pipenv/utils/resolver.py b/pipenv/utils/resolver.py index 7020bf1f11..c3872edba0 100644 --- a/pipenv/utils/resolver.py +++ b/pipenv/utils/resolver.py @@ -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): diff --git a/pipenv/utils/shell.py b/pipenv/utils/shell.py index 5411c6afce..40ca5365a8 100644 --- a/pipenv/utils/shell.py +++ b/pipenv/utils/shell.py @@ -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