workers-py 1.2.0__py3-none-any.whl → 1.3.0__py3-none-any.whl
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.
- pywrangler/metadata.py +16 -0
- pywrangler/sync.py +101 -9
- {workers_py-1.2.0.dist-info → workers_py-1.3.0.dist-info}/METADATA +12 -4
- workers_py-1.3.0.dist-info/RECORD +10 -0
- workers_py-1.2.0.dist-info/RECORD +0 -9
- {workers_py-1.2.0.dist-info → workers_py-1.3.0.dist-info}/WHEEL +0 -0
- {workers_py-1.2.0.dist-info → workers_py-1.3.0.dist-info}/entry_points.txt +0 -0
pywrangler/metadata.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from typing import Literal, NamedTuple
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class PythonCompatVersion(NamedTuple):
|
|
6
|
+
version: Literal["3.12", "3.13"]
|
|
7
|
+
compat_flag: str
|
|
8
|
+
compat_date: datetime | None
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
PYTHON_COMPAT_VERSIONS = [
|
|
12
|
+
PythonCompatVersion(
|
|
13
|
+
"3.13", "python_workers_20250116", datetime.strptime("2025-09-29", "%Y-%m-%d")
|
|
14
|
+
),
|
|
15
|
+
PythonCompatVersion("3.12", "python_workers", None),
|
|
16
|
+
]
|
pywrangler/sync.py
CHANGED
|
@@ -3,15 +3,18 @@ import os
|
|
|
3
3
|
import shutil
|
|
4
4
|
import tempfile
|
|
5
5
|
from contextlib import contextmanager
|
|
6
|
+
from datetime import datetime
|
|
6
7
|
from pathlib import Path
|
|
7
8
|
from typing import Literal
|
|
8
9
|
|
|
9
10
|
import click
|
|
11
|
+
import pyjson5
|
|
10
12
|
|
|
11
13
|
from pywrangler.utils import (
|
|
12
14
|
run_command,
|
|
13
15
|
find_pyproject_toml,
|
|
14
16
|
)
|
|
17
|
+
from pywrangler.metadata import PYTHON_COMPAT_VERSIONS
|
|
15
18
|
|
|
16
19
|
try:
|
|
17
20
|
import tomllib # Standard in Python 3.11+
|
|
@@ -60,15 +63,88 @@ def check_wrangler_config():
|
|
|
60
63
|
raise click.exceptions.Exit(code=1)
|
|
61
64
|
|
|
62
65
|
|
|
66
|
+
def _parse_wrangler_config() -> dict:
|
|
67
|
+
"""
|
|
68
|
+
Parse wrangler configuration from either wrangler.toml or wrangler.jsonc.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
dict: Parsed configuration data
|
|
72
|
+
"""
|
|
73
|
+
wrangler_toml = PROJECT_ROOT / "wrangler.toml"
|
|
74
|
+
wrangler_jsonc = PROJECT_ROOT / "wrangler.jsonc"
|
|
75
|
+
|
|
76
|
+
if wrangler_toml.is_file():
|
|
77
|
+
try:
|
|
78
|
+
with open(wrangler_toml, "rb") as f:
|
|
79
|
+
return tomllib.load(f)
|
|
80
|
+
except tomllib.TOMLDecodeError as e:
|
|
81
|
+
logger.error(f"Error parsing {wrangler_toml}: {e}")
|
|
82
|
+
raise click.exceptions.Exit(code=1)
|
|
83
|
+
|
|
84
|
+
if wrangler_jsonc.is_file():
|
|
85
|
+
try:
|
|
86
|
+
with open(wrangler_jsonc, "r") as f:
|
|
87
|
+
content = f.read()
|
|
88
|
+
return pyjson5.loads(content)
|
|
89
|
+
except (pyjson5.Json5DecoderError, ValueError) as e:
|
|
90
|
+
logger.error(f"Error parsing {wrangler_jsonc}: {e}")
|
|
91
|
+
raise click.exceptions.Exit(code=1)
|
|
92
|
+
|
|
93
|
+
return {}
|
|
94
|
+
|
|
95
|
+
|
|
63
96
|
def _get_python_version() -> Literal["3.12", "3.13"]:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
97
|
+
"""
|
|
98
|
+
Determine Python version from wrangler configuration.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
Python version string
|
|
102
|
+
"""
|
|
103
|
+
config = _parse_wrangler_config()
|
|
104
|
+
|
|
105
|
+
if not config:
|
|
106
|
+
logger.error("No wrangler config found")
|
|
107
|
+
raise click.exceptions.Exit(code=1)
|
|
108
|
+
|
|
109
|
+
compat_flags = config.get("compatibility_flags", [])
|
|
110
|
+
|
|
111
|
+
if "compatibility_date" not in config:
|
|
112
|
+
logger.error("No compatibility_date specified in wrangler config")
|
|
113
|
+
raise click.exceptions.Exit(code=1)
|
|
114
|
+
try:
|
|
115
|
+
compat_date = datetime.strptime(config.get("compatibility_date"), "%Y-%m-%d")
|
|
116
|
+
except ValueError:
|
|
117
|
+
logger.error(
|
|
118
|
+
f"Invalid compatibility_date format: {config.get('compatibility_date')}"
|
|
119
|
+
)
|
|
120
|
+
raise click.exceptions.Exit(code=1)
|
|
121
|
+
|
|
122
|
+
# Check if python_workers base flag is present (required for Python workers)
|
|
123
|
+
if "python_workers" not in compat_flags:
|
|
124
|
+
logger.error("`python_workers` compat flag not specified in wrangler config")
|
|
125
|
+
raise click.exceptions.Exit(code=1)
|
|
126
|
+
|
|
127
|
+
# Find the most specific Python version based on compat flags and date
|
|
128
|
+
# Sort by version descending to prioritize newer versions
|
|
129
|
+
sorted_versions = sorted(
|
|
130
|
+
PYTHON_COMPAT_VERSIONS, key=lambda x: x.version, reverse=True
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
for py_version in sorted_versions:
|
|
134
|
+
# Check if the specific compat flag is present
|
|
135
|
+
if py_version.compat_flag in compat_flags:
|
|
136
|
+
return py_version.version
|
|
137
|
+
|
|
138
|
+
# For versions with compat_date, also check the date requirement
|
|
139
|
+
if (
|
|
140
|
+
py_version.compat_date
|
|
141
|
+
and compat_date
|
|
142
|
+
and compat_date >= py_version.compat_date
|
|
143
|
+
):
|
|
144
|
+
return py_version.version
|
|
145
|
+
|
|
146
|
+
logger.error("Could not determine Python version from wrangler config")
|
|
147
|
+
raise click.exceptions.Exit(code=1)
|
|
72
148
|
|
|
73
149
|
|
|
74
150
|
def _get_uv_pyodide_interp_name():
|
|
@@ -118,7 +194,7 @@ def create_workers_venv():
|
|
|
118
194
|
Creates a virtual environment at `VENV_WORKERS_PATH` if it doesn't exist.
|
|
119
195
|
"""
|
|
120
196
|
wanted_python_version = _get_python_version()
|
|
121
|
-
logger.debug(f"Using python version: {wanted_python_version}")
|
|
197
|
+
logger.debug(f"Using python version from wrangler config: {wanted_python_version}")
|
|
122
198
|
|
|
123
199
|
if VENV_WORKERS_PATH.is_dir():
|
|
124
200
|
installed_version = _get_venv_python_version()
|
|
@@ -152,6 +228,21 @@ def create_workers_venv():
|
|
|
152
228
|
)
|
|
153
229
|
|
|
154
230
|
|
|
231
|
+
MIN_UV_VERSION = (0, 8, 10)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def check_uv_version():
|
|
235
|
+
res = run_command(["uv", "--version"], capture_output=True)
|
|
236
|
+
ver_str = res.stdout.split(" ")[1]
|
|
237
|
+
ver = tuple(int(x) for x in ver_str.split("."))
|
|
238
|
+
if ver >= MIN_UV_VERSION:
|
|
239
|
+
return
|
|
240
|
+
min_version_str = ".".join(str(x) for x in MIN_UV_VERSION)
|
|
241
|
+
logger.error(f"uv version at least {min_version_str} required, have {ver_str}.")
|
|
242
|
+
logger.error("Update uv with `uv self update`.")
|
|
243
|
+
raise click.exceptions.Exit(code=1)
|
|
244
|
+
|
|
245
|
+
|
|
155
246
|
def create_pyodide_venv():
|
|
156
247
|
if PYODIDE_VENV_PATH.is_dir():
|
|
157
248
|
logger.debug(
|
|
@@ -159,6 +250,7 @@ def create_pyodide_venv():
|
|
|
159
250
|
)
|
|
160
251
|
return
|
|
161
252
|
|
|
253
|
+
check_uv_version()
|
|
162
254
|
logger.debug(f"Creating Pyodide virtual environment at {PYODIDE_VENV_PATH}...")
|
|
163
255
|
PYODIDE_VENV_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
164
256
|
interp_name = _get_uv_pyodide_interp_name()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: workers-py
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: A set of libraries and tools for Python Workers
|
|
5
5
|
Project-URL: Homepage, https://github.com/cloudflare/workers-py
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/cloudflare/workers-py/issues
|
|
@@ -9,6 +9,7 @@ Classifier: Operating System :: OS Independent
|
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
10
|
Requires-Python: >=3.10
|
|
11
11
|
Requires-Dist: click<9.0.0,>=8.0.0
|
|
12
|
+
Requires-Dist: pyjson5>=1.6.0
|
|
12
13
|
Requires-Dist: pyodide-cli
|
|
13
14
|
Requires-Dist: rich>=13.0.0
|
|
14
15
|
Provides-Extra: build
|
|
@@ -29,7 +30,7 @@ A CLI tool for managing vendored packages in a Python Workers project.
|
|
|
29
30
|
On Linux, you may be able to install the tool globally by running:
|
|
30
31
|
|
|
31
32
|
```
|
|
32
|
-
uv
|
|
33
|
+
uv tool install workers-py
|
|
33
34
|
```
|
|
34
35
|
|
|
35
36
|
Alternatively, you can add `workers-py` to your pyproject.toml:
|
|
@@ -60,7 +61,7 @@ uv run --project $REPO_ROOT $REPO_ROOT/src/pywrangler --help
|
|
|
60
61
|
On Linux, to install it globally, you may also be able to run:
|
|
61
62
|
|
|
62
63
|
```
|
|
63
|
-
uv
|
|
64
|
+
uv tool install -e .
|
|
64
65
|
```
|
|
65
66
|
|
|
66
67
|
Alternatively, you can add `workers-py` to your pyproject.toml:
|
|
@@ -75,7 +76,14 @@ workers-py = { path = "../workers-py" }
|
|
|
75
76
|
|
|
76
77
|
Then run via `uv run pywrangler`.
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
#### Lint
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
uv run ruff check --fix
|
|
83
|
+
uv run ruff format
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
#### Tests
|
|
79
87
|
|
|
80
88
|
```
|
|
81
89
|
$ uv cache clean
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
pywrangler/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
pywrangler/__main__.py,sha256=BnrUM7YiBmlM4HAn2MI9hP1kVNtzeK_kEgQhRy5HTq0,38
|
|
3
|
+
pywrangler/cli.py,sha256=3hMjtOOib3HaTqCkuMGQe7MbBZNnim2ByHcDY4JxFlw,5091
|
|
4
|
+
pywrangler/metadata.py,sha256=vttmaCtouSr9ADj8ncvNGqeaWEGFP8pamH2T6ohFjnA,408
|
|
5
|
+
pywrangler/sync.py,sha256=ZzsRY8VsGOQufuQpJ0DxnPH3wXzTu5Myyh8wXs21oXA,12570
|
|
6
|
+
pywrangler/utils.py,sha256=wfkT7GbKtgtjHXtV3AjNeb25ohdAfrprdZIlqqidiQU,3269
|
|
7
|
+
workers_py-1.3.0.dist-info/METADATA,sha256=Xnj3ud5RhYdFFkndX_urC-jD3YWv_aUHQv2ckr_qiqA,1828
|
|
8
|
+
workers_py-1.3.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
workers_py-1.3.0.dist-info/entry_points.txt,sha256=pt6X-Nv5-gSiKUwrnvLwzlSXs9yP37m7zdTAi8f6nAM,50
|
|
10
|
+
workers_py-1.3.0.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
pywrangler/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
pywrangler/__main__.py,sha256=BnrUM7YiBmlM4HAn2MI9hP1kVNtzeK_kEgQhRy5HTq0,38
|
|
3
|
-
pywrangler/cli.py,sha256=3hMjtOOib3HaTqCkuMGQe7MbBZNnim2ByHcDY4JxFlw,5091
|
|
4
|
-
pywrangler/sync.py,sha256=4LbwXlzi7YXXhsgYT4unJOwX9DHSLI6sREcf7abJAks,9441
|
|
5
|
-
pywrangler/utils.py,sha256=wfkT7GbKtgtjHXtV3AjNeb25ohdAfrprdZIlqqidiQU,3269
|
|
6
|
-
workers_py-1.2.0.dist-info/METADATA,sha256=s9qthgJPRW1inmDvDDl_UR-V0KA-M_Hewwp6GJxjq04,1749
|
|
7
|
-
workers_py-1.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
-
workers_py-1.2.0.dist-info/entry_points.txt,sha256=pt6X-Nv5-gSiKUwrnvLwzlSXs9yP37m7zdTAi8f6nAM,50
|
|
9
|
-
workers_py-1.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|