workers-py 1.1.6__py3-none-any.whl → 1.1.7__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/sync.py +53 -4
- pywrangler/utils.py +17 -4
- {workers_py-1.1.6.dist-info → workers_py-1.1.7.dist-info}/METADATA +1 -1
- workers_py-1.1.7.dist-info/RECORD +9 -0
- workers_py-1.1.6.dist-info/RECORD +0 -9
- {workers_py-1.1.6.dist-info → workers_py-1.1.7.dist-info}/WHEEL +0 -0
- {workers_py-1.1.6.dist-info → workers_py-1.1.7.dist-info}/entry_points.txt +0 -0
pywrangler/sync.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import os
|
|
3
|
+
import shutil
|
|
3
4
|
from pathlib import Path
|
|
4
5
|
import tempfile
|
|
5
6
|
|
|
@@ -59,18 +60,66 @@ def _get_python_version():
|
|
|
59
60
|
return os.environ.get("_PYWRANGLER_PYTHON_VERSION", "3.12")
|
|
60
61
|
|
|
61
62
|
|
|
63
|
+
def _get_venv_python_version() -> str | None:
|
|
64
|
+
"""
|
|
65
|
+
Retrieves the Python version from the virtual environment.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
The Python version string or None if it cannot be determined.
|
|
69
|
+
"""
|
|
70
|
+
venv_python = (
|
|
71
|
+
VENV_WORKERS_PATH / "Scripts" / "python.exe"
|
|
72
|
+
if os.name == "nt"
|
|
73
|
+
else VENV_WORKERS_PATH / "bin" / "python"
|
|
74
|
+
)
|
|
75
|
+
if not venv_python.is_file():
|
|
76
|
+
return None
|
|
77
|
+
|
|
78
|
+
result = run_command(
|
|
79
|
+
[str(venv_python), "--version"], check=False, capture_output=True
|
|
80
|
+
)
|
|
81
|
+
if result.returncode != 0:
|
|
82
|
+
return None
|
|
83
|
+
|
|
84
|
+
return result.stdout.strip()
|
|
85
|
+
|
|
86
|
+
|
|
62
87
|
def create_workers_venv():
|
|
63
88
|
"""
|
|
64
89
|
Creates a virtual environment at `VENV_WORKERS_PATH` if it doesn't exist.
|
|
65
90
|
"""
|
|
91
|
+
wanted_python_version = _get_python_version()
|
|
92
|
+
logger.debug(f"Using python version: {wanted_python_version}")
|
|
93
|
+
|
|
66
94
|
if VENV_WORKERS_PATH.is_dir():
|
|
67
|
-
|
|
68
|
-
|
|
95
|
+
installed_version = _get_venv_python_version()
|
|
96
|
+
if installed_version:
|
|
97
|
+
if wanted_python_version in installed_version:
|
|
98
|
+
logger.debug(
|
|
99
|
+
f"Virtual environment at {VENV_WORKERS_PATH} already exists."
|
|
100
|
+
)
|
|
101
|
+
return
|
|
102
|
+
|
|
103
|
+
logger.warning(
|
|
104
|
+
f"Recreating virtual environment at {VENV_WORKERS_PATH} due to Python version mismatch. "
|
|
105
|
+
f"Found {installed_version}, expected {wanted_python_version}"
|
|
106
|
+
)
|
|
107
|
+
else:
|
|
108
|
+
logger.warning(
|
|
109
|
+
f"Could not determine python version for {VENV_WORKERS_PATH}, recreating."
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
shutil.rmtree(VENV_WORKERS_PATH)
|
|
69
113
|
|
|
70
114
|
logger.debug(f"Creating virtual environment at {VENV_WORKERS_PATH}...")
|
|
71
|
-
python_version = _get_python_version()
|
|
72
115
|
run_command(
|
|
73
|
-
[
|
|
116
|
+
[
|
|
117
|
+
"uv",
|
|
118
|
+
"venv",
|
|
119
|
+
str(VENV_WORKERS_PATH),
|
|
120
|
+
"--python",
|
|
121
|
+
f"python{wanted_python_version}",
|
|
122
|
+
]
|
|
74
123
|
)
|
|
75
124
|
|
|
76
125
|
|
pywrangler/utils.py
CHANGED
|
@@ -50,7 +50,21 @@ def run_command(
|
|
|
50
50
|
cwd: Path | None = None,
|
|
51
51
|
env: dict | None = None,
|
|
52
52
|
check: bool = True,
|
|
53
|
+
capture_output: bool = False,
|
|
53
54
|
):
|
|
55
|
+
"""
|
|
56
|
+
Runs a command and handles logging and errors.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
command: The command to run as a list of strings.
|
|
60
|
+
cwd: The working directory.
|
|
61
|
+
env: Environment variables.
|
|
62
|
+
check: If True, raise an exception on non-zero exit codes.
|
|
63
|
+
capture_output: If True, capture and return stdout/stderr.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
A subprocess.CompletedProcess instance.
|
|
67
|
+
"""
|
|
54
68
|
logger.log(RUNNING_LEVEL, f"{' '.join(str(arg) for arg in command)}")
|
|
55
69
|
try:
|
|
56
70
|
process = subprocess.run(
|
|
@@ -58,16 +72,15 @@ def run_command(
|
|
|
58
72
|
cwd=cwd,
|
|
59
73
|
env=env,
|
|
60
74
|
check=check,
|
|
61
|
-
|
|
62
|
-
stderr=subprocess.STDOUT,
|
|
75
|
+
capture_output=capture_output,
|
|
63
76
|
text=True,
|
|
64
77
|
)
|
|
65
|
-
if process.stdout:
|
|
78
|
+
if process.stdout and not capture_output:
|
|
66
79
|
logger.log(OUTPUT_LEVEL, f"{process.stdout.strip()}")
|
|
67
80
|
return process
|
|
68
81
|
except subprocess.CalledProcessError as e:
|
|
69
82
|
logger.error(
|
|
70
|
-
f"Error running command: {' '.join(str(arg) for arg in command)}\nExit code: {e.returncode}\nOutput:\n{e.stdout.strip()}"
|
|
83
|
+
f"Error running command: {' '.join(str(arg) for arg in command)}\nExit code: {e.returncode}\nOutput:\n{e.stdout.strip() if e.stdout else ''}{e.stderr.strip() if e.stderr else ''}"
|
|
71
84
|
)
|
|
72
85
|
raise click.exceptions.Exit(code=e.returncode)
|
|
73
86
|
except FileNotFoundError:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: workers-py
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.7
|
|
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
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
pywrangler/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
2
|
+
pywrangler/__main__.py,sha256=BnrUM7YiBmlM4HAn2MI9hP1kVNtzeK_kEgQhRy5HTq0,38
|
|
3
|
+
pywrangler/cli.py,sha256=BnGGrdksWP-qBj-b0ipji-61Q0kZJohyr2KZZz-XG5s,5150
|
|
4
|
+
pywrangler/sync.py,sha256=cjqKuId3QSz7K1qUC0-zOF1Fb9ahV2HVybR9-Np5SqE,11135
|
|
5
|
+
pywrangler/utils.py,sha256=wfkT7GbKtgtjHXtV3AjNeb25ohdAfrprdZIlqqidiQU,3269
|
|
6
|
+
workers_py-1.1.7.dist-info/METADATA,sha256=tBk1r9Nk_ch-I1tUJ5biEczlLuPyvPPSp2TPpftuYNY,1750
|
|
7
|
+
workers_py-1.1.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
+
workers_py-1.1.7.dist-info/entry_points.txt,sha256=pt6X-Nv5-gSiKUwrnvLwzlSXs9yP37m7zdTAi8f6nAM,50
|
|
9
|
+
workers_py-1.1.7.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
pywrangler/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
2
|
-
pywrangler/__main__.py,sha256=BnrUM7YiBmlM4HAn2MI9hP1kVNtzeK_kEgQhRy5HTq0,38
|
|
3
|
-
pywrangler/cli.py,sha256=BnGGrdksWP-qBj-b0ipji-61Q0kZJohyr2KZZz-XG5s,5150
|
|
4
|
-
pywrangler/sync.py,sha256=80pPCz-DTTAk5xTQ0j4ufrh3wv1nQ8y_-zpdPkaLVfw,9740
|
|
5
|
-
pywrangler/utils.py,sha256=6mR3kst-Y0w1DMQc5LQ2M9xiNWcVezctTKIWXKQXMJ8,2781
|
|
6
|
-
workers_py-1.1.6.dist-info/METADATA,sha256=rI1Ka0dZmdZPfLyanLGulrUewvzy0wnWeUZi9sMdMCI,1750
|
|
7
|
-
workers_py-1.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
-
workers_py-1.1.6.dist-info/entry_points.txt,sha256=pt6X-Nv5-gSiKUwrnvLwzlSXs9yP37m7zdTAi8f6nAM,50
|
|
9
|
-
workers_py-1.1.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|