asanypath 2.3.2__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.2 → asanypath-2.4.0}/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
- {asanypath-2.3.2 → asanypath-2.4.0}/CODE_OF_CONDUCT.md +1 -1
- {asanypath-2.3.2 → asanypath-2.4.0}/CONTRIBUTING.md +1 -1
- {asanypath-2.3.2 → asanypath-2.4.0}/PKG-INFO +45 -4
- {asanypath-2.3.2 → asanypath-2.4.0}/README.md +43 -2
- asanypath-2.4.0/src/asanypath/__init__.py +115 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/_transfer.py +8 -8
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/_version.py +2 -2
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/artifactory.py +34 -38
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/asanypath.py +63 -34
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/azure.py +2 -4
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/cli.py +117 -129
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/cloud.py +81 -61
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/common.py +92 -1
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/ftp.py +23 -20
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/gcs.py +2 -4
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/http.py +19 -7
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/local.py +31 -1
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/s3.py +2 -4
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/ssh.py +7 -4
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/sync.py +6 -1
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_artifactory.py +3 -3
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_asanypath.py +46 -1
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_azure.py +15 -45
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_cli.py +49 -76
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_cloudpathmixin.py +58 -25
- asanypath-2.4.0/tests/test_endpoints.py +93 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_ftp.py +26 -1
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_gcs.py +15 -49
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_http.py +109 -3
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_isolation.py +9 -4
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_local.py +2 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_s3.py +28 -67
- asanypath-2.4.0/tests/test_scandir.py +149 -0
- asanypath-2.3.2/SECURITY.md +0 -18
- asanypath-2.3.2/src/asanypath/__init__.py +0 -85
- {asanypath-2.3.2 → asanypath-2.4.0}/.copilot/skills/async-python-lib/SKILL.md +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/.copilot/skills/gitguro/SKILL.md +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/.github/CODEOWNERS +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/.github/dependabot.yml +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/.github/workflows/publish.yml +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/.github/workflows/unittests.yml +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/.gitignore +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/.pre-commit-config.yaml +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/LICENSE +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/asanypath.png +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/compose.yml +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/hatch_build.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/pyproject.toml +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/scripts/bench.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/scripts/bench_upload.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/__init__.pyi +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/_backend_opts.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/_credstore.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/_prompt.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/_resume.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/asanypath.pyi +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/batcher.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/cache.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/exceptions.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/options.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/py.typed +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/src/asanypath/unsupported.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/__init__.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/conftest.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_backend_options.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_batcher.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_cache.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_commonpathmixin.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_credstore.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_http_auth.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_options.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_py_typed.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_resume.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_ssh.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_ssh_hostkeys.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_sync.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_syncpath.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_transport_hardening.py +0 -0
- {asanypath-2.3.2 → asanypath-2.4.0}/tests/test_unsupported_path.py +0 -0
- {asanypath-2.3.2 → 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).
|
|
@@ -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
|
|
@@ -460,6 +489,14 @@ asanypath exists s3://bucket/file.txt
|
|
|
460
489
|
# Print file contents
|
|
461
490
|
asanypath cat s3://bucket/file.txt
|
|
462
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
|
+
|
|
463
500
|
# List directory (Artifactory with token)
|
|
464
501
|
asanypath ls art://repo/path/ --token mytoken
|
|
465
502
|
|
|
@@ -702,11 +739,15 @@ All path implementations support:
|
|
|
702
739
|
- `download(dst, resume, chunk_size)` — stream an object to a local file, resuming an interrupted transfer
|
|
703
740
|
- `read_bytes()` / `write_bytes(data)` — `read_bytes(use_cache=True)` serves from / stores in the opt-in [download cache](#download-caching-opt-in)
|
|
704
741
|
- `read_text(encoding)` / `write_text(data, encoding)` — `read_text` also accepts `use_cache`
|
|
705
|
-
- `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).
|
|
706
747
|
- `stat()` / `checksums()` (cloud backends)
|
|
707
748
|
- `mkdir(parents, exist_ok)` / `touch(exist_ok)`
|
|
708
749
|
- `unlink(missing_ok)` / `rmdir(recursive)`
|
|
709
|
-
- `iterdir()` / `rename(target)`
|
|
750
|
+
- `iterdir()` / `scandir(stat)` / `rename(target)`
|
|
710
751
|
- `get_access_policy()` / `update_access_policy(policy_patch)`
|
|
711
752
|
|
|
712
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
|
|
@@ -404,6 +433,14 @@ asanypath exists s3://bucket/file.txt
|
|
|
404
433
|
# Print file contents
|
|
405
434
|
asanypath cat s3://bucket/file.txt
|
|
406
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
|
+
|
|
407
444
|
# List directory (Artifactory with token)
|
|
408
445
|
asanypath ls art://repo/path/ --token mytoken
|
|
409
446
|
|
|
@@ -646,11 +683,15 @@ All path implementations support:
|
|
|
646
683
|
- `download(dst, resume, chunk_size)` — stream an object to a local file, resuming an interrupted transfer
|
|
647
684
|
- `read_bytes()` / `write_bytes(data)` — `read_bytes(use_cache=True)` serves from / stores in the opt-in [download cache](#download-caching-opt-in)
|
|
648
685
|
- `read_text(encoding)` / `write_text(data, encoding)` — `read_text` also accepts `use_cache`
|
|
649
|
-
- `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).
|
|
650
691
|
- `stat()` / `checksums()` (cloud backends)
|
|
651
692
|
- `mkdir(parents, exist_ok)` / `touch(exist_ok)`
|
|
652
693
|
- `unlink(missing_ok)` / `rmdir(recursive)`
|
|
653
|
-
- `iterdir()` / `rename(target)`
|
|
694
|
+
- `iterdir()` / `scandir(stat)` / `rename(target)`
|
|
654
695
|
- `get_access_policy()` / `update_access_policy(policy_patch)`
|
|
655
696
|
|
|
656
697
|
### Backend Operation Options
|
|
@@ -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"])
|
|
@@ -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
|
|
@@ -13,7 +13,7 @@ import json
|
|
|
13
13
|
import os
|
|
14
14
|
import shutil
|
|
15
15
|
import tempfile
|
|
16
|
-
from collections.abc import
|
|
16
|
+
from collections.abc import Mapping
|
|
17
17
|
from datetime import datetime, timezone
|
|
18
18
|
from os import getenv
|
|
19
19
|
from pathlib import Path
|
|
@@ -23,7 +23,7 @@ from typing import TYPE_CHECKING, Literal
|
|
|
23
23
|
import msgspec
|
|
24
24
|
|
|
25
25
|
if TYPE_CHECKING:
|
|
26
|
-
|
|
26
|
+
pass
|
|
27
27
|
|
|
28
28
|
from asanypath_native import (
|
|
29
29
|
art_copy_batch,
|
|
@@ -39,7 +39,8 @@ from asanypath_native import (
|
|
|
39
39
|
art_storage_info,
|
|
40
40
|
)
|
|
41
41
|
|
|
42
|
-
from asanypath.cloud import CloudPathMixin, _service_origin
|
|
42
|
+
from asanypath.cloud import CloudPathMixin, ServiceEndpointMixin, _service_origin
|
|
43
|
+
from asanypath.common import DirEntry
|
|
43
44
|
from asanypath.options import (
|
|
44
45
|
UPLOAD_CHUNK_SIZE,
|
|
45
46
|
AccessGrant,
|
|
@@ -74,7 +75,7 @@ def _jfrog_conf_token(base_url: str) -> str | None:
|
|
|
74
75
|
return None
|
|
75
76
|
|
|
76
77
|
|
|
77
|
-
class ArtifactoryPath(CloudPathMixin):
|
|
78
|
+
class ArtifactoryPath(CloudPathMixin, ServiceEndpointMixin):
|
|
78
79
|
"""Async path implementation for JFrog Artifactory with Bearer token auth.
|
|
79
80
|
|
|
80
81
|
Extends HTTPSPath to add authentication via Authorization: Bearer <token> header
|
|
@@ -135,19 +136,11 @@ class ArtifactoryPath(CloudPathMixin):
|
|
|
135
136
|
ValueError: If token is not provided and ARTIFACTORY_IDENTITY_TOKEN env var is not set.
|
|
136
137
|
"""
|
|
137
138
|
super().__init__(*args, **kwargs)
|
|
138
|
-
|
|
139
|
-
raw = str(self)[len("art://") :] # "host/artifactory/repo/path"
|
|
140
|
-
idx = raw.find("/artifactory/")
|
|
141
|
-
if idx >= 0:
|
|
142
|
-
self._base_url = raw[: idx + len("/artifactory")]
|
|
143
|
-
self._repo_path = raw[idx + len("/artifactory/") :]
|
|
144
|
-
else:
|
|
145
|
-
self._base_url = raw.split("/")[0]
|
|
146
|
-
self._repo_path = "/".join(raw.split("/")[1:])
|
|
139
|
+
self._bind_path_attrs()
|
|
147
140
|
|
|
148
141
|
from asanypath import _credstore
|
|
149
142
|
|
|
150
|
-
cred_key = f"art:{self.
|
|
143
|
+
cred_key = f"art:{self._service_key}"
|
|
151
144
|
known = ArtifactoryPath._service_tokens
|
|
152
145
|
if token:
|
|
153
146
|
# Persist user-supplied tokens once per service, not per derived path.
|
|
@@ -159,7 +152,7 @@ class ArtifactoryPath(CloudPathMixin):
|
|
|
159
152
|
else:
|
|
160
153
|
self._token = self._env_token() or known.get(cred_key)
|
|
161
154
|
if not self._token:
|
|
162
|
-
self._token = _credstore.load(cred_key) or _jfrog_conf_token(self.
|
|
155
|
+
self._token = _credstore.load(cred_key) or _jfrog_conf_token(self._service_key)
|
|
163
156
|
if self._token:
|
|
164
157
|
known[cred_key] = self._token
|
|
165
158
|
if not self._token:
|
|
@@ -189,13 +182,22 @@ class ArtifactoryPath(CloudPathMixin):
|
|
|
189
182
|
token = self.env_config.token
|
|
190
183
|
if token and self._ambient_credentials_allowed(
|
|
191
184
|
self._resolve_base_url_prefix(),
|
|
192
|
-
self.
|
|
185
|
+
self._service_key,
|
|
193
186
|
credential="ARTIFACTORY_IDENTITY_TOKEN",
|
|
194
187
|
setting="ARTIFACTORY_BASE_URL",
|
|
195
188
|
):
|
|
196
189
|
return token
|
|
197
190
|
return None
|
|
198
191
|
|
|
192
|
+
@property
|
|
193
|
+
def _service_key(self) -> str:
|
|
194
|
+
"""``host/artifactory``: the service key for the keyring, the JFrog CLI
|
|
195
|
+
config and token scoping. Derived as before endpoint normalization so
|
|
196
|
+
stored credentials keep matching."""
|
|
197
|
+
raw = str(self)[len("art://") :]
|
|
198
|
+
idx = raw.find("/artifactory/")
|
|
199
|
+
return raw[: idx + len("/artifactory")] if idx >= 0 else raw.split("/")[0]
|
|
200
|
+
|
|
199
201
|
@property
|
|
200
202
|
def _item_path(self) -> str:
|
|
201
203
|
return self._repo_path
|
|
@@ -203,11 +205,13 @@ class ArtifactoryPath(CloudPathMixin):
|
|
|
203
205
|
def _bind_path_attrs(self) -> None:
|
|
204
206
|
raw = str(self)[len("art://") :]
|
|
205
207
|
idx = raw.find("/artifactory/")
|
|
208
|
+
if idx < 0 and raw.rstrip("/").endswith("/artifactory"):
|
|
209
|
+
idx = len(raw.rstrip("/")) - len("/artifactory")
|
|
206
210
|
if idx >= 0:
|
|
207
|
-
self.
|
|
211
|
+
self._endpoint_url = "https://" + raw[: idx + len("/artifactory")]
|
|
208
212
|
self._repo_path = raw[idx + len("/artifactory/") :]
|
|
209
213
|
else:
|
|
210
|
-
self.
|
|
214
|
+
self._endpoint_url = "https://" + raw.split("/")[0]
|
|
211
215
|
self._repo_path = "/".join(raw.split("/")[1:])
|
|
212
216
|
self._is_folder = None
|
|
213
217
|
self._cached_info = None
|
|
@@ -215,14 +219,14 @@ class ArtifactoryPath(CloudPathMixin):
|
|
|
215
219
|
@property
|
|
216
220
|
def _native_kwargs(self) -> dict:
|
|
217
221
|
return {
|
|
218
|
-
"base_url": self.
|
|
222
|
+
"base_url": self._endpoint_url,
|
|
219
223
|
"token": self._token,
|
|
220
224
|
}
|
|
221
225
|
|
|
222
226
|
def _identity_parts(self) -> tuple:
|
|
223
227
|
# Keep cache identity scoped even when the token came from keyring/JFrog.
|
|
224
228
|
token_fp = hashlib.sha256(self._token.encode()).hexdigest()
|
|
225
|
-
return (*super()._identity_parts(), self.
|
|
229
|
+
return (*super()._identity_parts(), self._service_key, token_fp)
|
|
226
230
|
|
|
227
231
|
# ------------------------------------------------------------------
|
|
228
232
|
# Backend-specific operations
|
|
@@ -315,44 +319,36 @@ class ArtifactoryPath(CloudPathMixin):
|
|
|
315
319
|
except (FileNotFoundError, PermissionError):
|
|
316
320
|
return False
|
|
317
321
|
|
|
318
|
-
async def
|
|
322
|
+
async def _list_entries(self, *, stat: bool = False, fresh: bool = False) -> list[DirEntry]:
|
|
319
323
|
containers = await self._list_containers()
|
|
320
324
|
if containers is not None:
|
|
321
|
-
for uri in containers
|
|
322
|
-
yield self._child(uri)
|
|
323
|
-
return
|
|
325
|
+
return [DirEntry(self._child(uri), True) for uri in containers]
|
|
324
326
|
batcher = self._get_batcher()
|
|
325
327
|
results = await batcher.list(
|
|
326
328
|
item=self._repo_path,
|
|
327
|
-
base_url=self.
|
|
329
|
+
base_url=self._endpoint_url,
|
|
328
330
|
token=self._token,
|
|
329
331
|
)
|
|
330
332
|
base = str(self).rstrip("/")
|
|
333
|
+
entries = []
|
|
331
334
|
for uri, is_folder in results:
|
|
332
335
|
child_name = uri.rstrip("/").rsplit("/", 1)[-1]
|
|
333
336
|
child = self._confined_child(f"{base}/{child_name}", _is_folder=is_folder)
|
|
334
337
|
if child is not None:
|
|
335
|
-
|
|
338
|
+
entries.append(DirEntry(child, is_folder))
|
|
339
|
+
return entries
|
|
336
340
|
|
|
337
341
|
async def _list_containers(self) -> list[str] | None:
|
|
338
342
|
"""List repositories when at the server root (``art://<host>/artifactory/``).
|
|
339
343
|
|
|
340
344
|
Returns None once a repository is selected, so normal object listing
|
|
341
|
-
proceeds.
|
|
342
|
-
shorthand parse where the trailing ``artifactory`` lands in the repo
|
|
343
|
-
slot.
|
|
345
|
+
proceeds.
|
|
344
346
|
"""
|
|
345
|
-
base = self.
|
|
346
|
-
|
|
347
|
-
if repo == "artifactory":
|
|
348
|
-
base = f"{base}/artifactory"
|
|
349
|
-
repo = ""
|
|
350
|
-
if repo:
|
|
351
|
-
return None
|
|
352
|
-
if not base or base == "artifactory":
|
|
347
|
+
base = self._endpoint_url
|
|
348
|
+
if self._repo_path.strip("/"):
|
|
353
349
|
return None
|
|
354
350
|
names = await art_list_repos(base_url=base, token=self._token, use_h2=False)
|
|
355
|
-
return [f"art://{base}/{name}" for name in names]
|
|
351
|
+
return [f"art://{base.removeprefix('https://')}/{name}" for name in names]
|
|
356
352
|
|
|
357
353
|
@staticmethod
|
|
358
354
|
def _parse_art_ts(ts: str | None) -> float | None:
|
|
@@ -8,6 +8,7 @@ from __future__ import annotations
|
|
|
8
8
|
|
|
9
9
|
from abc import ABC, abstractmethod
|
|
10
10
|
from collections.abc import AsyncIterator, Callable
|
|
11
|
+
from importlib import import_module
|
|
11
12
|
from os import PathLike, getenv, stat_result
|
|
12
13
|
from pathlib import Path
|
|
13
14
|
from typing import TYPE_CHECKING, Any, TypeVar
|
|
@@ -23,58 +24,82 @@ from asanypath.exceptions import InvalidPathError
|
|
|
23
24
|
from asanypath.unsupported import UnsupportedProtocolPath
|
|
24
25
|
|
|
25
26
|
if TYPE_CHECKING:
|
|
27
|
+
from asanypath.common import DirEntry
|
|
26
28
|
from asanypath.options import AccessPolicy, AccessPolicyPatch, BackendOptions
|
|
27
29
|
|
|
28
30
|
|
|
31
|
+
# Built-in schemes, imported on first lookup so a local path never pays for
|
|
32
|
+
# cloud backends.
|
|
33
|
+
_BUILTIN_PROTOCOLS = {
|
|
34
|
+
"file": ("asanypath.local", "AsyncPath"),
|
|
35
|
+
"s3": ("asanypath.s3", "S3Path"),
|
|
36
|
+
"gs": ("asanypath.gcs", "GCSPath"),
|
|
37
|
+
"az": ("asanypath.azure", "AzurePath"),
|
|
38
|
+
"http": ("asanypath.http", "HTTPPath"),
|
|
39
|
+
"https": ("asanypath.http", "HTTPSPath"),
|
|
40
|
+
"art": ("asanypath.artifactory", "ArtifactoryPath"),
|
|
41
|
+
"ssh": ("asanypath.ssh", "SSHPath"),
|
|
42
|
+
"ftp": ("asanypath.ftp", "FTPPath"),
|
|
43
|
+
"ftps": ("asanypath.ftp", "FTPSPath"),
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
29
47
|
class _LazyDict(dict):
|
|
48
|
+
def __init__(self) -> None:
|
|
49
|
+
super().__init__()
|
|
50
|
+
self._pending = dict(_BUILTIN_PROTOCOLS)
|
|
51
|
+
|
|
52
|
+
def _load(self, key) -> bool:
|
|
53
|
+
spec = self._pending.pop(key, None)
|
|
54
|
+
if spec is None:
|
|
55
|
+
return False
|
|
56
|
+
try:
|
|
57
|
+
klass = getattr(import_module(spec[0]), spec[1])
|
|
58
|
+
except ImportError: # optional backend dependency not installed
|
|
59
|
+
return False
|
|
60
|
+
self.setdefault(key, klass)
|
|
61
|
+
return True
|
|
62
|
+
|
|
30
63
|
def _ensure(self):
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
from asanypath.s3 import S3Path
|
|
38
|
-
|
|
39
|
-
self.update(
|
|
40
|
-
file=AsyncPath,
|
|
41
|
-
s3=S3Path,
|
|
42
|
-
gs=GCSPath,
|
|
43
|
-
az=AzurePath,
|
|
44
|
-
http=HTTPPath,
|
|
45
|
-
https=HTTPSPath,
|
|
46
|
-
art=ArtifactoryPath,
|
|
47
|
-
)
|
|
48
|
-
try:
|
|
49
|
-
from asanypath.ssh import SSHPath
|
|
50
|
-
|
|
51
|
-
self.update(ssh=SSHPath)
|
|
52
|
-
except ImportError:
|
|
53
|
-
pass
|
|
54
|
-
try:
|
|
55
|
-
from asanypath.ftp import FTPPath, FTPSPath
|
|
56
|
-
|
|
57
|
-
self.update(ftp=FTPPath, ftps=FTPSPath)
|
|
58
|
-
except ImportError:
|
|
59
|
-
pass
|
|
64
|
+
for key in list(self._pending):
|
|
65
|
+
self._load(key)
|
|
66
|
+
|
|
67
|
+
def __setitem__(self, key, value):
|
|
68
|
+
self._pending.pop(key, None)
|
|
69
|
+
super().__setitem__(key, value)
|
|
60
70
|
|
|
61
71
|
def items(self):
|
|
62
72
|
self._ensure()
|
|
63
73
|
return super().items()
|
|
64
74
|
|
|
75
|
+
def keys(self):
|
|
76
|
+
self._ensure()
|
|
77
|
+
return super().keys()
|
|
78
|
+
|
|
79
|
+
def values(self):
|
|
80
|
+
self._ensure()
|
|
81
|
+
return super().values()
|
|
82
|
+
|
|
65
83
|
def __iter__(self):
|
|
66
84
|
self._ensure()
|
|
67
85
|
return super().__iter__()
|
|
68
86
|
|
|
69
|
-
def
|
|
87
|
+
def __len__(self):
|
|
70
88
|
self._ensure()
|
|
89
|
+
return super().__len__()
|
|
90
|
+
|
|
91
|
+
def __contains__(self, key):
|
|
92
|
+
self._load(key)
|
|
71
93
|
return super().__contains__(key)
|
|
72
94
|
|
|
95
|
+
def get(self, key, default=None):
|
|
96
|
+
self._load(key)
|
|
97
|
+
return super().get(key, default)
|
|
98
|
+
|
|
73
99
|
def __missing__(self, key):
|
|
74
|
-
self.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return self[key] # KeyError if truly unknown
|
|
100
|
+
if self._load(key):
|
|
101
|
+
return self[key]
|
|
102
|
+
return UnsupportedProtocolPath
|
|
78
103
|
|
|
79
104
|
|
|
80
105
|
PROTOCOL_MAP = _LazyDict()
|
|
@@ -366,6 +391,10 @@ class AsAnyPath(AsAnyPurePath):
|
|
|
366
391
|
async def iterdir(self) -> AsyncIterator[Self]:
|
|
367
392
|
pass
|
|
368
393
|
|
|
394
|
+
@abstractmethod
|
|
395
|
+
async def scandir(self, *, stat: bool = False) -> AsyncIterator[DirEntry]:
|
|
396
|
+
pass
|
|
397
|
+
|
|
369
398
|
@abstractmethod
|
|
370
399
|
def lchmod(self, mode: int) -> None:
|
|
371
400
|
pass
|