asanypath 2.3.1__tar.gz → 2.4.0__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.
- {asanypath-2.3.1 → asanypath-2.4.0}/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
- {asanypath-2.3.1 → asanypath-2.4.0}/.github/workflows/publish.yml +1 -1
- {asanypath-2.3.1 → asanypath-2.4.0}/CODE_OF_CONDUCT.md +1 -1
- {asanypath-2.3.1 → asanypath-2.4.0}/CONTRIBUTING.md +1 -1
- {asanypath-2.3.1 → asanypath-2.4.0}/PKG-INFO +97 -6
- {asanypath-2.3.1 → asanypath-2.4.0}/README.md +95 -4
- {asanypath-2.3.1 → asanypath-2.4.0}/hatch_build.py +9 -3
- asanypath-2.4.0/src/asanypath/__init__.py +115 -0
- asanypath-2.4.0/src/asanypath/_prompt.py +22 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/_transfer.py +8 -8
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/_version.py +2 -2
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/artifactory.py +85 -66
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/asanypath.py +63 -34
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/azure.py +15 -17
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/batcher.py +16 -19
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/cli.py +130 -130
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/cloud.py +233 -71
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/common.py +137 -12
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/ftp.py +35 -40
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/gcs.py +9 -15
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/http.py +76 -17
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/local.py +31 -1
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/s3.py +25 -19
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/ssh.py +162 -44
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/sync.py +6 -1
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/conftest.py +6 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_artifactory.py +10 -5
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_asanypath.py +46 -1
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_azure.py +28 -54
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_batcher.py +0 -1
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_cli.py +65 -86
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_cloudpathmixin.py +64 -30
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_commonpathmixin.py +13 -3
- asanypath-2.4.0/tests/test_endpoints.py +93 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_ftp.py +26 -1
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_gcs.py +15 -54
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_http.py +109 -3
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_http_auth.py +4 -0
- asanypath-2.4.0/tests/test_isolation.py +584 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_local.py +2 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_s3.py +29 -68
- asanypath-2.4.0/tests/test_scandir.py +149 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_ssh.py +21 -2
- asanypath-2.4.0/tests/test_ssh_hostkeys.py +149 -0
- asanypath-2.4.0/tests/test_transport_hardening.py +149 -0
- asanypath-2.3.1/SECURITY.md +0 -17
- asanypath-2.3.1/src/asanypath/__init__.py +0 -85
- {asanypath-2.3.1 → asanypath-2.4.0}/.copilot/skills/async-python-lib/SKILL.md +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/.copilot/skills/gitguro/SKILL.md +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/.github/CODEOWNERS +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/.github/dependabot.yml +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/.github/workflows/unittests.yml +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/.gitignore +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/.pre-commit-config.yaml +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/LICENSE +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/asanypath.png +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/compose.yml +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/pyproject.toml +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/scripts/bench.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/scripts/bench_upload.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/__init__.pyi +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/_backend_opts.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/_credstore.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/_resume.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/asanypath.pyi +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/cache.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/exceptions.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/options.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/py.typed +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/src/asanypath/unsupported.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/__init__.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_backend_options.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_cache.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_credstore.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_options.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_py_typed.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_resume.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_sync.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_syncpath.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_unsupported_path.py +0 -0
- {asanypath-2.3.1 → asanypath-2.4.0}/tests/test_upload.py +0 -0
|
@@ -19,4 +19,4 @@ labels: bug
|
|
|
19
19
|
- Operating system:
|
|
20
20
|
|
|
21
21
|
Do not include credentials, tokens, private endpoints, or customer data. Report
|
|
22
|
-
security vulnerabilities privately as described in
|
|
22
|
+
security vulnerabilities privately as described in the [security policy](https://github.com/AxisCommunications/asanypath/security/policy).
|
|
@@ -139,7 +139,7 @@ jobs:
|
|
|
139
139
|
env:
|
|
140
140
|
VERSION: ${{ needs.release-version.outputs.value }}
|
|
141
141
|
run: |
|
|
142
|
-
unzip -p dist/*.whl '*/METADATA' | grep -Fx "Requires-Dist: asanypath-native~=${VERSION
|
|
142
|
+
unzip -p dist/*.whl '*/METADATA' | grep -Fx "Requires-Dist: asanypath-native~=${VERSION}"
|
|
143
143
|
|
|
144
144
|
- name: Upload Python distributions
|
|
145
145
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
|
|
@@ -8,5 +8,5 @@ confidential information are not acceptable.
|
|
|
8
8
|
|
|
9
9
|
Project maintainers may remove, edit, or reject contributions and comments that
|
|
10
10
|
do not follow this code of conduct. Report conduct concerns through the private
|
|
11
|
-
security-reporting route in [
|
|
11
|
+
security-reporting route in the [security policy](https://github.com/AxisCommunications/asanypath/security/policy). Reports will be handled
|
|
12
12
|
as confidentially as practical.
|
|
@@ -36,7 +36,7 @@ document new configuration, credentials, or backend behavior in the README.
|
|
|
36
36
|
|
|
37
37
|
Do not include credentials, private endpoints, customer data, or other
|
|
38
38
|
confidential information in issues, commits, tests, or pull requests. Report
|
|
39
|
-
security issues privately as described in [
|
|
39
|
+
security issues privately as described in the [security policy](https://github.com/AxisCommunications/asanypath/security/policy).
|
|
40
40
|
|
|
41
41
|
By contributing, you agree that your contributions are licensed under the
|
|
42
42
|
[MIT License](LICENSE).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: asanypath
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.0
|
|
4
4
|
Summary: Async pathlib for local and cloud storage
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -19,7 +19,7 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
19
19
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
20
|
Requires-Python: >=3.10
|
|
21
21
|
Requires-Dist: anyio>=4
|
|
22
|
-
Requires-Dist: asanypath-native~=2.
|
|
22
|
+
Requires-Dist: asanypath-native~=2.4.0
|
|
23
23
|
Requires-Dist: msgspec>=0.22.0
|
|
24
24
|
Requires-Dist: yarl>=1.2
|
|
25
25
|
Provides-Extra: all
|
|
@@ -100,6 +100,11 @@ info = await path.stat()
|
|
|
100
100
|
async for child in path.parent.iterdir():
|
|
101
101
|
print(child.name)
|
|
102
102
|
|
|
103
|
+
# List with metadata: is_dir always; size/mtime with stat=True.
|
|
104
|
+
# Fields the listing already reports cost no extra requests.
|
|
105
|
+
async for entry in path.parent.scandir(stat=True):
|
|
106
|
+
print(entry.path.name, entry.is_dir, entry.size, entry.mtime)
|
|
107
|
+
|
|
103
108
|
# Glob
|
|
104
109
|
async for p in AsAnyPath("s3://bucket/logs/").glob("**/*.json"):
|
|
105
110
|
print(p)
|
|
@@ -133,6 +138,30 @@ with path.open("rb") as f:
|
|
|
133
138
|
Files smaller than the buffer size are fetched in one shot automatically.
|
|
134
139
|
Supported on S3, GCS, Azure, and Artifactory.
|
|
135
140
|
|
|
141
|
+
HTTP and HTTPS paths also support read-only `open("rb")` and `open("r")`
|
|
142
|
+
with both context-manager styles. These download the entire response on entry
|
|
143
|
+
and return a seekable in-memory handle, so servers do not need to support HEAD
|
|
144
|
+
or range requests. Text mode accepts `encoding`, `errors`, and `newline`.
|
|
145
|
+
Existing HTTP authentication and read-cache settings apply; anonymous URLs
|
|
146
|
+
require no token.
|
|
147
|
+
|
|
148
|
+
### Service endpoints
|
|
149
|
+
|
|
150
|
+
S3, GCS, Azure and Artifactory paths expose a read-only `endpoint_url` property:
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
path = AsAnyPath("s3://bucket/key", endpoint_url="https://storage.example.com")
|
|
154
|
+
print(path.endpoint_url) # https://storage.example.com
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
This is the complete service base URL, including any service-root path such as
|
|
158
|
+
`/artifactory`, but excluding the bucket, container, repository and object path.
|
|
159
|
+
Reading it performs no I/O. For S3, it initially reflects an explicit override
|
|
160
|
+
or regional default; AWS configuration resolution during an operation can
|
|
161
|
+
update it. It is not necessarily the final per-request URL (for example, after
|
|
162
|
+
bucket addressing or redirects). Local, HTTP, SSH and FTP paths do not expose
|
|
163
|
+
this property.
|
|
164
|
+
|
|
136
165
|
### Copy and recursive delete
|
|
137
166
|
|
|
138
167
|
```python
|
|
@@ -271,6 +300,49 @@ Pure path operations (e.g. `.name`, `.parent`, joins) still work, while backend
|
|
|
271
300
|
operations (e.g. `.exists()`, `.read_bytes()`, `.open()`) raise
|
|
272
301
|
`UnsupportedProtocolError` on use.
|
|
273
302
|
|
|
303
|
+
### Credentials and derived paths
|
|
304
|
+
|
|
305
|
+
Credentials and endpoints passed to a constructor belong to that path and to
|
|
306
|
+
paths derived from it (`/`, `parent`, `with_name`, `with_segments`, listing
|
|
307
|
+
children). Independently constructed paths resolve their own credentials from
|
|
308
|
+
the environment, the keyring, or the backend's usual configuration:
|
|
309
|
+
|
|
310
|
+
```python
|
|
311
|
+
from asanypath.s3 import S3Path
|
|
312
|
+
|
|
313
|
+
p = S3Path("s3://bucket/data", endpoint_url="https://minio.local", aws_access_key_id="...",
|
|
314
|
+
aws_secret_access_key="...")
|
|
315
|
+
child = p / "part-0.parquet" # same endpoint and credentials
|
|
316
|
+
other = S3Path("s3://bucket/data") # default AWS configuration
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
For backends whose credentials authenticate against the host in the URL
|
|
320
|
+
(Artifactory, SSH, FTP), explicit credentials never follow a derived path to a
|
|
321
|
+
different host. Listing results are only yielded when they name a direct child
|
|
322
|
+
of the listed path.
|
|
323
|
+
|
|
324
|
+
Ambient (environment) credentials belong to one configured service and are only
|
|
325
|
+
sent to that service's origin (scheme, host and port). Without a configured
|
|
326
|
+
service they are not sent at all, and a warning names the missing setting:
|
|
327
|
+
|
|
328
|
+
- **HTTP(S):** `HTTP_AUTH_USER`/`HTTP_AUTH_PASSWORD` or `HTTP_AUTH_TOKEN`
|
|
329
|
+
(with optional `HTTP_AUTH_HEADER`) are only used for URLs on the origin of
|
|
330
|
+
`HTTP_AUTH_URL`, e.g. `HTTP_AUTH_URL=https://files.example.com`. On a
|
|
331
|
+
redirect to another scheme, host or port, only non-credential headers
|
|
332
|
+
(`Range`, `Accept`, conditional headers, ...) are forwarded.
|
|
333
|
+
- **Artifactory:** `ARTIFACTORY_IDENTITY_TOKEN` is only used for the service in
|
|
334
|
+
`ARTIFACTORY_BASE_URL` (or `ART_BASE_URL`). A JFrog CLI server token is only
|
|
335
|
+
used for that server's own origin.
|
|
336
|
+
- **SSH:** host keys are checked like OpenSSH. `StrictHostKeyChecking`
|
|
337
|
+
(`yes`, `ask`, `accept-new`, `no`) and `UserKnownHostsFile` are read from
|
|
338
|
+
ssh_config; the default is `ask` against `~/.ssh/known_hosts`. Interactive
|
|
339
|
+
sessions are prompted for a host with no recorded key; non-interactive ones
|
|
340
|
+
refuse it. A changed key is refused, and with `StrictHostKeyChecking no`
|
|
341
|
+
password authentication is disabled for it. Pass `known_hosts=()` (or set
|
|
342
|
+
`SSH_KNOWN_HOSTS=none`) to disable checking.
|
|
343
|
+
- **Azure `presign()`** signs a blob-scoped SAS with the account key; a
|
|
344
|
+
configured SAS token is never handed out as a presigned URL.
|
|
345
|
+
|
|
274
346
|
### Download caching (opt-in)
|
|
275
347
|
|
|
276
348
|
Reading the same object or URL twice always re-downloads it — there is **no
|
|
@@ -318,9 +390,16 @@ Behaviour and trade-offs:
|
|
|
318
390
|
payloads; SQLite metadata and transaction journals add filesystem overhead.
|
|
319
391
|
Objects larger than the budget are returned without being cached.
|
|
320
392
|
- **Byte-only native storage:** SQLite stores raw bytes, never Python pickles.
|
|
321
|
-
The database lives under `native-v1/` in the configured cache directory
|
|
393
|
+
The database lives under `native-v1/` in the configured cache directory,
|
|
394
|
+
readable only by its owner (directory `0700`, files `0600` on POSIX).
|
|
322
395
|
Legacy DiskCache files are ignored, not migrated or deleted. Multiple
|
|
323
|
-
processes can share the new store; use the same size limit
|
|
396
|
+
processes of the same user can share the new store; use the same size limit
|
|
397
|
+
across them.
|
|
398
|
+
- **Scoped to credentials.** Entries are keyed by URL plus a hash of the
|
|
399
|
+
path's credentials and endpoint, so different identities never share an
|
|
400
|
+
entry. Credentials themselves are never written to the cache. A cached entry
|
|
401
|
+
is not revalidated, so revoking an identity's access upstream does not evict
|
|
402
|
+
what it already cached.
|
|
324
403
|
- **Staleness is on you.** Entries are keyed by URL with no revalidation — a
|
|
325
404
|
cached object that changes upstream is served stale until it expires (`ttl`)
|
|
326
405
|
or is evicted. Prefer caching immutable/versioned objects, or set a `ttl`.
|
|
@@ -410,6 +489,14 @@ asanypath exists s3://bucket/file.txt
|
|
|
410
489
|
# Print file contents
|
|
411
490
|
asanypath cat s3://bucket/file.txt
|
|
412
491
|
|
|
492
|
+
# List directory in columns; directories end with "/", dotfiles need -a
|
|
493
|
+
asanypath ls s3://bucket/prefix/
|
|
494
|
+
asanypath ls -a s3://bucket/prefix/
|
|
495
|
+
|
|
496
|
+
# Long listing (size, modified) and tree view
|
|
497
|
+
asanypath ls -l s3://bucket/prefix/
|
|
498
|
+
asanypath ls -r -d 2 s3://bucket/prefix/
|
|
499
|
+
|
|
413
500
|
# List directory (Artifactory with token)
|
|
414
501
|
asanypath ls art://repo/path/ --token mytoken
|
|
415
502
|
|
|
@@ -652,11 +739,15 @@ All path implementations support:
|
|
|
652
739
|
- `download(dst, resume, chunk_size)` — stream an object to a local file, resuming an interrupted transfer
|
|
653
740
|
- `read_bytes()` / `write_bytes(data)` — `read_bytes(use_cache=True)` serves from / stores in the opt-in [download cache](#download-caching-opt-in)
|
|
654
741
|
- `read_text(encoding)` / `write_text(data, encoding)` — `read_text` also accepts `use_cache`
|
|
655
|
-
- `exists()` / `is_file()` / `is_dir()`
|
|
742
|
+
- `exists()` / `is_file()` / `is_dir()` — `exists()` is true for files and directories,
|
|
743
|
+
like a local path. On object stores (S3, GCS, Azure) a non-empty prefix is a
|
|
744
|
+
directory, looked up only when no object exists at the key; a key can be both an
|
|
745
|
+
object and a prefix, so `is_file()` and `is_dir()` may both be true. Empty
|
|
746
|
+
directories don't exist there (`mkdir()` is a no-op).
|
|
656
747
|
- `stat()` / `checksums()` (cloud backends)
|
|
657
748
|
- `mkdir(parents, exist_ok)` / `touch(exist_ok)`
|
|
658
749
|
- `unlink(missing_ok)` / `rmdir(recursive)`
|
|
659
|
-
- `iterdir()` / `rename(target)`
|
|
750
|
+
- `iterdir()` / `scandir(stat)` / `rename(target)`
|
|
660
751
|
- `get_access_policy()` / `update_access_policy(policy_patch)`
|
|
661
752
|
|
|
662
753
|
### Backend Operation Options
|
|
@@ -44,6 +44,11 @@ info = await path.stat()
|
|
|
44
44
|
async for child in path.parent.iterdir():
|
|
45
45
|
print(child.name)
|
|
46
46
|
|
|
47
|
+
# List with metadata: is_dir always; size/mtime with stat=True.
|
|
48
|
+
# Fields the listing already reports cost no extra requests.
|
|
49
|
+
async for entry in path.parent.scandir(stat=True):
|
|
50
|
+
print(entry.path.name, entry.is_dir, entry.size, entry.mtime)
|
|
51
|
+
|
|
47
52
|
# Glob
|
|
48
53
|
async for p in AsAnyPath("s3://bucket/logs/").glob("**/*.json"):
|
|
49
54
|
print(p)
|
|
@@ -77,6 +82,30 @@ with path.open("rb") as f:
|
|
|
77
82
|
Files smaller than the buffer size are fetched in one shot automatically.
|
|
78
83
|
Supported on S3, GCS, Azure, and Artifactory.
|
|
79
84
|
|
|
85
|
+
HTTP and HTTPS paths also support read-only `open("rb")` and `open("r")`
|
|
86
|
+
with both context-manager styles. These download the entire response on entry
|
|
87
|
+
and return a seekable in-memory handle, so servers do not need to support HEAD
|
|
88
|
+
or range requests. Text mode accepts `encoding`, `errors`, and `newline`.
|
|
89
|
+
Existing HTTP authentication and read-cache settings apply; anonymous URLs
|
|
90
|
+
require no token.
|
|
91
|
+
|
|
92
|
+
### Service endpoints
|
|
93
|
+
|
|
94
|
+
S3, GCS, Azure and Artifactory paths expose a read-only `endpoint_url` property:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
path = AsAnyPath("s3://bucket/key", endpoint_url="https://storage.example.com")
|
|
98
|
+
print(path.endpoint_url) # https://storage.example.com
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
This is the complete service base URL, including any service-root path such as
|
|
102
|
+
`/artifactory`, but excluding the bucket, container, repository and object path.
|
|
103
|
+
Reading it performs no I/O. For S3, it initially reflects an explicit override
|
|
104
|
+
or regional default; AWS configuration resolution during an operation can
|
|
105
|
+
update it. It is not necessarily the final per-request URL (for example, after
|
|
106
|
+
bucket addressing or redirects). Local, HTTP, SSH and FTP paths do not expose
|
|
107
|
+
this property.
|
|
108
|
+
|
|
80
109
|
### Copy and recursive delete
|
|
81
110
|
|
|
82
111
|
```python
|
|
@@ -215,6 +244,49 @@ Pure path operations (e.g. `.name`, `.parent`, joins) still work, while backend
|
|
|
215
244
|
operations (e.g. `.exists()`, `.read_bytes()`, `.open()`) raise
|
|
216
245
|
`UnsupportedProtocolError` on use.
|
|
217
246
|
|
|
247
|
+
### Credentials and derived paths
|
|
248
|
+
|
|
249
|
+
Credentials and endpoints passed to a constructor belong to that path and to
|
|
250
|
+
paths derived from it (`/`, `parent`, `with_name`, `with_segments`, listing
|
|
251
|
+
children). Independently constructed paths resolve their own credentials from
|
|
252
|
+
the environment, the keyring, or the backend's usual configuration:
|
|
253
|
+
|
|
254
|
+
```python
|
|
255
|
+
from asanypath.s3 import S3Path
|
|
256
|
+
|
|
257
|
+
p = S3Path("s3://bucket/data", endpoint_url="https://minio.local", aws_access_key_id="...",
|
|
258
|
+
aws_secret_access_key="...")
|
|
259
|
+
child = p / "part-0.parquet" # same endpoint and credentials
|
|
260
|
+
other = S3Path("s3://bucket/data") # default AWS configuration
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
For backends whose credentials authenticate against the host in the URL
|
|
264
|
+
(Artifactory, SSH, FTP), explicit credentials never follow a derived path to a
|
|
265
|
+
different host. Listing results are only yielded when they name a direct child
|
|
266
|
+
of the listed path.
|
|
267
|
+
|
|
268
|
+
Ambient (environment) credentials belong to one configured service and are only
|
|
269
|
+
sent to that service's origin (scheme, host and port). Without a configured
|
|
270
|
+
service they are not sent at all, and a warning names the missing setting:
|
|
271
|
+
|
|
272
|
+
- **HTTP(S):** `HTTP_AUTH_USER`/`HTTP_AUTH_PASSWORD` or `HTTP_AUTH_TOKEN`
|
|
273
|
+
(with optional `HTTP_AUTH_HEADER`) are only used for URLs on the origin of
|
|
274
|
+
`HTTP_AUTH_URL`, e.g. `HTTP_AUTH_URL=https://files.example.com`. On a
|
|
275
|
+
redirect to another scheme, host or port, only non-credential headers
|
|
276
|
+
(`Range`, `Accept`, conditional headers, ...) are forwarded.
|
|
277
|
+
- **Artifactory:** `ARTIFACTORY_IDENTITY_TOKEN` is only used for the service in
|
|
278
|
+
`ARTIFACTORY_BASE_URL` (or `ART_BASE_URL`). A JFrog CLI server token is only
|
|
279
|
+
used for that server's own origin.
|
|
280
|
+
- **SSH:** host keys are checked like OpenSSH. `StrictHostKeyChecking`
|
|
281
|
+
(`yes`, `ask`, `accept-new`, `no`) and `UserKnownHostsFile` are read from
|
|
282
|
+
ssh_config; the default is `ask` against `~/.ssh/known_hosts`. Interactive
|
|
283
|
+
sessions are prompted for a host with no recorded key; non-interactive ones
|
|
284
|
+
refuse it. A changed key is refused, and with `StrictHostKeyChecking no`
|
|
285
|
+
password authentication is disabled for it. Pass `known_hosts=()` (or set
|
|
286
|
+
`SSH_KNOWN_HOSTS=none`) to disable checking.
|
|
287
|
+
- **Azure `presign()`** signs a blob-scoped SAS with the account key; a
|
|
288
|
+
configured SAS token is never handed out as a presigned URL.
|
|
289
|
+
|
|
218
290
|
### Download caching (opt-in)
|
|
219
291
|
|
|
220
292
|
Reading the same object or URL twice always re-downloads it — there is **no
|
|
@@ -262,9 +334,16 @@ Behaviour and trade-offs:
|
|
|
262
334
|
payloads; SQLite metadata and transaction journals add filesystem overhead.
|
|
263
335
|
Objects larger than the budget are returned without being cached.
|
|
264
336
|
- **Byte-only native storage:** SQLite stores raw bytes, never Python pickles.
|
|
265
|
-
The database lives under `native-v1/` in the configured cache directory
|
|
337
|
+
The database lives under `native-v1/` in the configured cache directory,
|
|
338
|
+
readable only by its owner (directory `0700`, files `0600` on POSIX).
|
|
266
339
|
Legacy DiskCache files are ignored, not migrated or deleted. Multiple
|
|
267
|
-
processes can share the new store; use the same size limit
|
|
340
|
+
processes of the same user can share the new store; use the same size limit
|
|
341
|
+
across them.
|
|
342
|
+
- **Scoped to credentials.** Entries are keyed by URL plus a hash of the
|
|
343
|
+
path's credentials and endpoint, so different identities never share an
|
|
344
|
+
entry. Credentials themselves are never written to the cache. A cached entry
|
|
345
|
+
is not revalidated, so revoking an identity's access upstream does not evict
|
|
346
|
+
what it already cached.
|
|
268
347
|
- **Staleness is on you.** Entries are keyed by URL with no revalidation — a
|
|
269
348
|
cached object that changes upstream is served stale until it expires (`ttl`)
|
|
270
349
|
or is evicted. Prefer caching immutable/versioned objects, or set a `ttl`.
|
|
@@ -354,6 +433,14 @@ asanypath exists s3://bucket/file.txt
|
|
|
354
433
|
# Print file contents
|
|
355
434
|
asanypath cat s3://bucket/file.txt
|
|
356
435
|
|
|
436
|
+
# List directory in columns; directories end with "/", dotfiles need -a
|
|
437
|
+
asanypath ls s3://bucket/prefix/
|
|
438
|
+
asanypath ls -a s3://bucket/prefix/
|
|
439
|
+
|
|
440
|
+
# Long listing (size, modified) and tree view
|
|
441
|
+
asanypath ls -l s3://bucket/prefix/
|
|
442
|
+
asanypath ls -r -d 2 s3://bucket/prefix/
|
|
443
|
+
|
|
357
444
|
# List directory (Artifactory with token)
|
|
358
445
|
asanypath ls art://repo/path/ --token mytoken
|
|
359
446
|
|
|
@@ -596,11 +683,15 @@ All path implementations support:
|
|
|
596
683
|
- `download(dst, resume, chunk_size)` — stream an object to a local file, resuming an interrupted transfer
|
|
597
684
|
- `read_bytes()` / `write_bytes(data)` — `read_bytes(use_cache=True)` serves from / stores in the opt-in [download cache](#download-caching-opt-in)
|
|
598
685
|
- `read_text(encoding)` / `write_text(data, encoding)` — `read_text` also accepts `use_cache`
|
|
599
|
-
- `exists()` / `is_file()` / `is_dir()`
|
|
686
|
+
- `exists()` / `is_file()` / `is_dir()` — `exists()` is true for files and directories,
|
|
687
|
+
like a local path. On object stores (S3, GCS, Azure) a non-empty prefix is a
|
|
688
|
+
directory, looked up only when no object exists at the key; a key can be both an
|
|
689
|
+
object and a prefix, so `is_file()` and `is_dir()` may both be true. Empty
|
|
690
|
+
directories don't exist there (`mkdir()` is a no-op).
|
|
600
691
|
- `stat()` / `checksums()` (cloud backends)
|
|
601
692
|
- `mkdir(parents, exist_ok)` / `touch(exist_ok)`
|
|
602
693
|
- `unlink(missing_ok)` / `rmdir(recursive)`
|
|
603
|
-
- `iterdir()` / `rename(target)`
|
|
694
|
+
- `iterdir()` / `scandir(stat)` / `rename(target)`
|
|
604
695
|
- `get_access_policy()` / `update_access_policy(policy_patch)`
|
|
605
696
|
|
|
606
697
|
### Backend Operation Options
|
|
@@ -4,17 +4,23 @@
|
|
|
4
4
|
# license that can be found in the LICENSE file or at
|
|
5
5
|
# https://opensource.org/licenses/MIT.
|
|
6
6
|
|
|
7
|
+
import re
|
|
8
|
+
|
|
7
9
|
from hatchling.metadata.plugin.interface import MetadataHookInterface
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
class PinNativeHook(MetadataHookInterface):
|
|
11
|
-
"""Provide dependencies, pinning asanypath-native to asanypath's
|
|
13
|
+
"""Provide dependencies, pinning asanypath-native to asanypath's release.
|
|
14
|
+
|
|
15
|
+
``~=X.Y.Z`` requires at least the same patch release (fixes and APIs the
|
|
16
|
+
Python code relies on) while allowing later patches of the same minor.
|
|
17
|
+
"""
|
|
12
18
|
|
|
13
19
|
def update(self, metadata: dict) -> None:
|
|
14
|
-
major, minor,
|
|
20
|
+
major, minor, patch = re.match(r"(\d+)\.(\d+)\.(\d+)", metadata["version"]).groups()
|
|
15
21
|
metadata["dependencies"] = [
|
|
16
22
|
"anyio>=4",
|
|
17
|
-
f"asanypath-native~={major}.{minor}.
|
|
23
|
+
f"asanypath-native~={major}.{minor}.{patch}",
|
|
18
24
|
"msgspec>=0.22.0",
|
|
19
25
|
"yarl>=1.2",
|
|
20
26
|
]
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Copyright (C) 2026 Axis Communications AB, Lund, Sweden
|
|
2
|
+
#
|
|
3
|
+
# Use of this source code is governed by an MIT-style
|
|
4
|
+
# license that can be found in the LICENSE file or at
|
|
5
|
+
# https://opensource.org/licenses/MIT.
|
|
6
|
+
|
|
7
|
+
from importlib import import_module
|
|
8
|
+
from importlib.util import find_spec
|
|
9
|
+
from typing import TYPE_CHECKING, Any
|
|
10
|
+
|
|
11
|
+
from asanypath.asanypath import (
|
|
12
|
+
PROTOCOL_MAP,
|
|
13
|
+
AsAnyPath,
|
|
14
|
+
AsAnyPurePath,
|
|
15
|
+
list_protocols,
|
|
16
|
+
register_protocol,
|
|
17
|
+
)
|
|
18
|
+
from asanypath.exceptions import (
|
|
19
|
+
AsAnyPathError,
|
|
20
|
+
InvalidPathError,
|
|
21
|
+
PathIsADirectoryError,
|
|
22
|
+
PathNotADirectoryError,
|
|
23
|
+
PathNotFoundError,
|
|
24
|
+
UnsupportedProtocolError,
|
|
25
|
+
)
|
|
26
|
+
from asanypath.unsupported import UnsupportedProtocolPath
|
|
27
|
+
|
|
28
|
+
if TYPE_CHECKING:
|
|
29
|
+
from asanypath._transfer import TransferBudget
|
|
30
|
+
from asanypath.artifactory import ArtifactoryPath
|
|
31
|
+
from asanypath.azure import AzurePath
|
|
32
|
+
from asanypath.cache import configure_cache
|
|
33
|
+
from asanypath.cloud import CloudPathMixin
|
|
34
|
+
from asanypath.common import CommonPurePathMixin, DirEntry
|
|
35
|
+
from asanypath.ftp import FTPPath, FTPSPath # noqa: F401
|
|
36
|
+
from asanypath.gcs import GCSPath
|
|
37
|
+
from asanypath.local import AsyncPath, SyncPath
|
|
38
|
+
from asanypath.options import AccessGrant, AccessPolicy, AccessPolicyPatch, BackendOptions
|
|
39
|
+
from asanypath.s3 import S3Path
|
|
40
|
+
from asanypath.ssh import SSHPath
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
from asanypath._version import __version__
|
|
44
|
+
except ModuleNotFoundError: # pragma: no cover
|
|
45
|
+
__version__ = "0.0.0-dev"
|
|
46
|
+
|
|
47
|
+
# Backends load on first attribute access, so importing one never pays for all.
|
|
48
|
+
_LAZY_EXPORTS = {
|
|
49
|
+
"TransferBudget": "asanypath._transfer",
|
|
50
|
+
"ArtifactoryPath": "asanypath.artifactory",
|
|
51
|
+
"AzurePath": "asanypath.azure",
|
|
52
|
+
"configure_cache": "asanypath.cache",
|
|
53
|
+
"CloudPathMixin": "asanypath.cloud",
|
|
54
|
+
"CommonPurePathMixin": "asanypath.common",
|
|
55
|
+
"DirEntry": "asanypath.common",
|
|
56
|
+
"FTPPath": "asanypath.ftp",
|
|
57
|
+
"FTPSPath": "asanypath.ftp",
|
|
58
|
+
"GCSPath": "asanypath.gcs",
|
|
59
|
+
"AsyncPath": "asanypath.local",
|
|
60
|
+
"SyncPath": "asanypath.local",
|
|
61
|
+
"AccessGrant": "asanypath.options",
|
|
62
|
+
"AccessPolicy": "asanypath.options",
|
|
63
|
+
"AccessPolicyPatch": "asanypath.options",
|
|
64
|
+
"BackendOptions": "asanypath.options",
|
|
65
|
+
"S3Path": "asanypath.s3",
|
|
66
|
+
"SSHPath": "asanypath.ssh",
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def __getattr__(name: str) -> Any:
|
|
71
|
+
module = _LAZY_EXPORTS.get(name)
|
|
72
|
+
if module is None:
|
|
73
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
74
|
+
value = getattr(import_module(module), name)
|
|
75
|
+
globals()[name] = value
|
|
76
|
+
return value
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def __dir__() -> list[str]:
|
|
80
|
+
return sorted({*globals(), *_LAZY_EXPORTS})
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
__all__ = [
|
|
84
|
+
"AsAnyPurePath",
|
|
85
|
+
"AsAnyPath",
|
|
86
|
+
"AsyncPath",
|
|
87
|
+
"SyncPath",
|
|
88
|
+
"TransferBudget",
|
|
89
|
+
"BackendOptions",
|
|
90
|
+
"AccessGrant",
|
|
91
|
+
"AccessPolicy",
|
|
92
|
+
"AccessPolicyPatch",
|
|
93
|
+
"S3Path",
|
|
94
|
+
"CloudPathMixin",
|
|
95
|
+
"CommonPurePathMixin",
|
|
96
|
+
"DirEntry",
|
|
97
|
+
"GCSPath",
|
|
98
|
+
"AzurePath",
|
|
99
|
+
"ArtifactoryPath",
|
|
100
|
+
"SSHPath",
|
|
101
|
+
"configure_cache",
|
|
102
|
+
"register_protocol",
|
|
103
|
+
"list_protocols",
|
|
104
|
+
"AsAnyPathError",
|
|
105
|
+
"InvalidPathError",
|
|
106
|
+
"UnsupportedProtocolError",
|
|
107
|
+
"UnsupportedProtocolPath",
|
|
108
|
+
"PathNotFoundError",
|
|
109
|
+
"PathIsADirectoryError",
|
|
110
|
+
"PathNotADirectoryError",
|
|
111
|
+
"PROTOCOL_MAP",
|
|
112
|
+
]
|
|
113
|
+
|
|
114
|
+
if find_spec("aioftp") is not None:
|
|
115
|
+
__all__.extend(["FTPPath", "FTPSPath"])
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Copyright (C) 2026 Axis Communications AB, Lund, Sweden
|
|
2
|
+
#
|
|
3
|
+
# Use of this source code is governed by an MIT-style
|
|
4
|
+
# license that can be found in the LICENSE file or at
|
|
5
|
+
# https://opensource.org/licenses/MIT.
|
|
6
|
+
|
|
7
|
+
"""Whether backends may prompt the user on the terminal."""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import sys
|
|
12
|
+
from os import getenv
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def interactive() -> bool:
|
|
16
|
+
"""Whether a backend may prompt the user (credentials, host keys)."""
|
|
17
|
+
if getenv("ASANYPATH_INTERACTIVE") == "0":
|
|
18
|
+
return False
|
|
19
|
+
try:
|
|
20
|
+
return sys.stdin.isatty()
|
|
21
|
+
except (AttributeError, ValueError): # pragma: no cover
|
|
22
|
+
return False # pragma: no cover
|
|
@@ -384,14 +384,16 @@ def run_sync_maybe(value: Any) -> Any:
|
|
|
384
384
|
|
|
385
385
|
|
|
386
386
|
async def async_destination_state(src: Any, dst: Any) -> tuple[bool, bool, bool]:
|
|
387
|
-
"""Return ``(needs_copy, same_path, destination_exists)``.
|
|
387
|
+
"""Return ``(needs_copy, same_path, destination_exists)``.
|
|
388
|
+
|
|
389
|
+
Only an existing *file* at ``dst`` counts: one cheap check (a HEAD on
|
|
390
|
+
object stores, which treat any non-empty prefix as a directory).
|
|
391
|
+
"""
|
|
388
392
|
same_path = str(src) == str(dst)
|
|
389
393
|
if same_path:
|
|
390
394
|
return (False, True, True)
|
|
391
|
-
if not await dst.
|
|
395
|
+
if not await dst.is_file():
|
|
392
396
|
return (True, False, False)
|
|
393
|
-
if await dst.is_dir():
|
|
394
|
-
raise IsADirectoryError(21, f"Is a directory: '{dst}'")
|
|
395
397
|
|
|
396
398
|
try:
|
|
397
399
|
src_checksums = _normalized_checksums(await src.checksums())
|
|
@@ -409,14 +411,12 @@ async def async_destination_state(src: Any, dst: Any) -> tuple[bool, bool, bool]
|
|
|
409
411
|
|
|
410
412
|
|
|
411
413
|
def sync_destination_state(src: Any, dst: Any) -> tuple[bool, bool, bool]:
|
|
412
|
-
"""Return ``(needs_copy, same_path, destination_exists)
|
|
414
|
+
"""Return ``(needs_copy, same_path, destination_exists)``; see the async variant."""
|
|
413
415
|
same_path = str(src) == str(dst)
|
|
414
416
|
if same_path:
|
|
415
417
|
return (False, True, True)
|
|
416
|
-
if not run_sync_maybe(dst.
|
|
418
|
+
if not run_sync_maybe(dst.is_file()):
|
|
417
419
|
return (True, False, False)
|
|
418
|
-
if run_sync_maybe(dst.is_dir()):
|
|
419
|
-
raise IsADirectoryError(21, f"Is a directory: '{dst}'")
|
|
420
420
|
|
|
421
421
|
src_checksums = _normalized_checksums(src.checksums())
|
|
422
422
|
dst_checksums = _normalized_checksums(run_sync_maybe(dst.checksums()))
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '2.
|
|
22
|
-
__version_tuple__ = version_tuple = (2,
|
|
21
|
+
__version__ = version = '2.4.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (2, 4, 0)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|