-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f29f475
Showing
40 changed files
with
1,538 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Install nbcommands if not already installed. More info: https://github.com/vinayak-mehta/nbcommands | ||
if ! command -v nbgrep &> /dev/null; then | ||
echo "nbcommands is not installed. Installing..." | ||
pip install nbcommands | ||
fi | ||
|
||
# Specify the path for the output Python file | ||
mkdir -p ./.github/workflows/testing | ||
touch ./.github/workflows/testing/test_import_libraries.py | ||
PYTHON_FILE="./.github/workflows/testing/test_import_libraries.py" | ||
|
||
# Remove the output file if it already exists | ||
rm -f "$PYTHON_FILE" | ||
|
||
# Search for *.ipynb files recursively in all folders | ||
find . -type f -name '*.ipynb' -print0 | | ||
while IFS= read -r -d '' file; do | ||
# Extract import statements from Jupyter notebooks | ||
# new one catch the import xx.x as y and removing the space | ||
# nbgrep "(?:from\s+(\w+(?:\.\w+)*)\s+import\s+(\*|\w+)(?:\s+as\s+\w+)?(?:,s*\w+(?:\\s+as\s+\w+)?)*|import\s+(\w+(?:\.\w+)*)\s+as\s+\w+(?:,\s*\w+(?:\s+as\s+\w+)?)*)" "$file" | grep -v 'nbgrep:' | awk -F ':' '{sub(/^[^:]*:[^:]*:line [0-9]+:/, " ", $0)}1'| sed 's/^[[:space:]]*//' | ||
nbgrep "(?:from\s+(\w+(?:\.\w+)*)\s+import\s+(\*|\w+)(?:\s+as\s+\w+)?(?:,\s*\w+(?:\s+as\s+\w+)?)*|import\s+(\w+(?:\.\w+)*)\s+as\s+\w+(?:,\s*\w+(?:\s+as\s+\w+)?)*)|(?:^|\n)import\s+(\w+(?:\.\w+)*)\s+" "$file" | grep -v 'nbgrep:' | awk -F ':' '{sub(/^[^:]*:[^:]*:line [0-9]+:/, " ", $0)}1'| sed 's/^[[:space:]]*//' | ||
|
||
|
||
done | sort -u > "$PYTHON_FILE" | ||
echo "<<<<<<< All extract import statements from Jupyter notebooks >>>>>>" | ||
cat "$PYTHON_FILE" | ||
|
||
|
||
# Generate test function in test.py | ||
echo "#!/usr/bin/env python" > "$PYTHON_FILE.tmp" | ||
echo "" >> "$PYTHON_FILE.tmp" | ||
echo "def test_import_libraries():" >> "$PYTHON_FILE.tmp" | ||
echo " try:" >> "$PYTHON_FILE.tmp" | ||
grep -v "^import" "$PYTHON_FILE" | sed 's/^/ /' >> "$PYTHON_FILE.tmp" | ||
echo " except ImportError as e:" >> "$PYTHON_FILE.tmp" | ||
echo " # If any of the libraries cannot be imported, the test will fail" >> "$PYTHON_FILE.tmp" | ||
echo " assert False, f\"Failed to import library: {e}\"" >> "$PYTHON_FILE.tmp" | ||
echo "" >> "$PYTHON_FILE.tmp" | ||
echo " # If all libraries are imported successfully, the test passes" >> "$PYTHON_FILE.tmp" | ||
echo " assert True" >> "$PYTHON_FILE.tmp" | ||
|
||
# Move the temporary file to the final location | ||
mv "$PYTHON_FILE.tmp" "$PYTHON_FILE" |
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,199 @@ | ||
name: Test in different OS | ||
## The events | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
include-MacOS-M1-M2: | ||
description: 'Include macOS-(M1-M2)variations' | ||
required: true | ||
default: 'false' | ||
type: choice | ||
options: | ||
- 'true' | ||
- 'false' | ||
# push: | ||
# branches: | ||
# - main | ||
# paths: | ||
# - requirements.txt | ||
|
||
jobs: | ||
|
||
Test_under_ubuntu: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ ubuntu-22.04, ubuntu-20.04] | ||
python-version: [3.11.3] | ||
|
||
## The actions | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Create import_libraries_test.py from Notebooks | ||
run: | | ||
echo "<<<<<<< Search for *.ipynb files recursively in all folders >>>>>>" | ||
chmod +x .github/workflows/REGX_test_import_libraries.sh | ||
./.github/workflows/REGX_test_import_libraries.sh | ||
echo "<<<<<<< Create import libraries from the Notebook run successfully >>>>>>" | ||
- name: Install dependencies | ||
run: | | ||
python --version | ||
python -m venv .venv | ||
source .venv/bin/activate | ||
python -m pip install --upgrade pip | ||
pip list | ||
pip install -r requirements.txt | ||
echo "<<<<<<< Install dependencies run successfully >>>>>>" | ||
- name: Test the import libraries | ||
run: | | ||
source .venv/bin/activate | ||
./.github/workflows/REGX_test_import_libraries.sh | ||
echo "<<<<<<< Test the dependencies in the import libraries from the Notebook >>>>>>" | ||
pip install pytest | ||
pytest ./.github/workflows/testing/test_import_libraries.py | ||
echo "<<<<<<< Test_under_ubuntuOS run successfully >>>>>>" | ||
Test_under_windows: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [windows-2022, windows-2019] | ||
python-version: [3.11.3] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Create import_libraries_test.py from Notebooks | ||
shell: bash | ||
run: | | ||
echo "<<<<<<< Search for *.ipynb files recursively in all folders >>>>>>" | ||
chmod +x .github/workflows/REGX_test_import_libraries.sh | ||
./.github/workflows/REGX_test_import_libraries.sh | ||
echo "<<<<<<< Create import libraries from the Notebook run successfully >>>>>>" | ||
- name: Install dependencies | ||
shell: bash | ||
run: | | ||
echo "Note: This code is intended to run under the Bash CLI, not PowerShell." | ||
python --version | ||
python -m venv .venv | ||
source .venv/Scripts/activate | ||
python -m pip install --upgrade pip | ||
pip list | ||
pip install -r requirements.txt | ||
echo "<<<<<<< Install dependencies run successfully >>>>>>" | ||
- name: Test the import libraries | ||
shell: bash | ||
run: | | ||
echo "Note: This code is intended to run under the Bash CLI, not PowerShell." | ||
source .venv/Scripts/activate | ||
./.github/workflows/REGX_test_import_libraries.sh | ||
echo "<<<<<<< Test the dependencies in the import libraries from the Notebook >>>>>>" | ||
pip install pytest | ||
pytest ./.github/workflows/testing/test_import_libraries.py | ||
echo "<<<<<<< Test_under_ubuntuOS run successfully >>>>>>" | ||
|
||
Test_under_macos: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [macos-latest,macos-13] | ||
python-version: [3.11.3] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Create import_libraries_test.py from Notebooks | ||
run: | | ||
echo "<<<<<<< Search for *.ipynb files recursively in all folders >>>>>>" | ||
chmod +x .github/workflows/REGX_test_import_libraries.sh | ||
./.github/workflows/REGX_test_import_libraries.sh | ||
echo "<<<<<<< Create import libraries from the Notebook run successfully >>>>>>" | ||
- name: Install dependencies | ||
run: | | ||
python --version | ||
python -m venv .venv | ||
source .venv/bin/activate | ||
python -m pip install --upgrade pip | ||
pip list | ||
pip install -r requirements.txt | ||
echo "<<<<<<< Install dependencies run successfully >>>>>>" | ||
- name: Test the import libraries | ||
run: | | ||
source .venv/bin/activate | ||
./.github/workflows/REGX_test_import_libraries.sh | ||
echo "<<<<<<< Test the dependencies in the import libraries from the Notebook >>>>>>" | ||
pip install pytest | ||
pytest ./.github/workflows/testing/test_import_libraries.py | ||
echo "<<<<<<< Test_under_ubuntuOS run successfully >>>>>>" | ||
Test_under_macos_M1-M2: | ||
runs-on: ${{ matrix.os }} | ||
if: github.event.inputs.include-MacOS-M1-M2 == 'true' | ||
strategy: | ||
matrix: | ||
os: [macos-14] #[flyci-macos-large-latest-m1,flyci-macos-large-latest-m2] # Price on FlyC (https://github.com/apps/flyci-prod) (https://github.com/actions/runner-images) | ||
python-version: [3.11.3] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Create import_libraries_test.py from Notebooks | ||
run: | | ||
echo "<<<<<<< Search for *.ipynb files recursively in all folders >>>>>>" | ||
chmod +x .github/workflows/REGX_test_import_libraries.sh | ||
./.github/workflows/REGX_test_import_libraries.sh | ||
echo "<<<<<<< Create import libraries from the Notebook run successfully >>>>>>" | ||
- name: Install dependencies | ||
run: | | ||
python --version | ||
python -m venv .venv | ||
source .venv/bin/activate | ||
python -m pip install --upgrade pip | ||
pip list | ||
pip install -r requirements.txt | ||
echo "<<<<<<< Install dependencies run successfully >>>>>>" | ||
- name: Test the import libraries | ||
run: | | ||
source .venv/bin/activate | ||
./.github/workflows/REGX_test_import_libraries.sh | ||
echo "<<<<<<< Test the dependencies in the import libraries from the Notebook >>>>>>" | ||
pip install pytest | ||
pytest ./.github/workflows/testing/test_import_libraries.py | ||
echo "<<<<<<< Test_under_ubuntuOS run successfully >>>>>>" |
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,139 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
|
||
# Mac Stuff | ||
.DS_Store | ||
|
||
# vscode Stuff | ||
.vscode | ||
|
||
# Data | ||
data/ |
Oops, something went wrong.