-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathinstall_lowest_dependencies.py
45 lines (35 loc) · 1.48 KB
/
install_lowest_dependencies.py
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
"""This script installs the package with the lowest dependencies."""
import re
import subprocess
import sys
from typing import List, Optional, Tuple
import toml
# Load the pyproject.toml
pyproject = toml.load("pyproject.toml")
# Extract dependencies
dependencies: List[str] = pyproject.get("project", {}).get("dependencies", []) + pyproject.get(
"project", {}
).get("optional-dependencies", {}).get("examples", [])
# 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*)?)?))?")
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
subprocess.run([sys.executable, "-m", "pip", "install", ".", "--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([sys.executable, "-m", "pip", "install"] + dependencies, check=True)