Skip to content

Commit

Permalink
Use github cache feature
Browse files Browse the repository at this point in the history
  • Loading branch information
zain-sohail committed Oct 11, 2023
1 parent 0a13521 commit 88caa16
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 161 deletions.
136 changes: 39 additions & 97 deletions .github/workflows/document_tutorials.yml
Original file line number Diff line number Diff line change
@@ -1,102 +1,44 @@
name: Convert Tutorial Files

name: autogenerate docs from tutorials
# Not finished! Only will run on a specific branch for now so can be left
on:
# Triggers the workflow on push but only for the main branch
push:
branches: [documentation]
branches: [ workflow_trials ]
paths: ['**.ipynb']

jobs:
build:
runs-on: ubuntu-latest # You can specify a different runner if needed

docs-from-tutorials:
runs-on: ubuntu-latest
defaults:
run:
working-directory: docs
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8 # Specify the Python version you need

- name: Install dependencies
run: pip install jupyter nbconvert

- name: Run Conversion Script
uses: jannekem/run-python-script-action@v1
with:
script: |
import pathlib
import shutil
import subprocess
def create_new_directory_with_modified_files(directory_path, new_directory_path):
try:
# Create a Path object for the source directory
source_directory = pathlib.Path(directory_path)
# Ensure the source directory exists
if not source_directory.is_dir():
raise FileNotFoundError(f"The source directory '{directory_path}' does not exist.")
# Create a Path object for the new directory
new_directory = pathlib.Path(new_directory_path)
# Create the new directory if it doesn't exist
new_directory.mkdir(parents=True, exist_ok=True)
# Loop through files in the source directory
for file_path in source_directory.iterdir():
if file_path.is_file():
# Remove spaces and change hyphens to underscores in the filename
new_name = file_path.name.replace(' ', '').replace('-', '_')
# Construct the path for the new file in the new directory
new_file_path = new_directory / new_name
# Copy the file to the new directory with the modified name
shutil.copy2(file_path, new_file_path)
print(f"Copied '{file_path}' to '{new_file_path}'")
print("File copying completed successfully.")
except Exception as e:
print(f"An error occurred: {str(e)}")
def convert_ipynb_to_rst(directory_path):
try:
# Create a Path object for the directory
directory = pathlib.Path(directory_path)
# Ensure the directory exists
if not directory.is_dir():
raise FileNotFoundError(f"The directory '{directory_path}' does not exist.")
# Loop through files in the directory
for file_path in directory.iterdir():
if file_path.is_file() and file_path.suffix == '.ipynb':
# Construct the command to run nbconvert
command = f"jupyter nbconvert --to rst {str(file_path)}"
# Run nbconvert using subprocess
subprocess.run(command, shell=True, check=True)
print(f"Converted '{file_path}' to .rst")
print("Conversion to .rst completed successfully.")
except Exception as e:
print(f"An error occurred during conversion: {str(e)}")
if __name__ == "__main__":
# Specify the source directory path where you want to process files
source_directory_path = "tutorial/"
# Specify the new directory path where you want to create modified files
new_directory_path = "docs/tutorial"
# Call the function to create a new directory with modified filenames
create_new_directory_with_modified_files(source_directory_path, new_directory_path)
# Run nbconvert to convert .ipynb files to .rst in the new directory
convert_ipynb_to_rst(new_directory_path)
# Check out repo and set up Python
- name: Check out the repository
uses: actions/checkout@v4
with:
lfs: true

- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: 3.8
poetry-version: 1.2.2

#
- name: run python script after setting up
run: |
poetry run pip install nbconvert
poetry install
mkdir tutorial
poetry run python renaming.py
- name: remove notebooks from docs
run: rm *.ipynb

- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'Updating tutorial rsts for docs'
add: 'sed/docs/tutorial/'
21 changes: 0 additions & 21 deletions .github/workflows/generate-requirements.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This workflow will install Python dependencies, lint and run tests with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

# TODO: switch to the cached version
name: linting

on: [push]
Expand Down
42 changes: 0 additions & 42 deletions .github/workflows/pytest.yml

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: pytest

on:
push:
branches: [ main ]
pull_request:
branches: [main]

jobs:
pytest:
# Using matrix strategy
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
runs-on: ubuntu-latest
steps:
#-------------------------------------#
# Check out repo and set up Python #
#-------------------------------------#
- name: Check out the repository
uses: actions/checkout@v4
with:
lfs: true

- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: ${{matrix.python-version}}
poetry-version: 1.2.2

#------------------------#
# Run pytest #
#------------------------#
- name: Run tests
run: |
poetry run pytest
# Coveralls missing
34 changes: 34 additions & 0 deletions .github/workflows/update_requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: update requirements.txt

on:
# Triggers the workflow on push but only for the main branch
push:
branches: [ main ]
paths: [pyproject.toml]

jobs:
pytest:
runs-on: ubuntu-latest
steps:
# Check out repo and set up Python
- name: Check out the repository
uses: actions/checkout@v4
with:
lfs: true

- name: "Setup Python, Poetry and Dependencies"
uses: packetcoders/action-setup-cache-python-poetry@main
with:
python-version: 3.8
poetry-version: 1.2.2

# Generates and commits a requirements.txt used by readthedocs
- name: Export requirements.txt
run: poetry export --without-hashes --format=requirements.txt -o docs/requirements.txt -E docs -E notebook

- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'Updating requirements for docs'
add: 'docs/requirements.txt'

0 comments on commit 88caa16

Please sign in to comment.