|
1 | 1 | from dataclasses import dataclass |
2 | 2 | from pathlib import Path, PurePosixPath |
3 | 3 | from collections.abc import Sequence, Iterator |
| 4 | +from packaging.version import Version |
4 | 5 | import shutil |
5 | 6 | from qml.lib import fs, cmds |
6 | 7 | from qml.lib.virtual_env import Virtualenv |
@@ -297,57 +298,28 @@ def _build_demo( |
297 | 298 | # If dev, we need to re-install the latest Catalyst, then Lightning, then PennyLane |
298 | 299 | # in that order, regardless of conflicts/warnings. |
299 | 300 | if dev: |
300 | | - with open(ctx.plc_dev_constraints_file, "r") as f: |
301 | | - packages = f.readlines() |
302 | | - for package in packages: |
303 | | - package = package.strip() |
304 | | - if package and not package.startswith("#"): |
305 | | - logger.info("Getting versions for %s", package) |
306 | | - try: |
307 | | - package_name, constraint = package.split("<", maxsplit=1) |
308 | | - except: |
309 | | - logger.error("Malformed constraints file for PLC dev.") |
310 | | - raise |
311 | | - package_versions = cmds.pip_get_versions(build_venv.python, package_name, index_url="https://test.pypi.org/simple/") |
312 | | - for version in package_versions: |
313 | | - if version < constraint: |
314 | | - logger.info("Installing %s==%s", package_name, version) |
315 | | - #Testing. Refactor this later if successful |
316 | | - if package_name == "pennylane-catalyst": |
317 | | - cmds.pip_install( |
318 | | - build_venv.python, |
319 | | - "--no-cache-dir", |
320 | | - "--extra-index-url", |
321 | | - "https://test.pypi.org/simple/", |
322 | | - f"{package_name}=={version}", |
323 | | - use_uv=False, |
324 | | - quiet=False, |
325 | | - ) |
326 | | - elif package_name == "pennylane-lightning": |
327 | | - cmds.pip_install( |
328 | | - build_venv.python, |
329 | | - "--no-cache-dir", |
330 | | - "--force-reinstall", |
331 | | - "--no-deps", |
332 | | - "--extra-index-url", |
333 | | - "https://test.pypi.org/simple/", |
334 | | - f"{package_name}=={version}", |
335 | | - use_uv=False, |
336 | | - quiet=False, |
337 | | - ) |
338 | | - elif package_name == "pennylane": |
339 | | - cmds.pip_install( |
340 | | - build_venv.python, |
341 | | - "--no-cache-dir", |
342 | | - "--force-reinstall", |
343 | | - "--no-deps", |
344 | | - "--extra-index-url", |
345 | | - "https://test.pypi.org/simple/", |
346 | | - f"{package_name}=={version}", |
347 | | - use_uv=False, |
348 | | - quiet=False, |
349 | | - ) |
350 | | - break |
| 301 | + base_install_args = [ |
| 302 | + build_venv.python, |
| 303 | + "--no-cache-dir", |
| 304 | + "--extra-index-url", |
| 305 | + "https://test.pypi.org/simple/", |
| 306 | + ] |
| 307 | + with open(ctx.plc_dev_constraints_file) as f: |
| 308 | + constraints = json.load(f) |
| 309 | + for package in constraints: |
| 310 | + logger.info("Getting versions for %s", package["name"]) |
| 311 | + package_versions = cmds.pip_get_versions(build_venv.python, package["name"], index_url="https://test.pypi.org/simple/") |
| 312 | + # These are ruturned newest to oldest, so we can break when we find the first match |
| 313 | + for version in package_versions: |
| 314 | + if Version(version).release == Version(package["version"]).release: |
| 315 | + logger.info("Installing %s==%s", package["name"], version) |
| 316 | + install_args = base_install_args.copy() |
| 317 | + if package["name"] != "pennylane-catalyst": |
| 318 | + install_args.append("--force-reinstall") |
| 319 | + install_args.append("--no-deps") |
| 320 | + install_args.append(f"{package['name']}=={version}") |
| 321 | + cmds.pip_install(*install_args, use_uv=False, quiet=False) |
| 322 | + break |
351 | 323 | # Need to reinstall the demo's requirements file to ensure the correct versions are installed |
352 | 324 | if demo.requirements_file: |
353 | 325 | cmds.pip_install( |
|
0 commit comments