Skip to content

Commit 369fc6a

Browse files
authored
Enforced check of that all notebooks has matching SG version installed (#1607)
* Enforced check of that all notebooks has matching SG version installed and simplified way of adding new notebooks * Fix failing CI
1 parent bcc026c commit 369fc6a

6 files changed

Lines changed: 24 additions & 12 deletions

File tree

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,11 @@ jobs:
243243
. venv/bin/activate
244244
python3 -m pip install pip==23.1.2
245245
python3 -m pip install -e .
246+
python3 -m pip install -r requirements.dev.txt
246247
python3 -m pip install gitpython==3.1.0
247248
coverage run --source=super_gradients -m unittest tests/breaking_change_tests/unit_test.py
248249
coverage run --source=super_gradients -m unittest tests/breaking_change_tests/test_detect_breaking_change.py
250+
make check_notebooks_version_match
249251
- run:
250252
name: Remove new environment when failed
251253
command: "rm -r venv"

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,18 @@ sweeper_test:
3131
fi
3232

3333
# Here you define a list of notebooks we want to execute and convert to markdown files
34-
# NOTEBOOKS = hellomake.ipynb hellofunc.ipynb helloclass.ipynb
35-
NOTEBOOKS = src/super_gradients/examples/model_export/models_export.ipynb notebooks/what_are_recipes_and_how_to_use.ipynb notebooks/transfer_learning_classification.ipynb notebooks/how_to_use_knowledge_distillation_for_classification.ipynb
34+
NOTEBOOKS_TO_RUN := src/super_gradients/examples/model_export/models_export.ipynb
35+
NOTEBOOKS_TO_RUN += notebooks/what_are_recipes_and_how_to_use.ipynb
36+
NOTEBOOKS_TO_RUN += notebooks/transfer_learning_classification.ipynb
37+
NOTEBOOKS_TO_RUN += notebooks/how_to_use_knowledge_distillation_for_classification.ipynb
38+
39+
# If there are additional notebooks that must not be executed, but still should be checked for version match, add them here
40+
NOTEBOOKS_TO_CHECK := $(NOTEBOOKS_TO_RUN)
3641

3742
# This Makefile target runs notebooks listed below and converts them to markdown files in documentation/source/
38-
run_and_convert_notebooks_to_docs: $(NOTEBOOKS)
43+
run_and_convert_notebooks_to_docs: $(NOTEBOOKS_TO_RUN)
3944
jupyter nbconvert --to markdown --output-dir="documentation/source/" --execute $^
4045

4146
# This Makefile target runs notebooks listed below and converts them to markdown files in documentation/source/
42-
check_notebooks_version_match: $(NOTEBOOKS)
47+
check_notebooks_version_match: $(NOTEBOOKS_TO_CHECK)
4348
python tests/verify_notebook_version.py $^

notebooks/transfer_learning_classification.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
}
6060
],
6161
"source": [
62-
"! pip install -qq super_gradients==3.3.1"
62+
"! pip install -qq super-gradients==3.3.1"
6363
]
6464
},
6565
{

notebooks/what_are_recipes_and_how_to_use.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
{
4242
"cell_type": "code",
4343
"source": [
44-
"!pip install -q super_gradients==3.3.1"
44+
"!pip install -q super-gradients==3.3.1"
4545
],
4646
"metadata": {
4747
"id": "8uZM-4va5Rpu",

tests/unit_tests/test_version_check.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ def test_pip_install_major_minor(self):
1616
def test_pip_install_major_patch(self):
1717
self.assertEquals(try_extract_super_gradients_version_from_pip_install_command("!pip install super-gradients==3.3.1"), "3.3.1")
1818

19+
def test_pip_install_with_underscore(self):
20+
self.assertEquals(try_extract_super_gradients_version_from_pip_install_command("!pip install super_gradients==3.3.1"), "3.3.1")
21+
1922
def test_pip_install_with_extra_args(self):
2023
self.assertEquals(try_extract_super_gradients_version_from_pip_install_command("!pip install -q super-gradients==3.3.1"), "3.3.1")
2124
self.assertEquals(try_extract_super_gradients_version_from_pip_install_command("!pip install super-gradients==3.3.1 --extra-index-url=foobar"), "3.3.1")

tests/verify_notebook_version.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def try_extract_super_gradients_version_from_pip_install_command(input: str) ->
3030
:param input: A string that contains a `!pip install super_gradients=={version}` command.
3131
:return: The version of super_gradients.
3232
"""
33-
pattern = re.compile(r"pip\s+install.*?super-gradients==([0-9]+(?:\.[0-9]+)*(?:\.[0-9]+)?)")
33+
pattern = re.compile(r"pip\s+install.*?super[-_]gradients==([0-9]+(?:\.[0-9]+)*(?:\.[0-9]+)?)")
3434
match = re.search(pattern, input)
3535
if match:
3636
return match.group(1)
@@ -46,22 +46,24 @@ def main():
4646
"""
4747
notebook_path = sys.argv[1]
4848
first_cell_content = get_first_cell_content(notebook_path)
49-
print(first_cell_content)
5049

50+
expected_version = super_gradients.__version__
5151
for line in first_cell_content.splitlines():
5252
sg_version_in_notebook = try_extract_super_gradients_version_from_pip_install_command(line)
5353
if sg_version_in_notebook is not None:
54-
if sg_version_in_notebook == super_gradients.__version__:
54+
if sg_version_in_notebook == expected_version:
5555
return 0
5656
else:
5757
print(
58-
f"Version mismatch detected:\n"
59-
f"super_gradients.__version__ is {super_gradients.__version__}\n"
58+
f"Version mismatch detected in {notebook_path}:\n"
59+
f"super_gradients.__version__ is {expected_version}\n"
6060
f"Notebook uses super_gradients {sg_version_in_notebook} (notebook_path)"
6161
)
6262
return 1
6363

64-
print("First code cell of the notebook does not contain a `!pip install super_gradients=={version} command`")
64+
print(f"First code cell of the notebook {notebook_path} does not contain a `!pip install super_gradients=={expected_version} command`")
65+
print("First code cell content:")
66+
print(first_cell_content)
6567
return 1
6668

6769

0 commit comments

Comments
 (0)