Skip to content

Commit

Permalink
Revert "Reduce complexity here with pathlib"
Browse files Browse the repository at this point in the history
This reverts commit c58ea38.
  • Loading branch information
matteius committed Jan 22, 2024
1 parent c58ea38 commit 65b8582
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions pipenv/vendor/pythonfinder/models/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
DefaultDict,
Generator,
Iterator,
Union,
)

from ..environment import (
Expand Down Expand Up @@ -312,28 +311,20 @@ def _setup_pyenv(self) -> SystemPath:
self._register_finder("pyenv", pyenv_finder)
return self

def get_path(self, path: Union[str, Path]) -> Union[PythonFinder, PathEntry]:
def get_path(self, path) -> PythonFinder | PathEntry:
if path is None:
raise TypeError("A path must be provided in order to generate a path entry.")

# Convert path to pathlib.Path object if it's a string
path = Path(path) if isinstance(path, str) else path

# Try to get the PathEntry or PythonFinder from the paths dictionary
path = ensure_path(path)
_path = self.paths.get(path)

# If not found, check if the path exists and is part of the path_order
if not _path and str(path) in self.path_order and path.exists():
if not _path:
_path = self.paths.get(path.as_posix())
if not _path and path.as_posix() in self.path_order and path.exists():
_path = PathEntry.create(
path=path.resolve(), # resolve() method will give the absolute path
is_root=True,
only_python=self.only_python
path=path.absolute(), is_root=True, only_python=self.only_python
)
self.paths[str(path)] = _path # Store the PathEntry or PythonFinder in paths

self.paths[path.as_posix()] = _path
if not _path:
raise ValueError(f"Path not found or generated: {path!r}")

return _path

def _get_paths(self) -> Generator[PythonFinder | PathEntry, None, None]:
Expand Down

0 comments on commit 65b8582

Please sign in to comment.