Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforced check of that all notebooks has matching SG version installed #1607

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,11 @@ jobs:
. venv/bin/activate
python3 -m pip install pip==23.1.2
python3 -m pip install -e .
python3 -m pip install -r requirements.dev.txt
python3 -m pip install gitpython==3.1.0
coverage run --source=super_gradients -m unittest tests/breaking_change_tests/unit_test.py
coverage run --source=super_gradients -m unittest tests/breaking_change_tests/test_detect_breaking_change.py
make check_notebooks_version_match
- run:
name: Remove new environment when failed
command: "rm -r venv"
Expand Down
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ sweeper_test:
fi

# Here you define a list of notebooks we want to execute and convert to markdown files
# NOTEBOOKS = hellomake.ipynb hellofunc.ipynb helloclass.ipynb
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
NOTEBOOKS_TO_RUN := src/super_gradients/examples/model_export/models_export.ipynb
NOTEBOOKS_TO_RUN += notebooks/what_are_recipes_and_how_to_use.ipynb
NOTEBOOKS_TO_RUN += notebooks/transfer_learning_classification.ipynb
NOTEBOOKS_TO_RUN += notebooks/how_to_use_knowledge_distillation_for_classification.ipynb

# If there are additional notebooks that must not be executed, but still should be checked for version match, add them here
NOTEBOOKS_TO_CHECK := $(NOTEBOOKS_TO_RUN)

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

# This Makefile target runs notebooks listed below and converts them to markdown files in documentation/source/
check_notebooks_version_match: $(NOTEBOOKS)
check_notebooks_version_match: $(NOTEBOOKS_TO_CHECK)
python tests/verify_notebook_version.py $^
2 changes: 1 addition & 1 deletion notebooks/transfer_learning_classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
}
],
"source": [
"! pip install -qq super_gradients==3.3.1"
"! pip install -qq super-gradients==3.3.1"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion notebooks/what_are_recipes_and_how_to_use.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{
"cell_type": "code",
"source": [
"!pip install -q super_gradients==3.3.1"
"!pip install -q super-gradients==3.3.1"
],
"metadata": {
"id": "8uZM-4va5Rpu",
Expand Down
3 changes: 3 additions & 0 deletions tests/unit_tests/test_version_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def test_pip_install_major_minor(self):
def test_pip_install_major_patch(self):
self.assertEquals(try_extract_super_gradients_version_from_pip_install_command("!pip install super-gradients==3.3.1"), "3.3.1")

def test_pip_install_with_underscore(self):
self.assertEquals(try_extract_super_gradients_version_from_pip_install_command("!pip install super_gradients==3.3.1"), "3.3.1")

def test_pip_install_with_extra_args(self):
self.assertEquals(try_extract_super_gradients_version_from_pip_install_command("!pip install -q super-gradients==3.3.1"), "3.3.1")
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")
Expand Down
14 changes: 8 additions & 6 deletions tests/verify_notebook_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def try_extract_super_gradients_version_from_pip_install_command(input: str) ->
:param input: A string that contains a `!pip install super_gradients=={version}` command.
:return: The version of super_gradients.
"""
pattern = re.compile(r"pip\s+install.*?super-gradients==([0-9]+(?:\.[0-9]+)*(?:\.[0-9]+)?)")
pattern = re.compile(r"pip\s+install.*?super[-_]gradients==([0-9]+(?:\.[0-9]+)*(?:\.[0-9]+)?)")
match = re.search(pattern, input)
if match:
return match.group(1)
Expand All @@ -46,22 +46,24 @@ def main():
"""
notebook_path = sys.argv[1]
first_cell_content = get_first_cell_content(notebook_path)
print(first_cell_content)

expected_version = super_gradients.__version__
for line in first_cell_content.splitlines():
sg_version_in_notebook = try_extract_super_gradients_version_from_pip_install_command(line)
if sg_version_in_notebook is not None:
if sg_version_in_notebook == super_gradients.__version__:
if sg_version_in_notebook == expected_version:
return 0
else:
print(
f"Version mismatch detected:\n"
f"super_gradients.__version__ is {super_gradients.__version__}\n"
f"Version mismatch detected in {notebook_path}:\n"
f"super_gradients.__version__ is {expected_version}\n"
f"Notebook uses super_gradients {sg_version_in_notebook} (notebook_path)"
)
return 1

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


Expand Down