asanypath 2.7.1__tar.gz → 3.0.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.7.1 → asanypath-3.0.0}/.copilot/skills/async-python-lib/SKILL.md +1 -1
- {asanypath-2.7.1 → asanypath-3.0.0}/.github/workflows/publish.yml +1 -2
- {asanypath-2.7.1 → asanypath-3.0.0}/.github/workflows/unittests.yml +1 -1
- {asanypath-2.7.1 → asanypath-3.0.0}/CONTRIBUTING.md +2 -2
- {asanypath-2.7.1 → asanypath-3.0.0}/PKG-INFO +26 -13
- {asanypath-2.7.1 → asanypath-3.0.0}/README.md +23 -9
- {asanypath-2.7.1 → asanypath-3.0.0}/pyproject.toml +5 -7
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/_version.py +2 -2
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/artifactory.py +2 -2
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/asanypath.py +52 -14
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/azure.py +2 -2
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/click.py +5 -1
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/cloud.py +7 -21
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/ftp.py +2 -2
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/http.py +88 -6
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/s3.py +2 -2
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/ssh.py +4 -7
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_asanypath.py +196 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_backend_options.py +51 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_ftp.py +3 -3
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_http.py +197 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_ssh.py +49 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/.copilot/skills/gitguro/SKILL.md +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/.github/CODEOWNERS +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/.github/dependabot.yml +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/.gitignore +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/.pre-commit-config.yaml +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/CODE_OF_CONDUCT.md +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/LICENSE +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/asanypath.png +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/compose.yml +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/hatch_build.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/scripts/bench.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/scripts/bench_rmtree.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/scripts/bench_upload.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/__init__.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/__init__.pyi +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/_backend_opts.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/_credstore.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/_prompt.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/_resume.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/_transfer.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/asanypath.pyi +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/batcher.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/cache.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/cli.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/common.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/exceptions.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/gcs.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/local.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/options.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/py.typed +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/sync.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/src/asanypath/unsupported.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/__init__.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/conftest.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_artifactory.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_auth_errors.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_azure.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_batcher.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_cache.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_cli.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_click.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_cloudpathmixin.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_commonpathmixin.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_credstore.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_endpoints.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_gcs.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_http_auth.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_isolation.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_local.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_options.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_py_typed.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_resume.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_s3.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_scandir.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_ssh_hostkeys.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_sync.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_syncpath.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_transport_hardening.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_unsupported_path.py +0 -0
- {asanypath-2.7.1 → asanypath-3.0.0}/tests/test_upload.py +0 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
Guide development of async Python libraries with clean APIs, proper typing, and thorough testing.
|
|
5
5
|
|
|
6
6
|
## Technical Stack
|
|
7
|
-
- **Python**: 3.
|
|
7
|
+
- **Python**: 3.11+ with full async/await
|
|
8
8
|
- **Package Manager**: uv (sync, run, build)
|
|
9
9
|
- **Build**: hatchling
|
|
10
10
|
- **Lint/Format**: ruff
|
|
@@ -74,7 +74,6 @@ jobs:
|
|
|
74
74
|
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7
|
|
75
75
|
with:
|
|
76
76
|
python-version: |
|
|
77
|
-
3.10
|
|
78
77
|
3.11
|
|
79
78
|
3.12
|
|
80
79
|
3.13
|
|
@@ -87,7 +86,7 @@ jobs:
|
|
|
87
86
|
working-directory: rust
|
|
88
87
|
target: ${{ matrix.target }}
|
|
89
88
|
manylinux: ${{ matrix.manylinux }}
|
|
90
|
-
args: --release --out dist --interpreter 3.
|
|
89
|
+
args: --release --out dist --interpreter 3.11 3.12 3.13 3.14 3.15
|
|
91
90
|
|
|
92
91
|
- name: Upload native wheels
|
|
93
92
|
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
|
|
@@ -30,7 +30,7 @@ jobs:
|
|
|
30
30
|
strategy:
|
|
31
31
|
fail-fast: true
|
|
32
32
|
matrix:
|
|
33
|
-
python-version: ["3.
|
|
33
|
+
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]
|
|
34
34
|
steps:
|
|
35
35
|
- name: Checkout repository
|
|
36
36
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
|
|
@@ -4,7 +4,7 @@ Thank you for contributing to AsAnyPath.
|
|
|
4
4
|
|
|
5
5
|
## Getting Started
|
|
6
6
|
|
|
7
|
-
Use Python 3.
|
|
7
|
+
Use Python 3.11 or newer and install the development dependencies:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
uv sync --extra dev
|
|
@@ -31,7 +31,7 @@ cargo check --manifest-path rust/Cargo.toml
|
|
|
31
31
|
## Pull Requests
|
|
32
32
|
|
|
33
33
|
Keep pull requests focused and include tests for changed behavior. Preserve
|
|
34
|
-
compatibility with Python 3.
|
|
34
|
+
compatibility with Python 3.11 through 3.15. Describe user-visible changes and
|
|
35
35
|
document new configuration, credentials, or backend behavior in the README.
|
|
36
36
|
|
|
37
37
|
Do not include credentials, private endpoints, customer data, or other
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: asanypath
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0.0
|
|
4
4
|
Summary: Async pathlib for local and cloud storage
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -11,16 +11,15 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
11
11
|
Classifier: Operating System :: OS Independent
|
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
|
13
13
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.11
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
17
16
|
Classifier: Programming Language :: Python :: 3.13
|
|
18
17
|
Classifier: Programming Language :: Python :: 3.14
|
|
19
18
|
Classifier: Programming Language :: Python :: 3.15
|
|
20
19
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
-
Requires-Python: >=3.
|
|
20
|
+
Requires-Python: >=3.11
|
|
22
21
|
Requires-Dist: anyio>=4
|
|
23
|
-
Requires-Dist: asanypath-native~=
|
|
22
|
+
Requires-Dist: asanypath-native~=3.0.0
|
|
24
23
|
Requires-Dist: msgspec>=0.22.0
|
|
25
24
|
Requires-Dist: yarl>=1.2
|
|
26
25
|
Provides-Extra: all
|
|
@@ -73,7 +72,7 @@ locally before connecting to a cloud account.
|
|
|
73
72
|
|
|
74
73
|
## Requirements
|
|
75
74
|
|
|
76
|
-
- Python 3.
|
|
75
|
+
- Python 3.11 through 3.15.
|
|
77
76
|
- Access credentials for each cloud service that your application uses.
|
|
78
77
|
|
|
79
78
|
S3 authentication accepts explicit keys or uses the AWS SDK credential provider
|
|
@@ -136,15 +135,15 @@ with path.open("rb") as f:
|
|
|
136
135
|
chunk = f.read(512)
|
|
137
136
|
```
|
|
138
137
|
|
|
139
|
-
|
|
140
|
-
Supported on S3, GCS, Azure, and
|
|
138
|
+
The buffer size controls prefetch; smaller files may be fetched in one shot.
|
|
139
|
+
Supported on S3, GCS, Azure, Artifactory, and HTTP/HTTPS.
|
|
141
140
|
|
|
142
|
-
HTTP and HTTPS paths
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
require no token.
|
|
141
|
+
HTTP and HTTPS paths support read-only `open("rb")` and `open("r")` with both
|
|
142
|
+
context-manager styles. They use lazy range reads when a HEAD response supplies
|
|
143
|
+
the size, falling back to a full download when HEAD or ranges are unavailable.
|
|
144
|
+
If the download cache is enabled, `open()` uses it instead of range reads.
|
|
145
|
+
Text mode accepts `encoding`, `errors`, and `newline`. Existing HTTP
|
|
146
|
+
authentication settings apply; anonymous URLs require no token.
|
|
148
147
|
|
|
149
148
|
### Service endpoints
|
|
150
149
|
|
|
@@ -612,6 +611,20 @@ syntax. Transport-managed headers such as `Host` and
|
|
|
612
611
|
visible in shell history or process listings, so use the HTTP auth environment
|
|
613
612
|
variables for secrets.
|
|
614
613
|
|
|
614
|
+
For SSH copies, config aliases can be used as `alias:path` (relative to the
|
|
615
|
+
remote home) or `ssh://alias/absolute/path`. Source overrides use constructor
|
|
616
|
+
option names, not OpenSSH directive names, and each requires a separate flag:
|
|
617
|
+
|
|
618
|
+
```sh
|
|
619
|
+
asanypath cp alias:logs/output.txt ./output.txt \
|
|
620
|
+
--src-option ssh.username=deploy \
|
|
621
|
+
--src-option ssh.port=2222 \
|
|
622
|
+
--src-option ssh.client_keys=/path/to/private-key
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
These override the corresponding config values. Passwords and other secrets
|
|
626
|
+
passed on the command line may be visible in shell history or process listings.
|
|
627
|
+
|
|
615
628
|
### Shell Completions (Beta)
|
|
616
629
|
|
|
617
630
|
Path completions are available for all subcommands that take cloud paths: `ls`, `cp`, `mv`, `rm`, `stat`, `cat`, `exists`, `touch`, `checksums`, `mkdir`, `presign`, and `sync`.
|
|
@@ -16,7 +16,7 @@ locally before connecting to a cloud account.
|
|
|
16
16
|
|
|
17
17
|
## Requirements
|
|
18
18
|
|
|
19
|
-
- Python 3.
|
|
19
|
+
- Python 3.11 through 3.15.
|
|
20
20
|
- Access credentials for each cloud service that your application uses.
|
|
21
21
|
|
|
22
22
|
S3 authentication accepts explicit keys or uses the AWS SDK credential provider
|
|
@@ -79,15 +79,15 @@ with path.open("rb") as f:
|
|
|
79
79
|
chunk = f.read(512)
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
Supported on S3, GCS, Azure, and
|
|
82
|
+
The buffer size controls prefetch; smaller files may be fetched in one shot.
|
|
83
|
+
Supported on S3, GCS, Azure, Artifactory, and HTTP/HTTPS.
|
|
84
84
|
|
|
85
|
-
HTTP and HTTPS paths
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
require no token.
|
|
85
|
+
HTTP and HTTPS paths support read-only `open("rb")` and `open("r")` with both
|
|
86
|
+
context-manager styles. They use lazy range reads when a HEAD response supplies
|
|
87
|
+
the size, falling back to a full download when HEAD or ranges are unavailable.
|
|
88
|
+
If the download cache is enabled, `open()` uses it instead of range reads.
|
|
89
|
+
Text mode accepts `encoding`, `errors`, and `newline`. Existing HTTP
|
|
90
|
+
authentication settings apply; anonymous URLs require no token.
|
|
91
91
|
|
|
92
92
|
### Service endpoints
|
|
93
93
|
|
|
@@ -555,6 +555,20 @@ syntax. Transport-managed headers such as `Host` and
|
|
|
555
555
|
visible in shell history or process listings, so use the HTTP auth environment
|
|
556
556
|
variables for secrets.
|
|
557
557
|
|
|
558
|
+
For SSH copies, config aliases can be used as `alias:path` (relative to the
|
|
559
|
+
remote home) or `ssh://alias/absolute/path`. Source overrides use constructor
|
|
560
|
+
option names, not OpenSSH directive names, and each requires a separate flag:
|
|
561
|
+
|
|
562
|
+
```sh
|
|
563
|
+
asanypath cp alias:logs/output.txt ./output.txt \
|
|
564
|
+
--src-option ssh.username=deploy \
|
|
565
|
+
--src-option ssh.port=2222 \
|
|
566
|
+
--src-option ssh.client_keys=/path/to/private-key
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
These override the corresponding config values. Passwords and other secrets
|
|
570
|
+
passed on the command line may be visible in shell history or process listings.
|
|
571
|
+
|
|
558
572
|
### Shell Completions (Beta)
|
|
559
573
|
|
|
560
574
|
Path completions are available for all subcommands that take cloud paths: `ls`, `cp`, `mv`, `rm`, `stat`, `cat`, `exists`, `touch`, `checksums`, `mkdir`, `presign`, and `sync`.
|
|
@@ -10,9 +10,8 @@ fallback-version = "0.0.0-dev"
|
|
|
10
10
|
version-file = "src/asanypath/_version.py"
|
|
11
11
|
|
|
12
12
|
[tool.uv]
|
|
13
|
-
# filelock (pre-commit -> virtualenv) has security fixes only from 4.2.1
|
|
14
|
-
|
|
15
|
-
constraint-dependencies = ["filelock>=4.2.1; python_version >= '3.11'"]
|
|
13
|
+
# filelock (pre-commit -> virtualenv) has security fixes only from 4.2.1.
|
|
14
|
+
constraint-dependencies = ["filelock>=4.2.1"]
|
|
16
15
|
|
|
17
16
|
[[tool.uv.index]]
|
|
18
17
|
url = "https://pypi.org/simple"
|
|
@@ -34,7 +33,7 @@ name = "asanypath"
|
|
|
34
33
|
dynamic = ["version", "dependencies"]
|
|
35
34
|
description = "Async pathlib for local and cloud storage"
|
|
36
35
|
readme = "README.md"
|
|
37
|
-
requires-python = ">=3.
|
|
36
|
+
requires-python = ">=3.11"
|
|
38
37
|
license = "MIT"
|
|
39
38
|
classifiers = [
|
|
40
39
|
"Development Status :: 4 - Beta",
|
|
@@ -43,7 +42,6 @@ classifiers = [
|
|
|
43
42
|
"Operating System :: OS Independent",
|
|
44
43
|
"Programming Language :: Python :: 3",
|
|
45
44
|
"Programming Language :: Python :: 3 :: Only",
|
|
46
|
-
"Programming Language :: Python :: 3.10",
|
|
47
45
|
"Programming Language :: Python :: 3.11",
|
|
48
46
|
"Programming Language :: Python :: 3.12",
|
|
49
47
|
"Programming Language :: Python :: 3.13",
|
|
@@ -85,13 +83,13 @@ asanypath = "asanypath.cli:main"
|
|
|
85
83
|
|
|
86
84
|
[tool.ruff]
|
|
87
85
|
line-length = 100
|
|
88
|
-
target-version = "
|
|
86
|
+
target-version = "py311"
|
|
89
87
|
|
|
90
88
|
[tool.ruff.lint]
|
|
91
89
|
select = ["E", "F", "I", "N", "W", "UP"]
|
|
92
90
|
|
|
93
91
|
[tool.mypy]
|
|
94
|
-
python_version = "3.
|
|
92
|
+
python_version = "3.11"
|
|
95
93
|
warn_return_any = true
|
|
96
94
|
warn_unused_configs = true
|
|
97
95
|
disallow_untyped_defs = true
|
|
@@ -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 = '
|
|
22
|
-
__version_tuple__ = version_tuple = (
|
|
21
|
+
__version__ = version = '3.0.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (3, 0, 0)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -15,7 +15,7 @@ import os
|
|
|
15
15
|
import shutil
|
|
16
16
|
import tempfile
|
|
17
17
|
from collections.abc import Mapping
|
|
18
|
-
from datetime import
|
|
18
|
+
from datetime import UTC, datetime
|
|
19
19
|
from os import getenv
|
|
20
20
|
from pathlib import Path
|
|
21
21
|
from types import SimpleNamespace
|
|
@@ -408,7 +408,7 @@ class ArtifactoryPath(CloudPathMixin, ServiceEndpointMixin):
|
|
|
408
408
|
if ts.endswith("Z"):
|
|
409
409
|
ts = ts[:-1] + "+00:00"
|
|
410
410
|
try:
|
|
411
|
-
return datetime.fromisoformat(ts).astimezone(
|
|
411
|
+
return datetime.fromisoformat(ts).astimezone(UTC).timestamp()
|
|
412
412
|
except ValueError:
|
|
413
413
|
return None
|
|
414
414
|
|
|
@@ -6,11 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
from __future__ import annotations
|
|
8
8
|
|
|
9
|
+
import os
|
|
9
10
|
from abc import ABC, abstractmethod
|
|
10
11
|
from collections.abc import AsyncIterator, Callable
|
|
11
12
|
from importlib import import_module
|
|
12
13
|
from os import PathLike, stat_result
|
|
13
14
|
from pathlib import Path, PurePosixPath
|
|
15
|
+
from threading import Lock
|
|
14
16
|
from typing import TYPE_CHECKING, Any, TypeVar
|
|
15
17
|
from urllib.parse import urlsplit
|
|
16
18
|
|
|
@@ -48,25 +50,60 @@ class _LazyDict(dict):
|
|
|
48
50
|
def __init__(self) -> None:
|
|
49
51
|
super().__init__()
|
|
50
52
|
self._pending = dict(_BUILTIN_PROTOCOLS)
|
|
53
|
+
self._lock = Lock()
|
|
54
|
+
self._loading: dict[str, int] = {}
|
|
55
|
+
self._generation = 0
|
|
56
|
+
|
|
57
|
+
def _after_fork(self):
|
|
58
|
+
self._lock = Lock()
|
|
59
|
+
self._loading.clear()
|
|
60
|
+
self._generation += 1
|
|
51
61
|
|
|
52
62
|
def _load(self, key) -> bool:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
with self._lock:
|
|
64
|
+
if super().__contains__(key):
|
|
65
|
+
self._pending.pop(key, None)
|
|
66
|
+
return True
|
|
67
|
+
spec = self._pending.get(key)
|
|
68
|
+
if spec is None:
|
|
69
|
+
return False
|
|
70
|
+
self._loading[key] = self._loading.get(key, 0) + 1
|
|
71
|
+
generation = self._generation
|
|
72
|
+
|
|
73
|
+
unavailable = False
|
|
56
74
|
try:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
75
|
+
# Do not hold the registry lock while Python's import locks are held.
|
|
76
|
+
try:
|
|
77
|
+
klass = getattr(import_module(spec[0]), spec[1])
|
|
78
|
+
except ImportError: # optional backend dependency not installed
|
|
79
|
+
unavailable = True
|
|
80
|
+
return False
|
|
81
|
+
with self._lock:
|
|
82
|
+
self.setdefault(key, klass)
|
|
83
|
+
if self._pending.get(key) == spec:
|
|
84
|
+
self._pending.pop(key)
|
|
85
|
+
return True
|
|
86
|
+
finally:
|
|
87
|
+
with self._lock:
|
|
88
|
+
if self._generation == generation:
|
|
89
|
+
remaining = self._loading[key] - 1
|
|
90
|
+
if remaining:
|
|
91
|
+
self._loading[key] = remaining
|
|
92
|
+
else:
|
|
93
|
+
del self._loading[key]
|
|
94
|
+
if unavailable and self._pending.get(key) == spec:
|
|
95
|
+
self._pending.pop(key)
|
|
62
96
|
|
|
63
97
|
def _ensure(self):
|
|
64
|
-
|
|
98
|
+
with self._lock:
|
|
99
|
+
pending = list(self._pending)
|
|
100
|
+
for key in pending:
|
|
65
101
|
self._load(key)
|
|
66
102
|
|
|
67
103
|
def __setitem__(self, key, value):
|
|
68
|
-
self.
|
|
69
|
-
|
|
104
|
+
with self._lock:
|
|
105
|
+
super().__setitem__(key, value)
|
|
106
|
+
self._pending.pop(key, None)
|
|
70
107
|
|
|
71
108
|
def items(self):
|
|
72
109
|
self._ensure()
|
|
@@ -97,12 +134,13 @@ class _LazyDict(dict):
|
|
|
97
134
|
return super().get(key, default)
|
|
98
135
|
|
|
99
136
|
def __missing__(self, key):
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return UnsupportedProtocolPath
|
|
137
|
+
self._load(key)
|
|
138
|
+
return super().get(key, UnsupportedProtocolPath)
|
|
103
139
|
|
|
104
140
|
|
|
105
141
|
PROTOCOL_MAP = _LazyDict()
|
|
142
|
+
if hasattr(os, "register_at_fork"):
|
|
143
|
+
os.register_at_fork(after_in_child=PROTOCOL_MAP._after_fork)
|
|
106
144
|
|
|
107
145
|
# Flavors whose abstract-method implementation has been validated once.
|
|
108
146
|
_VALIDATED_FLAVORS: set[type] = set()
|
|
@@ -14,7 +14,7 @@ from __future__ import annotations
|
|
|
14
14
|
|
|
15
15
|
import base64
|
|
16
16
|
from collections.abc import Mapping
|
|
17
|
-
from datetime import
|
|
17
|
+
from datetime import UTC, datetime
|
|
18
18
|
from os import getenv
|
|
19
19
|
from types import SimpleNamespace
|
|
20
20
|
from uuid import uuid4
|
|
@@ -264,7 +264,7 @@ class AzurePath(CloudPathMixin, ServiceEndpointMixin):
|
|
|
264
264
|
if last_modified:
|
|
265
265
|
mtime = (
|
|
266
266
|
datetime.strptime(last_modified, "%a, %d %b %Y %H:%M:%S GMT")
|
|
267
|
-
.replace(tzinfo=
|
|
267
|
+
.replace(tzinfo=UTC)
|
|
268
268
|
.timestamp()
|
|
269
269
|
)
|
|
270
270
|
return SimpleNamespace(
|
|
@@ -171,7 +171,11 @@ def _maybe_rewrite_scp_style(value: str) -> str:
|
|
|
171
171
|
return value
|
|
172
172
|
if not _discover_ssh_config():
|
|
173
173
|
return value
|
|
174
|
-
|
|
174
|
+
try:
|
|
175
|
+
resolved_host = _resolve_alias(host, None, None)[0]
|
|
176
|
+
except RuntimeError as exc:
|
|
177
|
+
raise click.ClickException(str(exc)) from exc
|
|
178
|
+
if resolved_host == host:
|
|
175
179
|
# No Host block matched — leave alone (don't probe DNS).
|
|
176
180
|
return value
|
|
177
181
|
prefix = f"{user}@" if user else ""
|
|
@@ -1321,24 +1321,6 @@ class _CloudRawIO(io.RawIOBase):
|
|
|
1321
1321
|
return self._pos
|
|
1322
1322
|
|
|
1323
1323
|
|
|
1324
|
-
class _SpooledWriteBuffer(tempfile.SpooledTemporaryFile):
|
|
1325
|
-
"""Spooled write buffer exposing the IOBase probes ``TextIOWrapper`` needs.
|
|
1326
|
-
|
|
1327
|
-
Python 3.10's ``SpooledTemporaryFile`` omits ``readable``/``writable``/
|
|
1328
|
-
``seekable`` (added in 3.11); the buffer is always opened ``w+b`` so all
|
|
1329
|
-
three are unconditionally true.
|
|
1330
|
-
"""
|
|
1331
|
-
|
|
1332
|
-
def readable(self) -> bool:
|
|
1333
|
-
return True
|
|
1334
|
-
|
|
1335
|
-
def writable(self) -> bool:
|
|
1336
|
-
return True
|
|
1337
|
-
|
|
1338
|
-
def seekable(self) -> bool:
|
|
1339
|
-
return True
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
1324
|
class _CloudFile:
|
|
1343
1325
|
"""File handle backed by cloud read/write with lazy range-read support.
|
|
1344
1326
|
|
|
@@ -1381,7 +1363,7 @@ class _CloudFile:
|
|
|
1381
1363
|
self._range_read = range_read
|
|
1382
1364
|
self._buf: IO[bytes] | None = None
|
|
1383
1365
|
self._text_wrapper: io.TextIOWrapper | None = None
|
|
1384
|
-
self._reader: io.BufferedReader | None = None
|
|
1366
|
+
self._reader: io.BufferedReader | io.RawIOBase | None = None
|
|
1385
1367
|
self._closed = False
|
|
1386
1368
|
self._sync = False
|
|
1387
1369
|
|
|
@@ -1402,7 +1384,7 @@ class _CloudFile:
|
|
|
1402
1384
|
if "r" in self._mode:
|
|
1403
1385
|
self._buf = io.BytesIO(data or b"")
|
|
1404
1386
|
else:
|
|
1405
|
-
self._buf =
|
|
1387
|
+
self._buf = tempfile.SpooledTemporaryFile(max_size=self._SPOOL_MAX_SIZE, mode="w+b")
|
|
1406
1388
|
if "b" not in self._mode:
|
|
1407
1389
|
self._text_wrapper = io.TextIOWrapper(
|
|
1408
1390
|
self._buf,
|
|
@@ -1415,11 +1397,12 @@ class _CloudFile:
|
|
|
1415
1397
|
|
|
1416
1398
|
def _make_reader(self, size: int) -> io.IOBase:
|
|
1417
1399
|
"""Create a lazily-filled reader backed by range reads."""
|
|
1418
|
-
raw =
|
|
1400
|
+
raw = self._make_raw_reader(size)
|
|
1419
1401
|
if self._buffering == 0:
|
|
1420
1402
|
# Unbuffered: return raw directly (binary only)
|
|
1421
1403
|
if "b" not in self._mode:
|
|
1422
1404
|
raise ValueError("can't have unbuffered text I/O")
|
|
1405
|
+
self._reader = raw
|
|
1423
1406
|
return raw
|
|
1424
1407
|
reader = io.BufferedReader(raw, buffer_size=self._chunk_size)
|
|
1425
1408
|
self._reader = reader
|
|
@@ -1432,6 +1415,9 @@ class _CloudFile:
|
|
|
1432
1415
|
)
|
|
1433
1416
|
return reader
|
|
1434
1417
|
|
|
1418
|
+
def _make_raw_reader(self, size: int) -> _CloudRawIO:
|
|
1419
|
+
return _CloudRawIO(self._path, size)
|
|
1420
|
+
|
|
1435
1421
|
def _spool_for_upload(self) -> tuple[IO[bytes], int]:
|
|
1436
1422
|
"""Flush any text layer and rewind the spool; return ``(buffer, size)``."""
|
|
1437
1423
|
if self._text_wrapper is not None:
|
|
@@ -56,7 +56,7 @@ import hashlib
|
|
|
56
56
|
import netrc
|
|
57
57
|
import warnings
|
|
58
58
|
from collections.abc import AsyncIterator, Awaitable, Callable
|
|
59
|
-
from datetime import
|
|
59
|
+
from datetime import UTC, datetime
|
|
60
60
|
from os import getenv
|
|
61
61
|
from types import SimpleNamespace
|
|
62
62
|
from typing import IO, TYPE_CHECKING, TypeVar, cast
|
|
@@ -111,7 +111,7 @@ def _parse_mlst_mtime(modify: str | None) -> float | None:
|
|
|
111
111
|
if not modify:
|
|
112
112
|
return None
|
|
113
113
|
fmt = "%Y%m%d%H%M%S.%f" if "." in modify else "%Y%m%d%H%M%S"
|
|
114
|
-
return datetime.strptime(modify, fmt).replace(tzinfo=
|
|
114
|
+
return datetime.strptime(modify, fmt).replace(tzinfo=UTC).timestamp()
|
|
115
115
|
|
|
116
116
|
|
|
117
117
|
_NETRC_WARNED = False
|
|
@@ -10,6 +10,7 @@ import logging
|
|
|
10
10
|
import re
|
|
11
11
|
from base64 import b64encode
|
|
12
12
|
from collections.abc import AsyncGenerator, AsyncIterator, Callable
|
|
13
|
+
from datetime import UTC
|
|
13
14
|
from os import getenv, linesep
|
|
14
15
|
from typing import TYPE_CHECKING, Literal
|
|
15
16
|
from xml.etree.ElementTree import XMLParser
|
|
@@ -29,7 +30,7 @@ from asanypath_native import (
|
|
|
29
30
|
from yarl import URL
|
|
30
31
|
|
|
31
32
|
from asanypath._transfer import RangeNotSupportedError
|
|
32
|
-
from asanypath.cloud import CloudPathMixin, _CloudFile, _service_origin
|
|
33
|
+
from asanypath.cloud import CloudPathMixin, _CloudFile, _CloudRawIO, _service_origin
|
|
33
34
|
|
|
34
35
|
logger = logging.getLogger(__name__)
|
|
35
36
|
|
|
@@ -483,8 +484,8 @@ class HTTPPath(CloudPathMixin):
|
|
|
483
484
|
def open(self, mode="r", buffering=-1, encoding=None, errors=None, newline=None):
|
|
484
485
|
"""Open a seekable read-only handle with sync or async context management.
|
|
485
486
|
|
|
486
|
-
|
|
487
|
-
|
|
487
|
+
Read ranges lazily when the server provides a usable size. Servers that
|
|
488
|
+
do not support HEAD or ranges fall back to a full download.
|
|
488
489
|
"""
|
|
489
490
|
if mode not in ("r", "rt", "tr", "rb", "br"):
|
|
490
491
|
raise ValueError("HTTPPath.open() supports only read modes ('r', 'rt', 'rb')")
|
|
@@ -492,7 +493,7 @@ class HTTPPath(CloudPathMixin):
|
|
|
492
493
|
raise ValueError("binary mode doesn't take an encoding, errors or newline argument")
|
|
493
494
|
if buffering == 0 and "b" not in mode:
|
|
494
495
|
raise ValueError("can't have unbuffered text I/O")
|
|
495
|
-
return
|
|
496
|
+
return _HTTPCloudFile(self, mode, buffering, encoding, errors, newline)
|
|
496
497
|
|
|
497
498
|
async def _read_bytes_uncached(self) -> bytes:
|
|
498
499
|
return await http_get(str(self), headers=self._merge_headers(None))
|
|
@@ -597,7 +598,7 @@ class HTTPPath(CloudPathMixin):
|
|
|
597
598
|
remaining ``stat`` fields. Returns a ``SimpleNamespace`` matching the
|
|
598
599
|
cloud-backend convention (see ``S3Path.stat``).
|
|
599
600
|
"""
|
|
600
|
-
from datetime import datetime
|
|
601
|
+
from datetime import datetime
|
|
601
602
|
from email.utils import parsedate_to_datetime
|
|
602
603
|
from types import SimpleNamespace
|
|
603
604
|
|
|
@@ -613,7 +614,7 @@ class HTTPPath(CloudPathMixin):
|
|
|
613
614
|
try:
|
|
614
615
|
mtime = (
|
|
615
616
|
datetime.strptime(last_modified, "%a, %d %b %Y %H:%M:%S GMT")
|
|
616
|
-
.replace(tzinfo=
|
|
617
|
+
.replace(tzinfo=UTC)
|
|
617
618
|
.timestamp()
|
|
618
619
|
)
|
|
619
620
|
except ValueError:
|
|
@@ -666,3 +667,84 @@ class HTTPSPath(HTTPPath):
|
|
|
666
667
|
"""Async path implementation for HTTPS."""
|
|
667
668
|
|
|
668
669
|
protocol: str = "https"
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
class _HTTPRawIO(_CloudRawIO):
|
|
673
|
+
def __init__(self, path, size: int, etag: str | None, last_modified: str | None):
|
|
674
|
+
super().__init__(path, size)
|
|
675
|
+
self._etag = etag
|
|
676
|
+
self._last_modified = last_modified
|
|
677
|
+
self._whole_response: bytes | None = None
|
|
678
|
+
|
|
679
|
+
def readinto(self, b):
|
|
680
|
+
if self._pos >= self._size or not b:
|
|
681
|
+
return 0
|
|
682
|
+
end = min(self._pos + len(b), self._size)
|
|
683
|
+
if self._whole_response is None:
|
|
684
|
+
from asanypath.sync import _SyncRunner
|
|
685
|
+
|
|
686
|
+
try:
|
|
687
|
+
data = _SyncRunner.get().run(
|
|
688
|
+
self._path._range_read(
|
|
689
|
+
self._pos,
|
|
690
|
+
end - 1,
|
|
691
|
+
etag=self._etag,
|
|
692
|
+
last_modified=self._last_modified,
|
|
693
|
+
total_size=self._size,
|
|
694
|
+
)
|
|
695
|
+
)
|
|
696
|
+
except RangeNotSupportedError as error:
|
|
697
|
+
if len(error.data) != self._size:
|
|
698
|
+
raise OSError("Source changed during ranged read") from error
|
|
699
|
+
self._whole_response = error.data
|
|
700
|
+
data = error.data[self._pos : end]
|
|
701
|
+
else:
|
|
702
|
+
data = self._whole_response[self._pos : end]
|
|
703
|
+
b[: len(data)] = data
|
|
704
|
+
self._pos += len(data)
|
|
705
|
+
return len(data)
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
class _HTTPCloudFile(_CloudFile):
|
|
709
|
+
async def _range_metadata(self):
|
|
710
|
+
from asanypath.cache import cache_enabled
|
|
711
|
+
|
|
712
|
+
if cache_enabled(None) or http_request is None:
|
|
713
|
+
return None
|
|
714
|
+
response = await self._path.request("HEAD", headers={"accept-encoding": "identity"})
|
|
715
|
+
if response.status_code in (400, 401, 403, 404, 405, 501):
|
|
716
|
+
logger.debug("HTTP HEAD unavailable; falling back to a full read")
|
|
717
|
+
return None
|
|
718
|
+
if not response.ok:
|
|
719
|
+
raise RuntimeError(f"HTTP {response.status_code} during HEAD request")
|
|
720
|
+
headers = {key.lower(): value for key, value in response.headers.items()}
|
|
721
|
+
if headers.get("accept-ranges", "").lower() == "none":
|
|
722
|
+
return None
|
|
723
|
+
if headers.get("content-encoding", "identity").lower() != "identity":
|
|
724
|
+
return None
|
|
725
|
+
size = self._get_size(headers)
|
|
726
|
+
if size is None or size <= 0:
|
|
727
|
+
return None
|
|
728
|
+
return size, headers.get("etag"), headers.get("last-modified")
|
|
729
|
+
|
|
730
|
+
def _make_raw_reader(self, size: int) -> _CloudRawIO:
|
|
731
|
+
return _HTTPRawIO(self._path, size, self._etag, self._last_modified)
|
|
732
|
+
|
|
733
|
+
def __enter__(self):
|
|
734
|
+
from asanypath.sync import _SyncRunner
|
|
735
|
+
|
|
736
|
+
self._sync = True
|
|
737
|
+
runner = _SyncRunner.get()
|
|
738
|
+
metadata = runner.run(self._range_metadata())
|
|
739
|
+
if metadata is not None:
|
|
740
|
+
size, self._etag, self._last_modified = metadata
|
|
741
|
+
return self._make_reader(size)
|
|
742
|
+
return self._make_buffer(runner.run(self._path.read_bytes()))
|
|
743
|
+
|
|
744
|
+
async def __aenter__(self):
|
|
745
|
+
self._sync = False
|
|
746
|
+
metadata = await self._range_metadata()
|
|
747
|
+
if metadata is not None:
|
|
748
|
+
size, self._etag, self._last_modified = metadata
|
|
749
|
+
return self._make_reader(size)
|
|
750
|
+
return self._make_buffer(await self._path.read_bytes())
|
|
@@ -10,7 +10,7 @@ import asyncio
|
|
|
10
10
|
import logging
|
|
11
11
|
import os
|
|
12
12
|
from collections.abc import Mapping
|
|
13
|
-
from datetime import
|
|
13
|
+
from datetime import UTC, datetime
|
|
14
14
|
from types import SimpleNamespace
|
|
15
15
|
from typing import cast
|
|
16
16
|
|
|
@@ -291,7 +291,7 @@ class S3Path(CloudPathMixin, ServiceEndpointMixin):
|
|
|
291
291
|
if last_modified:
|
|
292
292
|
mtime = (
|
|
293
293
|
datetime.strptime(last_modified, "%a, %d %b %Y %H:%M:%S GMT")
|
|
294
|
-
.replace(tzinfo=
|
|
294
|
+
.replace(tzinfo=UTC)
|
|
295
295
|
.timestamp()
|
|
296
296
|
)
|
|
297
297
|
return SimpleNamespace(
|