pathlib-next 0.8.1__tar.gz → 0.8.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/CHANGELOG.md +35 -1
  2. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/PKG-INFO +1 -1
  3. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/docs/benchmarks.md +10 -0
  4. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/pyproject.toml +1 -1
  5. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/sftp/__init__.py +67 -25
  6. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/sftp/_asyncssh.py +16 -2
  7. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/sftp/_paramiko.py +5 -14
  8. pathlib_next-0.8.3/src/pathlib_next/uri/schemes/sftp/_sshconfig.py +34 -0
  9. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_sftp_asyncssh.py +67 -6
  10. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_smoke.py +10 -6
  11. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/.gitignore +0 -0
  12. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/LICENSE +0 -0
  13. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/README.md +0 -0
  14. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/docs/api/mempath.md +0 -0
  15. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/docs/api/path.md +0 -0
  16. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/docs/api/testing.md +0 -0
  17. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/docs/api/uri.md +0 -0
  18. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/docs/api/utils.md +0 -0
  19. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/docs/changelog.md +0 -0
  20. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/docs/divergences.md +0 -0
  21. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/docs/guides/cli.md +0 -0
  22. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/docs/guides/extending.md +0 -0
  23. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/docs/guides/schemes.md +0 -0
  24. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/docs/index.md +0 -0
  25. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/examples/az_listing.py +0 -0
  26. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/examples/data_and_archive.py +0 -0
  27. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/examples/ftp_listing.py +0 -0
  28. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/examples/github_listing.py +0 -0
  29. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/examples/gitlab_listing.py +0 -0
  30. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/examples/gs_listing.py +0 -0
  31. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/examples/http_listing.py +0 -0
  32. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/examples/local_and_mem.py +0 -0
  33. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/examples/s3_listing.py +0 -0
  34. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/examples/sftp_sync.py +0 -0
  35. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/examples/webdav_roundtrip.py +0 -0
  36. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/mkdocs.yml +0 -0
  37. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/__init__.py +0 -0
  38. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/fspath.py +0 -0
  39. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/mempath.py +0 -0
  40. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/path.py +0 -0
  41. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/protocols/__init__.py +0 -0
  42. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/protocols/fs.py +0 -0
  43. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/protocols/io.py +0 -0
  44. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/py.typed +0 -0
  45. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/testing.py +0 -0
  46. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/tools/__init__.py +0 -0
  47. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/tools/uripath.py +0 -0
  48. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/__init__.py +0 -0
  49. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/query.py +0 -0
  50. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/__init__.py +0 -0
  51. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/_gitrepo.py +0 -0
  52. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/archive/__init__.py +0 -0
  53. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/archive/_base.py +0 -0
  54. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/archive/tar.py +0 -0
  55. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/archive/zip.py +0 -0
  56. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/az.py +0 -0
  57. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/data.py +0 -0
  58. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/dav.py +0 -0
  59. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/file.py +0 -0
  60. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/ftp.py +0 -0
  61. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/git/__init__.py +0 -0
  62. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/git/_base.py +0 -0
  63. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/git/github.py +0 -0
  64. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/git/gitlab.py +0 -0
  65. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/github.py +0 -0
  66. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/gitlab.py +0 -0
  67. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/gs.py +0 -0
  68. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/http.py +0 -0
  69. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/schemes/s3.py +0 -0
  70. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/uri/source.py +0 -0
  71. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/utils/__init__.py +0 -0
  72. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/utils/archive.py +0 -0
  73. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/utils/checksum.py +0 -0
  74. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/utils/glob.py +0 -0
  75. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/utils/stat.py +0 -0
  76. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/src/pathlib_next/utils/sync.py +0 -0
  77. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/conftest.py +0 -0
  78. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_archive_uri.py +0 -0
  79. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_az.py +0 -0
  80. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_az_fake.py +0 -0
  81. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_contract.py +0 -0
  82. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_data_uri.py +0 -0
  83. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_dav.py +0 -0
  84. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_ftp.py +0 -0
  85. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_gitrepo.py +0 -0
  86. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_glob.py +0 -0
  87. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_gs.py +0 -0
  88. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_gs_fake.py +0 -0
  89. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_http.py +0 -0
  90. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_http_live.py +0 -0
  91. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_http_parser.py +0 -0
  92. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_local.py +0 -0
  93. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_mempath.py +0 -0
  94. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_parity_io.py +0 -0
  95. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_parity_pure.py +0 -0
  96. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_path_gaps.py +0 -0
  97. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_pathname.py +0 -0
  98. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_plugins.py +0 -0
  99. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_properties.py +0 -0
  100. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_query.py +0 -0
  101. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_s3.py +0 -0
  102. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_sftp.py +0 -0
  103. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_source.py +0 -0
  104. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_sync.py +0 -0
  105. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_uri_parse.py +0 -0
  106. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_uri_path.py +0 -0
  107. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_uripath_tool.py +0 -0
  108. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_utils.py +0 -0
  109. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_walk.py +0 -0
  110. {pathlib_next-0.8.1 → pathlib_next-0.8.3}/tests/test_webdav.py +0 -0
@@ -7,6 +7,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.8.3] - 2026-07-18
11
+
12
+ ### Changed
13
+ - **`AsyncsshSftpBackend` default `max_concurrency` raised 8 → 16.** A 128-file
14
+ loopback recursive-copy/rm sweep of `mc ∈ {1,2,4,8,16}` (median of 3) showed
15
+ recursive copy improving monotonically with concurrency (mc=8→16 ≈3% faster on
16
+ top of mc=1→8 ≈1.13x) and recursive remove flat within noise, with 16
17
+ fastest-or-tied and well inside asyncssh's SFTP request window. Exposed as
18
+ `AsyncsshSftpBackend.DEFAULT_MAX_CONCURRENCY`; pass `max_concurrency=` to
19
+ override. Loopback evidence only — a high-latency remote link may warrant a
20
+ different value; 16 is a safe modest default, not a tuned optimum.
21
+
22
+ ## [0.8.2] - 2026-07-18
23
+
24
+ ### Fixed
25
+ - **`SftpPath` could not be imported or used with an asyncssh-only install
26
+ (no `paramiko`).** `uri/schemes/sftp/__init__.py` imported `._paramiko`
27
+ eagerly at module load, and `_asyncssh.py` imported the
28
+ `_DEFAULT_SSH_CONFIG` sentinel from `._paramiko`, so merely importing
29
+ `SftpPath` (or the `AsyncsshSftpBackend`) required `paramiko` even when the
30
+ caller only wanted the asyncssh backend from the `sftp-async` extra. The
31
+ paramiko-free bits (the sentinel + config-path normalization) moved to a new
32
+ `_sshconfig` module, and the paramiko `SftpBackend` is now imported lazily
33
+ (via `_probe_paramiko`, mirroring `_probe_asyncssh`) only when actually
34
+ selected. `SftpBackend`/`_DEFAULT_SSH_CONFIG` remain importable from the
35
+ scheme package (PEP 562 `__getattr__`) for backward compatibility.
36
+ `PATHLIB_NEXT_SFTP_BACKEND=paramiko` (or `auto` with neither library) now
37
+ raises a clear `ImportError` naming the missing extra instead of a bare
38
+ `ModuleNotFoundError` at import time. Regression test added
39
+ (`test_sftp_scheme_imports_and_resolves_without_paramiko`, runs in a
40
+ paramiko-masked subprocess).
41
+
10
42
  ## [0.8.1] - 2026-07-16
11
43
 
12
44
  ### Fixed
@@ -475,7 +507,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
475
507
  - Sync error handling.
476
508
  - Generic Path Protocol based pathlib implementation for URI paths with file access support for sftp, http, file schemes.
477
509
 
478
- [Unreleased]: https://github.com/jose-pr/pathlib_next/compare/v0.8.1...HEAD
510
+ [Unreleased]: https://github.com/jose-pr/pathlib_next/compare/v0.8.3...HEAD
511
+ [0.8.3]: https://github.com/jose-pr/pathlib_next/compare/v0.8.2...v0.8.3
512
+ [0.8.2]: https://github.com/jose-pr/pathlib_next/compare/v0.8.1...v0.8.2
479
513
  [0.8.1]: https://github.com/jose-pr/pathlib_next/compare/v0.8.0...v0.8.1
480
514
  [0.8.0]: https://github.com/jose-pr/pathlib_next/compare/v0.7.0...v0.8.0
481
515
  [0.7.0]: https://github.com/jose-pr/pathlib_next/compare/v0.6.0...v0.7.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pathlib_next
3
- Version: 0.8.1
3
+ Version: 0.8.3
4
4
  Summary: Generic Path Protocol based pathlib
5
5
  Project-URL: Homepage, https://github.com/jose-pr/pathlib_next/
6
6
  Project-URL: Documentation, https://jose-pr.github.io/pathlib_next/
@@ -142,6 +142,16 @@ Legend: `p` = `paramiko`, `a` = `asyncssh`.
142
142
  was fastest at `7.6068s`, with `4` at `14.2806s` and `8` at `13.3736s`.
143
143
  Treat this as workload-specific follow-up evidence, not as a default tuning
144
144
  decision.
145
+ - **2026-07-18 (0.8.3): `AsyncsshSftpBackend` default `max_concurrency` raised
146
+ 8 → 16.** A cleaner 128-file loopback sweep of `mc ∈ {1,2,4,8,16}` (median of
147
+ 3, py3.14) showed recursive copy improving *monotonically* with concurrency
148
+ (mc=1 `1.66s` → mc=8 `1.47s` ≈ 1.13x → mc=16 `1.42s`, a further ≈3%), and
149
+ recursive remove flat within noise (median spread `0.498`..`0.551`, mc=16
150
+ marginally best). This supersedes the earlier "mc=1 fastest" loopback reading
151
+ (from the older code path / a different venv). 16 stays within asyncssh's SFTP
152
+ request window. **Loopback only** — no per-op latency; a high-latency remote
153
+ link may favour higher concurrency still, so 16 is a safe modest default, not
154
+ a tuned optimum. Override per backend via `AsyncsshSftpBackend(max_concurrency=…)`.
145
155
  - `python benchmarks/bench.py syncer` on the same local run reported
146
156
  PathSyncer copy of 128 local files at `0.4524s`, dry-run at `0.0534s`, and
147
157
  remove-missing plus copy at `0.9260s`. This suggests metadata reuse may be
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pathlib_next"
7
- version = "0.8.1"
7
+ version = "0.8.3"
8
8
  authors = [{ name = "Jose A" }]
9
9
  description = "Generic Path Protocol based pathlib"
10
10
  readme = "README.md"
@@ -32,7 +32,9 @@ class BaseSftpBackend(object):
32
32
  def client(self, source: Source): ...
33
33
 
34
34
 
35
- from ._paramiko import _DEFAULT_SSH_CONFIG, SftpBackend as SftpBackend # noqa: E402
35
+ # The default-config sentinel is paramiko-free (lives in `_sshconfig`) so
36
+ # importing this scheme never pulls paramiko in just to have the sentinel.
37
+ from ._sshconfig import _DEFAULT_SSH_CONFIG
36
38
 
37
39
 
38
40
  # --- backend selection -----------------------------------------------------
@@ -41,10 +43,18 @@ from ._paramiko import _DEFAULT_SSH_CONFIG, SftpBackend as SftpBackend # noqa:
41
43
  # UriPath backend propagation works, unchanged) > `SftpPath._default_backend_cls`
42
44
  # class attribute > `PATHLIB_NEXT_SFTP_BACKEND` env var > auto-detect
43
45
  # (asyncssh if importable, else paramiko).
46
+ #
47
+ # BOTH backends are imported lazily (`_probe_asyncssh`/`_probe_paramiko`): merely
48
+ # importing this scheme -- which happens for every `sftp:` URL and for
49
+ # `from ...sftp import SftpPath` -- must not require *either* SSH library. In
50
+ # particular an asyncssh-only install (the `sftp-async` extra, no paramiko) must
51
+ # be able to import and use `SftpPath`; eagerly importing `._paramiko` here broke
52
+ # exactly that.
44
53
 
45
54
  _ENV_VAR = "PATHLIB_NEXT_SFTP_BACKEND"
46
- _BACKEND_REGISTRY: "dict[str, type[BaseSftpBackend]]" = {"paramiko": SftpBackend}
55
+ _BACKEND_REGISTRY: "dict[str, type[BaseSftpBackend]]" = {}
47
56
  _asyncssh_probed = False
57
+ _paramiko_probed = False
48
58
  _resolved_backend_cls: "type[BaseSftpBackend] | None" = None
49
59
 
50
60
 
@@ -64,47 +74,79 @@ def _probe_asyncssh() -> None:
64
74
  _BACKEND_REGISTRY["asyncssh"] = AsyncsshSftpBackend
65
75
 
66
76
 
77
+ def _probe_paramiko() -> None:
78
+ # Symmetric with `_probe_asyncssh`: only import paramiko when it is actually
79
+ # needed (paramiko selected, or auto-detect with asyncssh unavailable), so an
80
+ # asyncssh-only install never imports paramiko.
81
+ global _paramiko_probed
82
+ if _paramiko_probed:
83
+ return
84
+ _paramiko_probed = True
85
+ try:
86
+ from ._paramiko import SftpBackend
87
+ except ImportError:
88
+ return
89
+ _BACKEND_REGISTRY["paramiko"] = SftpBackend
90
+
91
+
67
92
  def _resolve_default_backend_cls(reload: bool = False) -> "type[BaseSftpBackend]":
68
93
  global _resolved_backend_cls
69
94
  if not reload and _resolved_backend_cls is not None:
70
95
  return _resolved_backend_cls
71
96
  value = _os.environ.get(_ENV_VAR, "auto")
72
97
  if value == "paramiko":
98
+ _probe_paramiko()
99
+ if "paramiko" not in _BACKEND_REGISTRY:
100
+ raise ImportError(
101
+ f"{_ENV_VAR}=paramiko but the paramiko package is not "
102
+ "installed -- install the 'sftp' extra, or unset "
103
+ f"{_ENV_VAR} to auto-detect (uses asyncssh if available)."
104
+ )
73
105
  cls = _BACKEND_REGISTRY["paramiko"]
74
- else:
106
+ elif value == "asyncssh":
75
107
  _probe_asyncssh()
76
- if value == "auto":
77
- cls = _BACKEND_REGISTRY.get("asyncssh") or _BACKEND_REGISTRY["paramiko"]
78
- elif value == "asyncssh":
79
- if "asyncssh" not in _BACKEND_REGISTRY:
80
- # Fail loud -- a silent fallback to paramiko would hide a
81
- # deployment misconfiguration (asyncssh extra not installed
82
- # where the operator explicitly asked for it).
83
- raise ImportError(
84
- f"{_ENV_VAR}=asyncssh but the asyncssh package is not "
85
- "installed -- install the 'sftp-async' extra, or unset "
86
- f"{_ENV_VAR} to auto-detect (falls back to paramiko)."
87
- )
88
- cls = _BACKEND_REGISTRY["asyncssh"]
89
- else:
90
- raise ValueError(
91
- f"{_ENV_VAR}={value!r} is not a recognized SFTP backend "
92
- f"(expected one of {sorted({'auto', *_BACKEND_REGISTRY})!r})"
108
+ if "asyncssh" not in _BACKEND_REGISTRY:
109
+ # Fail loud -- a silent fallback to paramiko would hide a
110
+ # deployment misconfiguration (asyncssh extra not installed
111
+ # where the operator explicitly asked for it).
112
+ raise ImportError(
113
+ f"{_ENV_VAR}=asyncssh but the asyncssh package is not "
114
+ "installed -- install the 'sftp-async' extra, or unset "
115
+ f"{_ENV_VAR} to auto-detect (falls back to paramiko)."
116
+ )
117
+ cls = _BACKEND_REGISTRY["asyncssh"]
118
+ elif value == "auto":
119
+ _probe_asyncssh()
120
+ if "asyncssh" not in _BACKEND_REGISTRY:
121
+ _probe_paramiko()
122
+ cls = _BACKEND_REGISTRY.get("asyncssh") or _BACKEND_REGISTRY.get("paramiko")
123
+ if cls is None:
124
+ raise ImportError(
125
+ "no SFTP backend available -- install the 'sftp-async' "
126
+ "(asyncssh) or 'sftp' (paramiko) extra."
93
127
  )
128
+ else:
129
+ raise ValueError(
130
+ f"{_ENV_VAR}={value!r} is not a recognized SFTP backend "
131
+ "(expected one of 'auto', 'asyncssh', 'paramiko')"
132
+ )
94
133
  _resolved_backend_cls = cls
95
134
  return cls
96
135
 
97
136
 
98
137
  def __getattr__(name: str):
99
- # PEP 562 lazy module attribute: `from .sftp import AsyncsshSftpBackend`
100
- # (or `sftp.AsyncsshSftpBackend`) only imports asyncssh at the point
101
- # it's actually referenced -- importing `pathlib_next.uri.schemes.sftp`
102
- # itself (which happens for every `sftp:` URL, regardless of which
103
- # backend ends up selected) must not eagerly import asyncssh.
138
+ # PEP 562 lazy module attributes: referencing `AsyncsshSftpBackend`,
139
+ # `SftpBackend` (paramiko), or `_DEFAULT_SSH_CONFIG` via
140
+ # `from .sftp import ...` imports the relevant backend only at that point --
141
+ # importing the scheme module itself pulls in neither SSH library.
104
142
  if name == "AsyncsshSftpBackend":
105
143
  from ._asyncssh import AsyncsshSftpBackend
106
144
 
107
145
  return AsyncsshSftpBackend
146
+ if name == "SftpBackend":
147
+ from ._paramiko import SftpBackend
148
+
149
+ return SftpBackend
108
150
  raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
109
151
 
110
152
 
@@ -15,7 +15,7 @@ import asyncssh as _asyncssh
15
15
  from ... import Source
16
16
  from ....utils.stat import FileStat
17
17
  from . import BaseSftpBackend
18
- from ._paramiko import _DEFAULT_SSH_CONFIG
18
+ from ._sshconfig import _DEFAULT_SSH_CONFIG
19
19
 
20
20
  # --- shared background event loop -------------------------------------
21
21
  # asyncssh is asyncio-only end to end (connect(), every SFTPClient method,
@@ -482,14 +482,28 @@ class AsyncsshSftpBackend(BaseSftpBackend):
482
482
  #: real-world OpenSSH v3 servers, or the standard opcode against v5/v6).
483
483
  supports_hardlink = True
484
484
 
485
+ #: Default bound on concurrent SFTP requests during a recursive copy/rm.
486
+ #: 16 (raised from 8 in 0.8.3): a 128-file loopback sweep of mc in
487
+ #: {1,2,4,8,16} (median of 3, 3.14) showed recursive copy improving
488
+ #: monotonically with concurrency -- mc=1 -> mc=8 ~1.13x, mc=8 -> mc=16 a
489
+ #: further ~3% -- with recursive rm flat (spread within run-to-run noise) and
490
+ #: mc=16 fastest-or-tied for both. 16 stays well inside asyncssh's SFTP
491
+ #: request window, so the extra in-flight requests carry no overload risk.
492
+ #: NOTE: loopback evidence only (no per-op network latency); a high-latency
493
+ #: remote link may favour even higher concurrency, but 16 is a safe, modest
494
+ #: default. Override per-backend via ``max_concurrency=``.
495
+ DEFAULT_MAX_CONCURRENCY = 16
496
+
485
497
  def __init__(
486
498
  self,
487
499
  connect_opts: "dict[str, _ty.Any] | None" = None,
488
500
  *,
489
- max_concurrency: int = 8,
501
+ max_concurrency: "int | None" = None,
490
502
  sftp_version: int = 4,
491
503
  ssh_config=_DEFAULT_SSH_CONFIG,
492
504
  ):
505
+ if max_concurrency is None:
506
+ max_concurrency = self.DEFAULT_MAX_CONCURRENCY
493
507
  self.connect_opts = {} if connect_opts is None else dict(connect_opts)
494
508
  if "config" not in self.connect_opts:
495
509
  if ssh_config is None:
@@ -9,20 +9,11 @@ from .... import utils as _utils
9
9
  from ... import Source
10
10
  from . import BaseSftpBackend
11
11
 
12
-
13
- _DEFAULT_SSH_CONFIG = object()
14
-
15
-
16
- def _normalize_config_paths(
17
- ssh_config: "object",
18
- ) -> "tuple[str, ...] | None":
19
- if ssh_config is _DEFAULT_SSH_CONFIG:
20
- return (str(_pathlib.Path.home() / ".ssh" / "config"),)
21
- if ssh_config is None:
22
- return None
23
- if isinstance(ssh_config, (str, _pathlib.PurePath)):
24
- return (str(ssh_config),)
25
- return tuple(str(path) for path in ssh_config)
12
+ # The sentinel + path normalization are paramiko-free and now live in
13
+ # ``_sshconfig`` so the asyncssh backend and the scheme ``__init__`` can use them
14
+ # without importing paramiko. Re-exported here for backward compatibility (older
15
+ # code did ``from ._paramiko import _DEFAULT_SSH_CONFIG``).
16
+ from ._sshconfig import _DEFAULT_SSH_CONFIG, _normalize_config_paths
26
17
 
27
18
 
28
19
  @_utils.LRU
@@ -0,0 +1,34 @@
1
+ """Backend-agnostic SSH-config helpers (no paramiko/asyncssh import).
2
+
3
+ The default-config sentinel and path normalization live here, separate from
4
+ ``_paramiko.py``, so the asyncssh backend and the scheme's ``__init__`` can
5
+ reference them **without importing paramiko**. Only the actual config *parsing*
6
+ (``_load_ssh_config``/``_lookup_ssh_config`` in ``_paramiko.py``) needs
7
+ ``paramiko.SSHConfig``; the sentinel and the "which files" logic do not.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import pathlib as _pathlib
13
+
14
+ #: Sentinel meaning "use the default SSH config location(s)". A bare ``object()``
15
+ #: so it is distinct from ``None`` (explicitly no config) and from any real path.
16
+ #: Shared by both backends; kept paramiko-free on purpose (see module docstring).
17
+ _DEFAULT_SSH_CONFIG = object()
18
+
19
+
20
+ def _normalize_config_paths(
21
+ ssh_config: "object",
22
+ ) -> "tuple[str, ...] | None":
23
+ """Resolve an ``ssh_config`` argument to a tuple of file paths, or ``None``.
24
+
25
+ ``_DEFAULT_SSH_CONFIG`` -> the user's ``~/.ssh/config``; ``None`` -> no config;
26
+ a str/path -> that one file; an iterable -> those files. No paramiko needed.
27
+ """
28
+ if ssh_config is _DEFAULT_SSH_CONFIG:
29
+ return (str(_pathlib.Path.home() / ".ssh" / "config"),)
30
+ if ssh_config is None:
31
+ return None
32
+ if isinstance(ssh_config, (str, _pathlib.PurePath)):
33
+ return (str(ssh_config),)
34
+ return tuple(str(path) for path in ssh_config)
@@ -137,6 +137,13 @@ def _reset_backend_resolution(monkeypatch):
137
137
 
138
138
  from pathlib_next.uri.schemes import sftp as sftp_pkg # noqa: E402
139
139
 
140
+ import importlib.util as _importutil # noqa: E402
141
+
142
+ _HAS_PARAMIKO = _importutil.find_spec("paramiko") is not None
143
+ _needs_paramiko = pytest.mark.skipif(
144
+ not _HAS_PARAMIKO, reason="paramiko not installed (asyncssh-only install)"
145
+ )
146
+
140
147
 
141
148
  def test_resolve_default_backend_auto_prefers_asyncssh(monkeypatch):
142
149
  monkeypatch.delenv(sftp_pkg._ENV_VAR, raising=False)
@@ -144,6 +151,7 @@ def test_resolve_default_backend_auto_prefers_asyncssh(monkeypatch):
144
151
  assert cls is backend_mod.AsyncsshSftpBackend
145
152
 
146
153
 
154
+ @_needs_paramiko
147
155
  def test_resolve_default_backend_explicit_paramiko(monkeypatch):
148
156
  monkeypatch.setenv(sftp_pkg._ENV_VAR, "paramiko")
149
157
  cls = sftp_pkg._resolve_default_backend_cls(reload=True)
@@ -164,7 +172,6 @@ def test_resolve_default_backend_invalid_value_raises(monkeypatch):
164
172
 
165
173
  def test_resolve_default_backend_asyncssh_unavailable_raises_importerror(monkeypatch):
166
174
  monkeypatch.setenv(sftp_pkg._ENV_VAR, "asyncssh")
167
- monkeypatch.setitem(sftp_pkg._BACKEND_REGISTRY, "paramiko", sftp_pkg.SftpBackend)
168
175
  monkeypatch.delitem(sftp_pkg._BACKEND_REGISTRY, "asyncssh", raising=False)
169
176
  monkeypatch.setattr(sftp_pkg, "_asyncssh_probed", True) # skip the real probe
170
177
  with pytest.raises(ImportError, match="sftp-async"):
@@ -172,13 +179,16 @@ def test_resolve_default_backend_asyncssh_unavailable_raises_importerror(monkeyp
172
179
 
173
180
 
174
181
  def test_resolve_default_backend_result_is_cached(monkeypatch):
175
- monkeypatch.setenv(sftp_pkg._ENV_VAR, "paramiko")
176
- first = sftp_pkg._resolve_default_backend_cls(reload=True)
182
+ # asyncssh first (always available in this test module), then flip the env
183
+ # and confirm no-reload returns the cached asyncssh result.
177
184
  monkeypatch.setenv(sftp_pkg._ENV_VAR, "asyncssh")
185
+ first = sftp_pkg._resolve_default_backend_cls(reload=True)
186
+ monkeypatch.setenv(sftp_pkg._ENV_VAR, "auto")
178
187
  second = sftp_pkg._resolve_default_backend_cls() # no reload -- cached
179
- assert first is second is sftp_pkg.SftpBackend
188
+ assert first is second is backend_mod.AsyncsshSftpBackend
180
189
 
181
190
 
191
+ @_needs_paramiko
182
192
  def test_default_backend_cls_class_attribute_wins_over_env(monkeypatch):
183
193
  monkeypatch.setenv(sftp_pkg._ENV_VAR, "asyncssh")
184
194
 
@@ -191,6 +201,42 @@ def test_default_backend_cls_class_attribute_wins_over_env(monkeypatch):
191
201
  assert isinstance(backend, sftp_pkg.SftpBackend)
192
202
 
193
203
 
204
+ def test_sftp_scheme_imports_and_resolves_without_paramiko():
205
+ """Regression: an asyncssh-only install (no paramiko) must still import
206
+ SftpPath and auto-resolve to the asyncssh backend.
207
+
208
+ Runs in a subprocess with ``paramiko`` masked (blocked in sys.modules) so the
209
+ guard holds even in a CI env where paramiko happens to be installed. Before
210
+ the fix, ``uri/schemes/sftp/__init__`` imported ``._paramiko`` eagerly, so
211
+ merely importing ``SftpPath`` raised ModuleNotFoundError without paramiko.
212
+ """
213
+ import subprocess
214
+ import sys
215
+ import textwrap
216
+
217
+ script = textwrap.dedent(
218
+ """
219
+ import sys
220
+ # Make `import paramiko` fail, simulating an asyncssh-only install.
221
+ sys.modules["paramiko"] = None
222
+ from pathlib_next.uri.schemes.sftp import SftpPath
223
+ from pathlib_next.uri.schemes import sftp as pkg
224
+ sp = SftpPath("sftp://root@h:22/etc/hosts")
225
+ assert sp.source.host == "h" and sp.path == "/etc/hosts"
226
+ cls = pkg._resolve_default_backend_cls(reload=True)
227
+ assert cls.__name__ == "AsyncsshSftpBackend", cls
228
+ print("OK")
229
+ """
230
+ )
231
+ result = subprocess.run(
232
+ [sys.executable, "-c", script],
233
+ capture_output=True,
234
+ text=True,
235
+ )
236
+ assert result.returncode == 0, result.stderr
237
+ assert "OK" in result.stdout
238
+
239
+
194
240
  def test_explicit_backend_kwarg_wins_over_everything(monkeypatch):
195
241
  monkeypatch.setenv(sftp_pkg._ENV_VAR, "asyncssh")
196
242
  explicit = backend_mod.AsyncsshSftpBackend()
@@ -219,6 +265,7 @@ def test_asyncssh_backend_supports_lchmod_and_hardlink():
219
265
  assert backend.supports_hardlink is True
220
266
 
221
267
 
268
+ @_needs_paramiko
222
269
  def test_paramiko_backend_does_not_support_lchmod_or_hardlink():
223
270
  assert sftp_pkg.SftpBackend.supports_lchmod is False
224
271
  assert sftp_pkg.SftpBackend.supports_hardlink is False
@@ -246,9 +293,12 @@ def test_asyncssh_backend_has_max_concurrency():
246
293
  assert backend.max_concurrency == 16
247
294
 
248
295
 
249
- def test_asyncssh_backend_max_concurrency_defaults_to_8():
296
+ def test_asyncssh_backend_max_concurrency_defaults_to_16():
297
+ # Raised from 8 to 16 in 0.8.3 (loopback recursive-copy sweep); see
298
+ # DEFAULT_MAX_CONCURRENCY's rationale in _asyncssh.py.
250
299
  backend = backend_mod.AsyncsshSftpBackend()
251
- assert backend.max_concurrency == 8
300
+ assert backend.max_concurrency == 16
301
+ assert backend.max_concurrency == backend_mod.AsyncsshSftpBackend.DEFAULT_MAX_CONCURRENCY
252
302
  assert "config" not in backend.connect_opts
253
303
 
254
304
 
@@ -710,3 +760,14 @@ def test_sftppath_rm_recursive_uses_concurrent_helper(monkeypatch):
710
760
  assert recorded["kwargs"]["max_concurrency"] == 6
711
761
  assert recorded["kwargs"]["missing_ok"] is True
712
762
  assert recorded["kwargs"]["on_error"](ValueError("ignored"), src) is True
763
+
764
+
765
+ # --- default max_concurrency -------------------------------------------------
766
+
767
+
768
+ def test_explicit_max_concurrency_overrides_default():
769
+ backend = backend_mod.AsyncsshSftpBackend({"config": None}, max_concurrency=4)
770
+ assert backend.max_concurrency == 4
771
+ # 0 is honored as given (the async helpers clamp to >=1 at use time via
772
+ # `max(1, max_concurrency)`), not silently replaced by the default.
773
+ assert backend_mod.AsyncsshSftpBackend({"config": None}, max_concurrency=1).max_concurrency == 1
@@ -108,12 +108,16 @@ def test_optional_schemes_presence_or_absence():
108
108
  except ImportError:
109
109
  assert not hasattr(schemes, "HttpPath")
110
110
 
111
- # Check sftp
112
- try:
113
- import paramiko # noqa: F401
114
- assert hasattr(schemes, "SftpPath")
115
- except ImportError:
116
- assert not hasattr(schemes, "SftpPath")
111
+ # Check sftp: as of 0.8.2 importing SftpPath no longer requires an SSH
112
+ # backend (paramiko/asyncssh) -- those are resolved lazily at USE time. The
113
+ # scheme is a UriPath, so its import gate is `uritools` (the `uri` extra);
114
+ # SftpPath is present exactly when that is importable. Using it without any
115
+ # SSH backend installed is what raises (covered by the backend-selection
116
+ # tests), not importing it.
117
+ import importlib.util as _importutil
118
+
119
+ _has_uri = _importutil.find_spec("uritools") is not None
120
+ assert hasattr(schemes, "SftpPath") == _has_uri
117
121
 
118
122
  # Check s3 -- S3Path only needs botocore at import time (boto3 itself is
119
123
  # a lazy import inside S3Backend.client()), so that's what gates it.
File without changes
File without changes
File without changes
File without changes
File without changes