-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathinstall_lowest_dependencies.py
More file actions
68 lines (55 loc) · 2.09 KB
/
install_lowest_dependencies.py
File metadata and controls
68 lines (55 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""This script installs the package with the lowest dependencies."""
from argparse import ArgumentParser
import re
import subprocess
import sys
from typing import List, Optional, Tuple
import toml
parser = ArgumentParser(
description="This script installs the package with the lowest dependencies."
)
parser.add_argument(
"-e",
"--examples",
action="store_true",
help="Install the examples dependencies",
)
args = parser.parse_args()
# Load the pyproject.toml
pyproject = toml.load("pyproject.toml")
# Extract dependencies
if args.examples:
dependencies: List[str] = (
pyproject.get("project", {}).get("optional-dependencies", {}).get("examples", [])
)
else:
dependencies: List[str] = pyproject.get("project", {}).get("dependencies", [])
# Function to get exactly the minimal specified version
def get_lowest_version(dependency_string: str) -> str:
"""Get the lowest version of a dependency."""
pattern = re.compile(r"([\w-]+)(?:>=(\d*(?:\.\d*(?:\.\d*(?:\.\d*)?)?)?))?")
match = pattern.match(dependency_string)
if match:
groups: Tuple[Optional[str], Optional[str]] = match.groups()
if groups[1]:
return "==".join(groups)
return groups[0]
return dependency_string
# Install the main package without dependencies
# Check if uv is available in the current environment
try:
subprocess.run(["uv", "--version"], check=True, capture_output=True)
pip_cmd = ["uv", "pip", "install", "--python", sys.executable]
except (subprocess.CalledProcessError, FileNotFoundError):
pip_cmd = [sys.executable, "-m", "pip", "install"]
subprocess.run(pip_cmd + [".", "--no-deps"], check=True)
# Get the lowest version of pennylane
PENNYLANE_VERSION = None
for dependency in dependencies:
if dependency.startswith("pennylane"):
PENNYLANE_VERSION = get_lowest_version(dependency).split("==")[1]
break
dependencies = [get_lowest_version(dependency) for dependency in dependencies]
if PENNYLANE_VERSION:
dependencies.append(f"pennylane-lightning=={PENNYLANE_VERSION}")
subprocess.run(pip_cmd + dependencies, check=True)