Skip to content

Instantly share code, notes, and snippets.

@karm-patel
Last active July 13, 2022 06:31
Show Gist options
  • Save karm-patel/73d4947870815d3343ddb3ca4efd193a to your computer and use it in GitHub Desktop.
Save karm-patel/73d4947870815d3343ddb3ca4efd193a to your computer and use it in GitHub Desktop.

Understanding the workflows

There are 3 workflows that need to be passed after creating the PR.

image

1. black_format

This workflow checks if all notebooks are formatted as per black's guidelines. There are two ways to apply black on notebooks.

a) Manually:

$ pip install black[jupyter]==22.3.0 # check this version in requirements-dev.txt
$ black <path/to/notebook>

b) Pre-commit: we have already configured black in pre-commit.yaml file.

$ pip install pre-commit
$ pre-commit install

After the above configuration, on every commit, pre-commit will run black on modified notebooks.

Gotcha: black_format workflow checks all the notebooks in the repo, so it may be possible that you have already reformated your notebook but still workflow fails due to an existing un-formated notebook. In this case, you can search unformatted notebooks in logs (see below image) and put a comment mentioning the notebook name. image

2. static_import_check

You need to put import <package> in try..except ModuleNotFoundError block. This is only applicable when package is not in requirements.txt or it is not pre-installed in pip packages. Example: This workflow will fail on the following code.

import os
import pandas as pd
import tensorflow_probability as tfp

The above imports should be written as follows:

import os # pre-installed in python
import pandas as pd # available in requirements.txt
try:
  import tensorflow_probability as tfp # put try...except
except ModuleNotFoundError:
  %pip install -qqq tensorflow_probability # use -qqq flag
  import tensorflow_probability as tfp
  

3. execute_current_PR_notebook

This workflow execute your notebook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment