-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See if tutorial autogeneration works
- Loading branch information
1 parent
a7cae25
commit b4c5fb5
Showing
4 changed files
with
392 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
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) |
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,38 @@ | ||
name: autogenerate docs from tutorials | ||
|
||
on: | ||
# Triggers the workflow on push but only for the main branch | ||
push: | ||
branches: [ workflow_trials ] | ||
paths: ['**.ipynb'] | ||
|
||
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 | ||
# Missing is to run the notebooks for now! | ||
- name: run python script | ||
run: poetry run python docs/tutorial/renaming.py | ||
|
||
- name: remove ipynbs | ||
run: rm docs/tutorial/*.ipynb | ||
|
||
- name: Commit changes | ||
uses: EndBug/add-and-commit@v9 | ||
with: | ||
default_author: github_actions | ||
message: 'Updating tutorial rsts for docs' | ||
add: 'docs/tutorial/' |
Large diffs are not rendered by default.
Oops, something went wrong.