Skip to content

Commit

Permalink
Remove some more vistir usage (#5067)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
oz123 authored Apr 21, 2022
1 parent 23851d8 commit f0199ee
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
22 changes: 12 additions & 10 deletions pipenv/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json as simplejson
import logging
import os
import shutil
import sys
import time
import warnings
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions pipenv/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -319,7 +318,7 @@ def sys_path(self):
)
try:
path = json.loads(path.strip())
except JSONDecodeError:
except json.JSONDecodeError:
path = sys.path
return path

Expand Down
4 changes: 2 additions & 2 deletions pipenv/utils/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down
15 changes: 4 additions & 11 deletions pipenv/utils/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f0199ee

Please sign in to comment.