Skip to content

Commit e24bec1

Browse files
authored
ci: pre-install in separate step (#349)
1 parent 910c12d commit e24bec1

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

.actions/assistant.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from datetime import datetime
99
from shutil import copyfile
1010
from textwrap import wrap
11-
from typing import Any, Dict, List, Optional, Sequence, Tuple
11+
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
1212
from warnings import warn
1313

1414
import fire
@@ -283,11 +283,12 @@ def _valid_accelerator(folder: str) -> bool:
283283
return any(ac in meta_accels for ac in device_accels)
284284

285285
@staticmethod
286-
def _parse_requirements(folder: str) -> Tuple[str, str]:
286+
def _parse_requirements(folder: str, formatted: bool = True) -> Union[Tuple[str, str], Tuple[list, list]]:
287287
"""Parse standard requirements from meta file.
288288
289289
Args:
290290
folder: path to the folder with python script, meta and artefacts
291+
formatted: format it into two strings
291292
292293
"""
293294
meta = AssistantCLI._load_meta(folder)
@@ -298,15 +299,27 @@ def _parse_requirements(folder: str) -> Tuple[str, str]:
298299
for k, v in meta.items()
299300
if k.startswith(AssistantCLI._META_PIP_KEY)
300301
}
301-
pip_args = ['--extra-index-url="https://download.pytorch.org/whl/"' + _RUNTIME_VERSIONS.get("DEVICE")]
302+
pip_args = [f'--extra-index-url="https://download.pytorch.org/whl/{_RUNTIME_VERSIONS.get("DEVICE")}"']
302303
for pip_key in meta_pip_args:
303304
if not isinstance(meta_pip_args[pip_key], (list, tuple, set)):
304305
meta_pip_args[pip_key] = [meta_pip_args[pip_key]]
305306
for arg in meta_pip_args[pip_key]:
306307
arg = arg % _RUNTIME_VERSIONS
307308
pip_args.append(f"--{pip_key} {arg}")
309+
if formatted:
310+
return " ".join([f'"{req}"' for req in requires]), " ".join(pip_args)
311+
return list(requires), pip_args
308312

309-
return " ".join([f'"{req}"' for req in requires]), " ".join(pip_args)
313+
@staticmethod
314+
def pip_install(folder: str) -> str:
315+
"""Print all notebook requirements to be pre-installed in format of requirements file.
316+
317+
Args:
318+
folder: path to the folder with python script, meta and artefacts
319+
320+
"""
321+
req, args = AssistantCLI._parse_requirements(folder, formatted=False)
322+
return os.linesep.join(req) + os.linesep + os.linesep.join(args)
310323

311324
@staticmethod
312325
def _bash_download_data(folder: str) -> List[str]:

.azure/ipynb-publish.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@ jobs:
143143
- bash: |
144144
set -e
145145
pip --version
146-
# todo: export requirements for notebooks to file and execute
147146
# todo: adjust torch ecosystem versions
148147
pip install -r requirements.txt
148+
# export requirements for notebooks to file and execute
149+
python .actions/assistant.py pip-install --folder=$(notebook) > notebook.txt
150+
pip install -r notebook.txt
149151
displayName: "Install dependencies"
150152
timeoutInMinutes: "15"
151153
@@ -156,14 +158,14 @@ jobs:
156158
python -m papermill --version
157159
displayName: "Sanity check"
158160
159-
- bash: python .actions/assistant.py convert-ipynb $(notebook)
161+
- bash: python .actions/assistant.py convert-ipynb --folder=$(notebook)
160162
displayName: "Generate notebook"
161163
timeoutInMinutes: "5"
162164

163165
- bash: |
164166
set -e
165167
mkdir $(PATH_DATASETS)
166-
python .actions/assistant.py bash-render $(notebook)
168+
python .actions/assistant.py bash-render --folder=$(notebook)
167169
cat .actions/_ipynb-render.sh
168170
bash .actions/_ipynb-render.sh
169171
git status

.azure/ipynb-validate.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ jobs:
8585
set -e
8686
pip --version
8787
pip install -r requirements.txt
88-
pip list
88+
python .actions/assistant.py pip-install --folder=$(notebook) > notebook.txt
89+
pip install -r notebook.txt
8990
displayName: "Install dependencies"
9091
9192
- bash: |
@@ -94,13 +95,13 @@ jobs:
9495
python -c "import torch ; mgpu = torch.cuda.device_count() ; assert mgpu > 0, f'GPU: {mgpu}'"
9596
displayName: "Sanity check"
9697
97-
- bash: python .actions/assistant.py convert-ipynb $(notebook)
98+
- bash: python .actions/assistant.py convert-ipynb --folder=$(notebook)
9899
displayName: "Generate notebook"
99100

100101
- bash: |
101102
set -e
102103
mkdir $(PATH_DATASETS)
103-
python .actions/assistant.py bash-validate $(notebook)
104+
python .actions/assistant.py bash-validate --folder=$(notebook)
104105
cat .actions/_ipynb-validate.sh
105106
bash .actions/_ipynb-validate.sh
106107
env:

0 commit comments

Comments
 (0)