Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.

Commit 70e40cd

Browse files
committed
JB: pip args
1 parent 52d64a6 commit 70e40cd

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

.actions/helpers.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,33 @@
6969
"""
7070

7171

72+
def get_running_cuda_version() -> str:
73+
try:
74+
import torch
75+
return torch.version.cuda
76+
except ImportError:
77+
return ""
78+
79+
80+
def get_running_torch_version():
81+
try:
82+
import torch
83+
ver = torch.__version__
84+
return ver[:ver.index('+')] if '+' in ver else ver
85+
except ImportError:
86+
return ""
87+
88+
89+
TORCH_VERSION = get_running_torch_version()
90+
CUDA_VERSION = get_running_cuda_version()
91+
RUNTIME_VERSIONS = dict(
92+
TORCH_VERSION_FULL=TORCH_VERSION,
93+
TORCH_VERSION=TORCH_VERSION[:TORCH_VERSION.index('+')] if '+' in TORCH_VERSION else TORCH_VERSION,
94+
CUDA_VERSION=CUDA_VERSION,
95+
CUDA_VERSION_NODOT=CUDA_VERSION.replace(".", ""),
96+
)
97+
98+
7299
class HelperCLI:
73100

74101
DIR_NOTEBOOKS = ".notebooks"
@@ -82,6 +109,8 @@ class HelperCLI:
82109
)
83110
META_FILE_REGEX = ".meta.{yaml,yml}"
84111
REQUIREMENTS_FILE = "requirements.txt"
112+
PIP_ARGS_FILE = "pip_arguments.txt"
113+
META_PIP_KEY = 'pip__'
85114

86115
@staticmethod
87116
def _meta_file(folder: str) -> str:
@@ -164,10 +193,27 @@ def parse_requirements(dir_path: str):
164193

165194
req = meta.get('requirements', [])
166195
fname = os.path.join(dir_path, HelperCLI.REQUIREMENTS_FILE)
167-
print(fname)
196+
print(f"Requirements: {fname}")
168197
with open(fname, "w") as fp:
169198
fp.write(os.linesep.join(req))
170199

200+
pip_args = {
201+
k.replace(HelperCLI.META_PIP_KEY, ''): v
202+
for k, v in meta.items() if k.startswith(HelperCLI.META_PIP_KEY)
203+
}
204+
cmd_args = []
205+
for pip_key in pip_args:
206+
if not isinstance(pip_args[pip_key], (list, tuple, set)):
207+
pip_args[pip_key] = [pip_args[pip_key]]
208+
for arg in pip_args[pip_key]:
209+
arg = arg % RUNTIME_VERSIONS
210+
cmd_args.append(f"--{pip_key} {arg}")
211+
212+
fname = os.path.join(dir_path, HelperCLI.PIP_ARGS_FILE)
213+
print(f"PIP arguments: {fname}")
214+
with open(fname, "w") as fp:
215+
fp.write(" ".join(cmd_args))
216+
171217
@staticmethod
172218
def copy_notebooks(path_root: str, path_docs_ipynb: str = "docs/source/notebooks"):
173219
"""Copy all notebooks from a folder to doc folder.

.actions/ipynb-render.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ mkdir -p $pub_dir
1616
python .actions/helpers.py parse-requirements $1
1717
pip install --quiet --requirement requirements.txt --upgrade-strategy only-if-needed
1818
cat "$1/requirements.txt"
19-
pip install --requirement "$1/requirements.txt"
19+
pip_args=$(cat "$1/pip_arguments.txt")
20+
printf "pip arguments: $pip_args"
21+
pip install --requirement "$1/requirements.txt"$pip_args
2022

2123
echo "available: $ACCELERATOR"
2224
accel=$(python .actions/helpers.py valid-accelerator $1 2>&1)

.actions/ipynb-test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ python -m virtualenv --system-site-packages "$1/venv"
1717
source "$1/venv/bin/activate"
1818
pip --version
1919
pip install --quiet --requirement requirements.txt --upgrade-strategy only-if-needed
20-
pip install --requirement "$1/requirements.txt"
20+
pip_args=$(cat "$1/pip_arguments.txt")
21+
printf "pip arguments: $pip_args"
22+
pip install --requirement "$1/requirements.txt" $pip_args
2123
pip list
2224

2325
echo "available: $ACCELERATOR"

0 commit comments

Comments
 (0)