Skip to content

Commit

Permalink
Remove unnecessary exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dqkqd committed Aug 2, 2022
1 parent 3a05e37 commit 3ca7c96
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions pipenv/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import site
import sys
from pathlib import Path
from sysconfig import get_paths, get_python_version, get_scheme_names
from sysconfig import get_paths, get_scheme_names

import pkg_resources

Expand Down Expand Up @@ -159,17 +159,6 @@ def python_info(self) -> Dict[str, str]:
return {"py_version_short": py_version_short, "abiflags": abiflags}
return {}

def _replace_parent_version(self, path: str, replace_version: str) -> str:
if not os.path.exists(path):
base, leaf = os.path.split(path)
base, parent = os.path.split(base)
leaf = os.path.join(parent, leaf).replace(
replace_version,
self.python_info.get("py_version_short", get_python_version()),
)
return os.path.join(base, leaf)
return path

@cached_property
def install_scheme(self):
if "venv" in get_scheme_names():
Expand Down Expand Up @@ -214,30 +203,7 @@ def base_paths(self) -> Dict[str, str]:
if self._base_paths:
paths = self._base_paths.copy()
else:
try:
paths = self.get_paths()
except Exception:
paths = get_paths(
self.install_scheme,
vars={
"base": prefix,
"platbase": prefix,
},
)
current_version = get_python_version()
try:
for k in list(paths.keys()):
if not os.path.exists(paths[k]):
paths[k] = self._replace_parent_version(
paths[k], current_version
)
except OSError:
# Sometimes virtualenvs are made using virtualenv interpreters and there is no
# include directory, which will cause this approach to fail. This failsafe
# will make sure we fall back to the shell execution to find the real include path
paths = self.get_include_path()
paths.update(self.get_lib_paths())
paths["scripts"] = self.script_basedir
paths = self.get_paths()
if not paths:
paths = get_paths(
self.install_scheme,
Expand Down

0 comments on commit 3ca7c96

Please sign in to comment.