test #210
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
name: CI | |
on: [workflow_dispatch, pull_request, push] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install nbdev torch torchvision requests | |
pip install -e ".[dev]" | |
- name: Diagnostic Information | |
run: | | |
python -c "import torch; print('Torch version:', torch.__version__)" | |
python -c "import torchvision; print('Torchvision version:', torchvision.__version__)" | |
python -c "import torchtext; print('Torchtext version:', torchtext.__version__)" | |
python -c "import os; print('Current working directory:', os.getcwd())" | |
python -c "import sys; print('Python path:', sys.path)" | |
- name: Prepare MNIST Dataset | |
run: | | |
python -c " | |
import os | |
import sys | |
import requests | |
def download_mnist(url, filename): | |
os.makedirs('data/image/raw', exist_ok=True) | |
filepath = os.path.join('data/image/raw', filename) | |
if not os.path.exists(filepath): | |
print(f'Downloading {url} to {filepath}') | |
try: | |
# Use requests with a user agent to avoid 403 errors | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' | |
} | |
response = requests.get(url, headers=headers) | |
# Raise an exception for HTTP errors | |
response.raise_for_status() | |
# Write the content to file | |
with open(filepath, 'wb') as f: | |
f.write(response.content) | |
print(f'Successfully downloaded {filename}') | |
return True | |
except Exception as e: | |
print(f'Failed to download {filename}: {e}') | |
return False | |
return True | |
# MNIST URLs | |
base_url = 'http://yann.lecun.com/exdb/mnist/' | |
files_to_download = [ | |
(base_url + 'train-images-idx3-ubyte.gz', 'train-images-idx3-ubyte.gz'), | |
(base_url + 'train-labels-idx1-ubyte.gz', 'train-labels-idx1-ubyte.gz'), | |
(base_url + 't10k-images-idx3-ubyte.gz', 't10k-images-idx3-ubyte.gz'), | |
(base_url + 't10k-labels-idx1-ubyte.gz', 't10k-labels-idx1-ubyte.gz') | |
] | |
# Try alternative mirror if primary fails | |
alternative_base_url = 'https://ossci-datasets.s3.amazonaws.com/mnist/' | |
alternative_files = [ | |
(alternative_base_url + 'train-images-idx3-ubyte.gz', 'train-images-idx3-ubyte.gz'), | |
(alternative_base_url + 'train-labels-idx1-ubyte.gz', 'train-labels-idx1-ubyte.gz'), | |
(alternative_base_url + 't10k-images-idx3-ubyte.gz', 't10k-images-idx3-ubyte.gz'), | |
(alternative_base_url + 't10k-labels-idx1-ubyte.gz', 't10k-labels-idx1-ubyte.gz') | |
] | |
# Try primary URLs first | |
success = all(download_mnist(url, filename) for url, filename in files_to_download) | |
# If primary fails, try alternative mirror | |
if not success: | |
print('Trying alternative mirror...') | |
success = all(download_mnist(url, filename) for url, filename in alternative_files) | |
if not success: | |
print('Failed to download MNIST files from all sources') | |
sys.exit(1) | |
" | |
- name: Verify MNIST Dataset | |
run: | | |
python -c " | |
import os | |
import sys | |
mnist_raw_dir = 'data/image/raw' | |
expected_files = [ | |
'train-images-idx3-ubyte.gz', | |
'train-labels-idx1-ubyte.gz', | |
't10k-images-idx3-ubyte.gz', | |
't10k-labels-idx1-ubyte.gz' | |
] | |
missing_files = [f for f in expected_files if not os.path.exists(os.path.join(mnist_raw_dir, f))] | |
if missing_files: | |
print(f'Missing files: {missing_files}') | |
sys.exit(1) | |
else: | |
print('All MNIST files downloaded successfully') | |
" | |
- name: Clean notebooks | |
run: | | |
nbdev_clean | |
- name: Export notebooks | |
run: | | |
nbdev_export | |
- name: Run tests | |
run: | | |
nbdev_test --do_print --timing |