diff --git a/src/depkit/depmanager.py b/src/depkit/depmanager.py index bbd6688..d1de5a8 100644 --- a/src/depkit/depmanager.py +++ b/src/depkit/depmanager.py @@ -190,9 +190,7 @@ def install_script(self, script_path: str | os.PathLike[str]) -> None: DependencyError: If script processing or installation fails ScriptError: If script metadata is invalid """ - from upath import UPath - - path = UPath(script_path) + path = Path(script_path) try: # Read and validate script diff --git a/src/depkit/utils.py b/src/depkit/utils.py index 5ab3589..6dfad34 100644 --- a/src/depkit/utils.py +++ b/src/depkit/utils.py @@ -6,7 +6,6 @@ import importlib.metadata import logging import os -from pathlib import Path import shutil import subprocess import sys @@ -16,6 +15,11 @@ from depkit.parser import parse_pep723_deps +try: + from upath import UPath as Path +except (ImportError, ModuleNotFoundError): + from pathlib import Path + if TYPE_CHECKING: from collections.abc import Sequence from os import PathLike @@ -27,11 +31,9 @@ def verify_paths(paths: Sequence[str | PathLike[str]]) -> None: """Verify that paths exist and are accessible.""" - from upath import UPath - for path in paths: try: - path_obj = UPath(path) + path_obj = Path(path) if not path_obj.exists(): msg = f"Path does not exist: {path}" raise DependencyError(msg) # noqa: TRY301 @@ -85,10 +87,8 @@ def get_pip_command(*, prefer_uv: bool = False, is_uv: bool = False) -> Command: def collect_file_dependencies(path: str | PathLike[str]) -> set[str]: """Collect dependencies from a Python file.""" - from upath import UPath - try: - content = UPath(path).read_text(encoding="utf-8", errors="ignore") + content = Path(path).read_text(encoding="utf-8", errors="ignore") return set(parse_pep723_deps(content)) except Exception as exc: # noqa: BLE001 logger.debug("Failed to parse dependencies from %s: %s", path, exc) @@ -97,10 +97,8 @@ def collect_file_dependencies(path: str | PathLike[str]) -> set[str]: def scan_directory_deps(directory: str | PathLike[str]) -> set[str]: """Recursively scan directory for PEP 723 dependencies.""" - from upath import UPath - all_deps: set[str] = set() - dir_path = UPath(directory) + dir_path = Path(directory) # Don't scan site-packages or other system directories if "site-packages" in str(dir_path):