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

Commit 9b6995f

Browse files
committed
JB: pip args
1 parent d9f816f commit 9b6995f

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
@@ -72,6 +72,33 @@
7272
"""
7373

7474

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

77104
DIR_NOTEBOOKS = ".notebooks"
@@ -85,6 +112,8 @@ class HelperCLI:
85112
)
86113
META_FILE_REGEX = ".meta.{yaml,yml}"
87114
REQUIREMENTS_FILE = "requirements.txt"
115+
PIP_ARGS_FILE = "pip_arguments.txt"
116+
META_PIP_KEY = 'pip__'
88117

89118
@staticmethod
90119
def _meta_file(folder: str) -> str:
@@ -205,10 +234,27 @@ def parse_requirements(dir_path: str):
205234

206235
req = meta.get('requirements', [])
207236
fname = os.path.join(dir_path, HelperCLI.REQUIREMENTS_FILE)
208-
print(fname)
237+
print(f"Requirements: {fname}")
209238
with open(fname, "w") as fp:
210239
fp.write(os.linesep.join(req))
211240

241+
pip_args = {
242+
k.replace(HelperCLI.META_PIP_KEY, ''): v
243+
for k, v in meta.items() if k.startswith(HelperCLI.META_PIP_KEY)
244+
}
245+
cmd_args = []
246+
for pip_key in pip_args:
247+
if not isinstance(pip_args[pip_key], (list, tuple, set)):
248+
pip_args[pip_key] = [pip_args[pip_key]]
249+
for arg in pip_args[pip_key]:
250+
arg = arg % RUNTIME_VERSIONS
251+
cmd_args.append(f"--{pip_key} {arg}")
252+
253+
fname = os.path.join(dir_path, HelperCLI.PIP_ARGS_FILE)
254+
print(f"PIP arguments: {fname}")
255+
with open(fname, "w") as fp:
256+
fp.write(" ".join(cmd_args))
257+
212258
@staticmethod
213259
def copy_notebooks(path_root: str, path_docs_ipynb: str = "docs/source/notebooks"):
214260
"""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
printf "available: $ACCELERATOR\n"
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
printf "available: $ACCELERATOR\n"

0 commit comments

Comments
 (0)