@@ -140,17 +140,11 @@ def extend_pyscript_config(
140140 return orjson .dumps (pyscript_config ).decode ("utf-8" )
141141
142142
143- @functools .cache
144143def reactpy_version_string () -> str : # pragma: no cover
145144 local_version = reactpy .__version__
146145
147146 # Get a list of all versions via `pip index versions`
148- result = subprocess .run (
149- ["pip" , "index" , "versions" , "reactpy" ],
150- capture_output = True ,
151- text = True ,
152- check = False ,
153- )
147+ result = cached_pip_index_versions ("reactpy" )
154148
155149 # Check if the command failed
156150 if result .returncode != 0 :
@@ -177,11 +171,7 @@ def reactpy_version_string() -> str: # pragma: no cover
177171 return f"reactpy=={ local_version } "
178172
179173 # Begin determining an alternative method of installing ReactPy
180- _logger .warning (
181- "'reactpy==%s' is not available on PyPi, "
182- "Attempting to determine an alternative to use within PyScript..." ,
183- local_version ,
184- )
174+
185175 if not latest_version :
186176 _logger .warning ("Failed to determine the latest version of ReactPy on PyPi. " )
187177
@@ -199,7 +189,7 @@ def reactpy_version_string() -> str: # pragma: no cover
199189 )
200190 wheel_glob = glob (str (dist_dir / f"reactpy-{ local_version } -*.whl" ))
201191
202- # Building a local wheel failed, find an alternative installation method
192+ # Building a local wheel failed, try our best to give the user any possible version.
203193 if not wheel_glob :
204194 if latest_version :
205195 _logger .warning (
@@ -213,14 +203,29 @@ def reactpy_version_string() -> str: # pragma: no cover
213203 )
214204 return f"reactpy=={ local_version } "
215205
216- # Move the wheel file to the web_modules directory, if needed
206+ # Move the local file to the web modules directory, if needed
217207 wheel_file = Path (wheel_glob [0 ])
218208 new_path = REACTPY_WEB_MODULES_DIR .current / wheel_file .name
219209 if not new_path .exists ():
210+ _logger .warning (
211+ "'reactpy==%s' is not available on PyPi. "
212+ "PyScript will utilize a local wheel of ReactPy instead." ,
213+ local_version ,
214+ )
220215 shutil .copy (wheel_file , new_path )
221216 return f"{ REACTPY_PATH_PREFIX .current } modules/{ wheel_file .name } "
222217
223218
219+ @functools .cache
220+ def cached_pip_index_versions (package_name : str ) -> subprocess .CompletedProcess [str ]:
221+ return subprocess .run (
222+ ["pip" , "index" , "versions" , package_name ],
223+ capture_output = True ,
224+ text = True ,
225+ check = False ,
226+ )
227+
228+
224229@functools .cache
225230def cached_file_read (file_path : str , minifiy = True ) -> str :
226231 content = Path (file_path ).read_text (encoding = "utf-8" ).strip ()
0 commit comments