diff --git a/.github/workflows/document_tutorials.yml b/.github/workflows/document_tutorials.yml index 0e13deef..ad2f9bd2 100644 --- a/.github/workflows/document_tutorials.yml +++ b/.github/workflows/document_tutorials.yml @@ -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/' diff --git a/.github/workflows/generate-requirements.yml b/.github/workflows/generate-requirements.yml deleted file mode 100644 index f971a3d8..00000000 --- a/.github/workflows/generate-requirements.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Generate requirements.txt for readthedocs - -on: - push: - branches: [main] - -jobs: - generate-requirements: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - lfs: true - - name: Set up Python 3.8 - uses: actions/setup-python@v4 - with: - python-version: 3.8 - - name: Install Poetry - run: curl -sSL https://install.python-poetry.org | python3 - - - name: Export requirements.txt - run: poetry export --without-hashes --format=requirements.txt -o docs/requirements.txt -E docs -E notebook diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index c02f7fa2..857e4e5b 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -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] diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml deleted file mode 100644 index bb07fbd9..00000000 --- a/.github/workflows/pytest.yml +++ /dev/null @@ -1,42 +0,0 @@ -# This workflow will install Python dependencies, and run tests for multiple versions of Python -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: pytest - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - pytest: - runs-on: ubuntu-latest - strategy: - matrix: - python_version: ["3.8", "3.9", "3.10"] - - steps: - - uses: actions/checkout@v3 - with: - lfs: true - - name: Set up Python ${{ matrix.python_version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python_version }} - - name: Install dependencies - run: | - git lfs pull - python -m pip install --upgrade pip - python -m pip install pytest coverage coveralls - - name: Install package - run: | - python -m pip install . - - name: Test with pytest - run: | - coverage run -m pytest -sv --show-capture=no tests - - name: Submit to coveralls - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - coveralls --service=github diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 00000000..a816e5fc --- /dev/null +++ b/.github/workflows/testing.yml @@ -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 diff --git a/.github/workflows/update_requirements.yml b/.github/workflows/update_requirements.yml new file mode 100644 index 00000000..21c6d435 --- /dev/null +++ b/.github/workflows/update_requirements.yml @@ -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'