-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/sg 1147 notebooks in repo (#1493)
* Add CI config to run notebooks conversion * Add CI config to run notebooks conversion * Specify ipykernel * Specify ipykernel * Specify ipykernel * Remove crashing notebook * Added additional step to verify that all converted notebooks has a correct SG version installed and bumped up SG version in master to reflect that we already have 3.2.1
- Loading branch information
Showing
6 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ flake8==5.0.4 | |
black==22.10.0 | ||
pre-commit==2.20.0 | ||
gitpython>=3.1.0 | ||
ipykernel==6.25 | ||
nbconvert==7.8.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import re | ||
import sys | ||
import super_gradients | ||
import nbformat | ||
|
||
|
||
def get_first_cell_content(notebook_path): | ||
# Load the notebook | ||
with open(notebook_path, "r", encoding="utf-8") as notebook_file: | ||
notebook_content = nbformat.read(notebook_file, as_version=4) | ||
|
||
# Get the content of the first cell (assuming it's a code cell) | ||
code_cells = [cell for cell in notebook_content.cells if cell.cell_type == "code"] | ||
first_cell_content = "" | ||
if code_cells: | ||
first_cell = code_cells[0] | ||
first_cell_content = first_cell.source | ||
|
||
return first_cell_content | ||
|
||
|
||
def main(): | ||
""" | ||
This script is used to verify that the version of the SG package matches the version of SG installed in the notebook. | ||
The script assumes that the first cell of the notebook contains a `!pip install super_gradients=={version}` command. | ||
:return: An exit code of 0 if the versions match, 1 otherwise. | ||
""" | ||
notebook_path = sys.argv[1] | ||
first_cell_content = get_first_cell_content(notebook_path) | ||
print(first_cell_content) | ||
|
||
# Check if the first cell contains "!pip install super_gradients=={version}" using regex and extract the version | ||
pattern = re.compile(r"^!pip install super_gradients==([\d\.]+)") | ||
|
||
for line in first_cell_content.splitlines(): | ||
match = re.search(pattern, line) | ||
if match: | ||
sg_version_in_notebook = match.group(1) | ||
if sg_version_in_notebook == super_gradients.__version__: | ||
return 0 | ||
else: | ||
print( | ||
f"Version mismatch detected:\n" | ||
f"super_gradients.__version__ is {super_gradients.__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`") | ||
return 1 | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |