diff --git a/.github/ISSUE_TEMPLATE/bug.md b/.github/ISSUE_TEMPLATE/bug.md deleted file mode 100644 index cacde65..0000000 --- a/.github/ISSUE_TEMPLATE/bug.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Bug -about: Use this template for filing bugs -title: "" -labels: bug -assignees: '' - ---- - -## Required Prerequisites for filing a bug - -### You must follow ALL the steps in the [troubleshooting guide](https://github.com/fastai/fastpages/blob/master/_fastpages_docs/TROUBLESHOOTING.md). Not doing so may result in automatic closure of the issue. - - -## Required information - -1. Steps to reproduce the problem -2. A link to the notebook or markdown file where the error is occurring -3. If the error is happening in GitHub Actions, a link to the specific error along with how you are able to reproduce this error. You must provide this **in addition to the link to the notebook or markdown file**. -4. A screenshot / dump of relevant logs or error messages you are receiving from your local development environment. Instructions of running a local development server is provided in the [development guide](https://github.com/fastai/fastpages/blob/master/_fastpages_docs/DEVELOPMENT.md). diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 11fc491..0000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: '' -labels: enhancement -assignees: '' - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/chatops.yaml b/.github/workflows/chatops.yaml deleted file mode 100755 index 6bdfbd5..0000000 --- a/.github/workflows/chatops.yaml +++ /dev/null @@ -1,198 +0,0 @@ -name: Chatops -on: [issue_comment] - -permissions: - actions: write - pull-requests: write - contents: write - -jobs: - trigger-chatops: - if: (github.event.issue.pull_request != null) && contains(github.event.comment.body, '/preview') && (github.repository == 'fastai/fastpages') - env: - NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} - CHECK_RUN_NAME: "Draft-Site-Build" - runs-on: ubuntu-latest - steps: - - name: see payload - run: | - echo "FULL PAYLOAD:\n${PAYLOAD}\n" - echo "PR_PAYLOAD PAYLOAD:\n${PR_PAYLOAD}" - env: - PAYLOAD: ${{ toJSON(github.event) }} - PR_PAYLOAD: ${{ github.event.pull_request }} - - - name: verify env exists - id: get_status - run: | - if [ -z ${NETLIFY_AUTH_TOKEN} ]; then echo "::set-output name=status::public"; else echo "::set-output name=status::private"; fi - - - name: make comment on PR if env does not exist - if: steps.get_status.outputs.status == 'public' - run: | - ./_action_files/pr_comment.sh "Was not able to generate site preview due to absent credentials." - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ISSUE_NUMBER: ${{ github.event.issue.number }} - - - name: Fetch context about the PR that has been commented on - id: chatops - uses: machine-learning-apps/actions-chatops@master - with: - TRIGGER_PHRASE: "/preview" - env: # you must supply GITHUB_TOKEN - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up Python - uses: actions/setup-python@v1 - with: - python-version: 3.6 - - - name: install requests - run: pip3 install requests - - - name: add check run - id: create_check - if: steps.get_status.outputs.status == 'private' - shell: python - run: | - import os, requests - - sha = os.getenv('SHA') - token = os.getenv('GITHUB_TOKEN') - nwo = os.getenv('GITHUB_REPOSITORY') - name = os.getenv('CHECK_RUN_NAME') - - url = f'https://api.github.com/repos/{nwo}/check-runs' - - headers = {'authorization': f'token {token}', - 'accept': 'application/vnd.github.antiope-preview+json'} - - payload = { - 'name': f'{name}', - 'head_sha': f'{sha}', - 'status': 'in_progress', - 'output':{ - 'title': f'Building preview of site for {sha}.', - 'summary': ' ', - 'text': ' ' - }, - } - response = requests.post(url=url, headers=headers, json=payload) - print(response) - id = response.json()['id'] - print(f"::set-output name=id::{id}") - env: - SHA: ${{ steps.chatops.outputs.SHA }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: add label - if: steps.get_status.outputs.status == 'private' - run: | - import os, requests - nwo = os.getenv('GITHUB_REPOSITORY') - token = os.getenv('GITHUB_TOKEN') - pr_num = os.getenv('PR_NUM') - headers = {'Accept': 'application/vnd.github.symmetra-preview+json', - 'Authorization': f'token {token}'} - url = f"https://api.github.com/repos/{nwo}/issues/{pr_num}/labels" - data = {"labels": ["draft build pending"]} - result = requests.post(url=url, headers=headers, json=data) - # assert response.status_code == 201, f"Received status code of {response.status_code}" - print(result) - shell: python - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUM: ${{ steps.chatops.outputs.PULL_REQUEST_NUMBER }} - GITHUB_REPOSITORY: $GITHUB_REPOSITORY - - - name: Copy The PR's Branch Repository Contents - uses: actions/checkout@main - if: steps.get_status.outputs.status == 'private' - with: - ref: ${{ steps.chatops.outputs.SHA }} - - - name: convert notebooks and word docs to posts - uses: ./ # use the code in this repo to instead of fastai/fastpages@master - - - name: setup directories for Jekyll build - if: steps.get_status.outputs.status == 'private' - run: | - rm -rf _site - sudo chmod -R 777 . - - - name: Jekyll build with baseurl as root for netifly - if: steps.get_status.outputs.status == 'private' - uses: docker://fastai/fastpages-jekyll - with: - args: bash -c "jekyll build" - - - name: deploy to netlify - if: steps.get_status.outputs.status == 'private' - id: py - run: | - sudo npm install -g --unsafe-perm=true netlify-cli - netlify deploy --dir _site | tee _netlify_logs.txt - cat _netlify_logs.txt | python _action_files/parse_netlify.py - - - name: make comment on PR - if: steps.get_status.outputs.status == 'private' - run: | - MSG="A preview build of this branch has been generated for SHA: $SHA and can be viewed **live** at: ${URL}\n\nThe current fastpages site built from master can be viewed for comparison [here](https://fastpages.fast.ai/)" - echo "$MSG" - ./_action_files/pr_comment.sh "${MSG}" - env: - URL: ${{ steps.py.outputs.draft_url }} - SHA: ${{ steps.chatops.outputs.SHA }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ISSUE_NUMBER: ${{ github.event.issue.number }} - - - name: remove label - if: always() - run: | - import os, requests - nwo = os.getenv('GITHUB_REPOSITORY') - token = os.getenv('GITHUB_TOKEN') - pr_num = os.getenv('PR_NUM') - headers = {'Accept': 'application/vnd.github.symmetra-preview+json', - 'Authorization': f'token {token}'} - url = f"https://api.github.com/repos/{nwo}/issues/{pr_num}/labels/draft%20build%20pending" - result = requests.delete(url=url, headers=headers) - print(result) - shell: python - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PR_NUM: ${{ steps.chatops.outputs.PULL_REQUEST_NUMBER }} - GITHUB_REPOSITORY: $GITHUB_REPOSITORY - - # defensively clear check run each time - - name: clear check run - if: always() - continue-on-error: true - shell: python - run: | - import os, requests - - sha = os.getenv('SHA') - conclusion = os.getenv('WORKFLOW_CONCLUSION').lower() - token = os.getenv('GITHUB_TOKEN') - nwo = os.getenv('GITHUB_REPOSITORY') - check_run_id = os.getenv('CHECK_RUN_ID') - if not check_run_id: - quit() - - url = f'https://api.github.com/repos/{nwo}/check-runs/{check_run_id}' - headers = {'authorization': f'token {token}', - 'accept': 'application/vnd.github.antiope-preview+json'} - - data = { - 'conclusion': f'{conclusion}', - } - response = requests.patch(url=url, headers=headers, json=data) - print(response) - env: - SHA: ${{ steps.chatops.outputs.SHA }} - WORKFLOW_CONCLUSION: ${{ job.status }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CHECK_RUN_ID: ${{ steps.create_check.outputs.id }} diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml deleted file mode 100755 index a2b2075..0000000 --- a/.github/workflows/docker.yaml +++ /dev/null @@ -1,33 +0,0 @@ -name: Build-Docker -on: - push: - paths: - - Gemfile* - branches: - - master - pull_request: - paths: - - Gemfile* - -jobs: - jekyll-fastpages: - if: github.repository == 'fastai/fastpages' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@main - - - name: setup directories for Jekyll build - run: sudo chmod -R 777 . - - - name: build container - run: | - docker build -t fastai/fastpages-jekyll -f _action_files/fastpages-jekyll.Dockerfile . - - - name: push container - if: github.event == 'push' - run: | - echo ${PASSWORD} | docker login -u $USERNAME --password-stdin - docker push fastai/fastpages-jekyll - env: - USERNAME: ${{ secrets.DOCKER_USERNAME }} - PASSWORD: ${{ secrets.DOCKER_PASSWORD }} diff --git a/.github/workflows/issue_reminder.yaml b/.github/workflows/issue_reminder.yaml deleted file mode 100644 index 1e6634a..0000000 --- a/.github/workflows/issue_reminder.yaml +++ /dev/null @@ -1,29 +0,0 @@ -name: Issue Reminder -on: - issues: - types: [opened] - -permissions: - actions: write - pull-requests: write - contents: write - -jobs: - issue_comment: - if: | - (github.repository == 'fastai/fastpages') - runs-on: ubuntu-latest - steps: - - name: Comment on issue - uses: actions/github-script@0.6.0 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - var url = 'https://github.com/fastai/fastpages/blob/master/_fastpages_docs/TROUBLESHOOTING.md' - var msg = `Thank you for opening an issue. If this issue is related to a bug, please follow the steps and provide the information outlined in the [Troubleshooting Guide](${url}). Failure to follow these instructions may result in automatic closing of this issue.` - github.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: msg - }) diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml deleted file mode 100755 index 17eaf5d..0000000 --- a/.github/workflows/setup.yaml +++ /dev/null @@ -1,112 +0,0 @@ -name: Setup -on: push - -permissions: - actions: write - pull-requests: write - contents: write - deployments: write - pages: write - statuses: write - -jobs: - setup: - if: (github.event.commits[0].message == 'Initial commit') && (github.run_number == 1) - runs-on: ubuntu-latest - steps: - - name: Set up Python - uses: actions/setup-python@v1 - with: - python-version: 3.6 - - - name: Copy Repository Contents - uses: actions/checkout@v2 - - - name: modify files - run: | - import re, os - from pathlib import Path - from configparser import ConfigParser - config = ConfigParser() - - nwo = os.getenv('GITHUB_REPOSITORY') - username, repo_name = nwo.split('/') - readme_template_path = Path('_fastpages_docs/README_TEMPLATE.md') - readme_path = Path('README.md') - config_path = Path('_config.yml') - pr_msg_path = Path('_fastpages_docs/_setup_pr_template.md') - settings = Path('_action_files/settings.ini') - - assert readme_template_path.exists(), 'Did not find _fastpages_docs/README_TEMPLATE.md in the current directory!' - assert readme_path.exists(), 'Did not find README.md in the current directory!' - assert config_path.exists(), 'Did not find _config.yml in the current directory!' - assert pr_msg_path.exists(), 'Did not find _fastpages_docs/_setup_pr_template.md in the current directory!' - assert settings.exists(), 'Did not find _action_files/settings.ini in the current directory!' - - # edit settings.ini file to inject baseurl - config.read(settings) - config['DEFAULT']['baseurl'] = f'/{repo_name}' - with open('_action_files/settings.ini', 'w') as configfile: - config.write(configfile) - - # replace content of README with template - readme = readme_template_path.read_text().replace('{_username_}', username).replace('{_repo_name_}', repo_name) - readme_path.write_text(readme) - - # update _config.yml - cfg = config_path.read_text() - cfg = re.sub(r'^(github_username: )(fastai)', fr'\g<1>{username}', cfg, flags=re.MULTILINE) - cfg = re.sub(r'^(baseurl: )("")', r'\1"/{}"'.format(repo_name), cfg, flags=re.MULTILINE) - cfg = re.sub(r'^(github_repo: ")(fastpages)', r'\1{}'.format(repo_name), cfg, flags=re.MULTILINE) - cfg = re.sub(r'^(url: "https://)(fastpages.fast.ai)(")', fr'\g<1>{username}.github.io\3', cfg, flags=re.MULTILINE) - cfg = re.sub('UA-57531313-5', '', cfg, flags=re.MULTILINE) - config_path.write_text(cfg) - - # prepare the pr message - pr = pr_msg_path.read_text().replace('{_username_}', username).replace('{_repo_name_}', repo_name) - pr_msg_path.write_text(pr) - shell: python - - - name: commit changes - run: | - git config --global user.email "${GH_EMAIL}" - git config --global user.name "${GH_USERNAME}" - git checkout -B fastpages-automated-setup - git rm CNAME action.yml - git rm _notebooks/2020-02-21-introducing-fastpages.ipynb - git rm _notebooks/2020-09-01-fastcore.ipynb || true - git rm _notebooks/2020-11-17-linkcheck.ipynb || true - git rm -rf _notebooks/fastcore_imgs - git rm -rf _notebooks/fastlinkcheck_images - git rm _posts/2020-03-06-fastpages-actions.md - git rm _posts/*codespaces.md || true - git rm -rf images/fastpages_posts - git rm .github/workflows/chatops.yaml - git rm .github/workflows/docker.yaml - git rm .github/workflows/issue_reminder.yaml - git rm .github/workflows/setup.yaml - git rm .github/ISSUE_TEMPLATE/bug.md - git rm .github/ISSUE_TEMPLATE/feature_request.md - git rm _word/*.docx - git add _config.yml README.md _fastpages_docs/ _action_files/settings.ini - git commit -m'setup repo' - git push -f --set-upstream origin fastpages-automated-setup - env: - GH_EMAIL: ${{ github.event.commits[0].author.email }} - GH_USERNAME: ${{ github.event.commits[0].author.username }} - - - name: Open a PR - uses: actions/github-script@0.5.0 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - var fs = require('fs'); - var contents = fs.readFileSync('_fastpages_docs/_setup_pr_template.md', 'utf8'); - github.pulls.create({ - owner: context.repo.owner, - repo: context.repo.repo, - title: 'Initial Setup', - head: 'fastpages-automated-setup', - base: 'master', - body: `${contents}` - }) diff --git a/CNAME b/CNAME deleted file mode 100644 index 18a648f..0000000 --- a/CNAME +++ /dev/null @@ -1 +0,0 @@ -fastpages.fast.ai diff --git a/README.md b/README.md index 6b38105..727f1ee 100755 --- a/README.md +++ b/README.md @@ -1,571 +1,29 @@ -[//]: # (BADGES SECTION: change `fastai` with your GitHub username and `fastpages` with the name of your repo) +[//]: # (This template replaces README.md when someone creates a new repo with the fastpages template.) -![](https://github.com/fastai/fastpages/workflows/CI/badge.svg) -![](https://github.com/fastai/fastpages/workflows/GH-Pages%20Status/badge.svg) -[![](https://img.shields.io/static/v1?label=fastai&message=nbdev&color=57aeac&labelColor=black&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAjCAYAAABhCKGoAAAGMklEQVR42q1Xa0xTVxyfKExlui9blszoB12yDzPGzJhtyT5s+zBxUxELBQSHm2ZzU5epBF/LclXae29pCxR5VEGgLQUuIOKDuClhm8oUK7S9ve19tLTl/fA5p9MNc/Y/hRYEzGLxJL/87zk9Ob/zf5++NGHMALzYgdDYmWh0Qly3Lybtwi6lXdpN2cWN5A0+hrQKe5R2PoN2uD+OKcn/UF5ZsVduMmyXVRi+jzebdmI5/juhwrgj3mTI2GA0vvsUIcMwM7GkOD42t7Mf6bqHkFry2yk7X5PXcxMVDN5DGtFf9NkJfe6W5iaUyFShjfV1KPlk7VPAa0k11WjzL+eRvMJ4IKQO0dw8SydJL+Op0u5cn+3tQTn+fqTivTbQpiavF0iG7iGt6NevKjpKpTbUo3hj+QO47XB8hfHfIGAelA+T6mqQzFi+e0oTKm3iexQnXaU56ZrK5SlVsq70LMF7TuX0XNTyvi1rThzLST3TgOCgxwD0DPwDGoE07QkcSl/m5ynbHWmZVm6b0sp9o2DZN8aTZtqk9w9b2G2HLbbvsjlx+fry0vwU0OS5SH68Ylmilny3c3x9SOvpRuQN7hO8vqulZQ6WJMuXFAzcRfkDd5BG8B1bpc+nU0+fQtgkYLIngOEJwGt/J9UxCIJg1whJ05Ul4IMejbsLqUUfOjJKQnCDr4ySHMeO1/UMIa3UmR9TUpj7ZdMFJK8yo6RaZjLAF/JqM/rifCO+yP4AycGmlgUaT9cZ0OYP2um5prjBLhtvLhy68Fs7RFqbRvSlf15ybGdyLcPJmcpfIcIuT4nqqt+Sa2vaZaby1FB+JGi1c9INhuiv9fpIysItIh3CVgVAzXfEE1evzse/bwr8bolcAXs+zcqKXksQc5+FD2D/svT06I8IYtaUeZLZzsVm+3oRDmON1Ok/2NKyIJSs0xnj84RknXG6zgGEE1It+rsPtrYuDOxBKAJLrO1qnW7+OpqeNxF4HWv6v4Rql3uFRvL/DATnc/29x4lmy2t4fXVjY+ASGwylm8DBvkSm2gpgx1Bpg4hyyysqVoUuFRw0z8+jXe40yiFsp1lpC9navlJpE9JIh7RVwfJywmKZO4Hkh02NZ1FilfkJLi1B4GhLPduAZGazHO9LGDX/WAj7+npzwUQqvuOBoo1Va91dj3Tdgyinc0Dae+HyIrxvc2npbCxlxrJvcW3CeSKDMhKCoexRYnUlSqg0xU0iIS5dXwzm6c/x9iKKEx8q2lkV5RARJCcm9We2sgsZhGZmgMYjJOU7UhpOIqhRwwlmEwrBZHgCBRKkKX4ySVvbmzQnXoSDHWCyS6SV20Ha+VaSFTiSE8/ttVheDe4NarLxVB1kdE0fYAgjGaOWGYD1vxKrqmInkSBchRkmiuC4KILhonAo4+9gWVHYnElQMEsAxbRDSHtp7dq5CRWly2VlZe/EFRcvDcBQvBTPZeXly1JMpvlThzBBRASBoDsSBIpgOBQV6C+sUJzffwflQX8BTevCTZMZeoslUo9QJJZYTZDw3RuIKtIhlhXdfhDoJ7TTXY/XdBBpgUshwFMSRYTVwim7FJvt6aFyOnoVKqc7MZQDzzNwsmnd3UegCudl8R2qzHZ7bJbQoYGyn692+zMULCfXenoOacTOTBUnJYRFsq+5+a3sjp5BXM6hEz7ObHNoVEIHyocekiX6WIiykwWDd1HhzT8RzY2YqxnK0HNQBJtW500ddiwrDgdIeCABZ4MPnKQdk9xDhUP3wfHSqbBI9v/e9jo0Iy30cCOgAMyVgMMVCMwql/cQxfKp2R1dWWrRm0PzUkrIXC9ykDY+hnJ5DqkE709guriwSRgGzWTQCPABWJZ6vbNHQlgo099+CCEMPnF6xnwynYETEWd8ls0WPUpSWnTrfuAhAWacPslUiQRNLBGXFSA7TrL8V3gNhesTnLFY0jb+bYWVp0i7SClY184jVtcayi7so2yuA0r4npbjsV8CJHZhPQ7no323cJ5w8FqpLwR/YJNRnHs0hNGs6ZFw/Lpsb+9oj/dZSbuL0XUNojx4d9Gch5mOT0ImINsdKyHzT9Muz1lcXhRWbo9a8J3B72H8Lg6+bKb1hyWMPeERBXMGRxEBCM7Ddfh/1jDuWhb5+QkAAAAASUVORK5CYII=)](https://github.com/fastai/nbdev) -[![](https://img.shields.io/static/v1?label=View%20Demo%20Site&message=link&labelColor=2f363d&color=blue&style=flat&logo=github&logoColor=959da5)](https://fastpages.fast.ai/) +![](https://github.com/shreya-ahujaa/fastpages/workflows/CI/badge.svg) +![](https://github.com/shreya-ahujaa/fastpages/workflows/GH-Pages%20Status/badge.svg) +[![](https://img.shields.io/static/v1?label=fastai&message=fastpages&color=57aeac&labelColor=black&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAjCAYAAABhCKGoAAAGMklEQVR42q1Xa0xTVxyfKExlui9blszoB12yDzPGzJhtyT5s+zBxUxELBQSHm2ZzU5epBF/LclXae29pCxR5VEGgLQUuIOKDuClhm8oUK7S9ve19tLTl/fA5p9MNc/Y/hRYEzGLxJL/87zk9Ob/zf5++NGHMALzYgdDYmWh0Qly3Lybtwi6lXdpN2cWN5A0+hrQKe5R2PoN2uD+OKcn/UF5ZsVduMmyXVRi+jzebdmI5/juhwrgj3mTI2GA0vvsUIcMwM7GkOD42t7Mf6bqHkFry2yk7X5PXcxMVDN5DGtFf9NkJfe6W5iaUyFShjfV1KPlk7VPAa0k11WjzL+eRvMJ4IKQO0dw8SydJL+Op0u5cn+3tQTn+fqTivTbQpiavF0iG7iGt6NevKjpKpTbUo3hj+QO47XB8hfHfIGAelA+T6mqQzFi+e0oTKm3iexQnXaU56ZrK5SlVsq70LMF7TuX0XNTyvi1rThzLST3TgOCgxwD0DPwDGoE07QkcSl/m5ynbHWmZVm6b0sp9o2DZN8aTZtqk9w9b2G2HLbbvsjlx+fry0vwU0OS5SH68Ylmilny3c3x9SOvpRuQN7hO8vqulZQ6WJMuXFAzcRfkDd5BG8B1bpc+nU0+fQtgkYLIngOEJwGt/J9UxCIJg1whJ05Ul4IMejbsLqUUfOjJKQnCDr4ySHMeO1/UMIa3UmR9TUpj7ZdMFJK8yo6RaZjLAF/JqM/rifCO+yP4AycGmlgUaT9cZ0OYP2um5prjBLhtvLhy68Fs7RFqbRvSlf15ybGdyLcPJmcpfIcIuT4nqqt+Sa2vaZaby1FB+JGi1c9INhuiv9fpIysItIh3CVgVAzXfEE1evzse/bwr8bolcAXs+zcqKXksQc5+FD2D/svT06I8IYtaUeZLZzsVm+3oRDmON1Ok/2NKyIJSs0xnj84RknXG6zgGEE1It+rsPtrYuDOxBKAJLrO1qnW7+OpqeNxF4HWv6v4Rql3uFRvL/DATnc/29x4lmy2t4fXVjY+ASGwylm8DBvkSm2gpgx1Bpg4hyyysqVoUuFRw0z8+jXe40yiFsp1lpC9navlJpE9JIh7RVwfJywmKZO4Hkh02NZ1FilfkJLi1B4GhLPduAZGazHO9LGDX/WAj7+npzwUQqvuOBoo1Va91dj3Tdgyinc0Dae+HyIrxvc2npbCxlxrJvcW3CeSKDMhKCoexRYnUlSqg0xU0iIS5dXwzm6c/x9iKKEx8q2lkV5RARJCcm9We2sgsZhGZmgMYjJOU7UhpOIqhRwwlmEwrBZHgCBRKkKX4ySVvbmzQnXoSDHWCyS6SV20Ha+VaSFTiSE8/ttVheDe4NarLxVB1kdE0fYAgjGaOWGYD1vxKrqmInkSBchRkmiuC4KILhonAo4+9gWVHYnElQMEsAxbRDSHtp7dq5CRWly2VlZe/EFRcvDcBQvBTPZeXly1JMpvlThzBBRASBoDsSBIpgOBQV6C+sUJzffwflQX8BTevCTZMZeoslUo9QJJZYTZDw3RuIKtIhlhXdfhDoJ7TTXY/XdBBpgUshwFMSRYTVwim7FJvt6aFyOnoVKqc7MZQDzzNwsmnd3UegCudl8R2qzHZ7bJbQoYGyn692+zMULCfXenoOacTOTBUnJYRFsq+5+a3sjp5BXM6hEz7ObHNoVEIHyocekiX6WIiykwWDd1HhzT8RzY2YqxnK0HNQBJtW500ddiwrDgdIeCABZ4MPnKQdk9xDhUP3wfHSqbBI9v/e9jo0Iy30cCOgAMyVgMMVCMwql/cQxfKp2R1dWWrRm0PzUkrIXC9ykDY+hnJ5DqkE709guriwSRgGzWTQCPABWJZ6vbNHQlgo099+CCEMPnF6xnwynYETEWd8ls0WPUpSWnTrfuAhAWacPslUiQRNLBGXFSA7TrL8V3gNhesTnLFY0jb+bYWVp0i7SClY184jVtcayi7so2yuA0r4npbjsV8CJHZhPQ7no323cJ5w8FqpLwR/YJNRnHs0hNGs6ZFw/Lpsb+9oj/dZSbuL0XUNojx4d9Gch5mOT0ImINsdKyHzT9Muz1lcXhRWbo9a8J3B72H8Lg6+bKb1hyWMPeERBXMGRxEBCM7Ddfh/1jDuWhb5+QkAAAAASUVORK5CYII=)](https://github.com/fastai/fastpages) -[//]: # (END OF BADGES SECTION) +https://shreya-ahujaa.github.io/fastpages/ -# Welcome To `fastpages` +# My Blog -> An easy to use blogging platform, with support for Jupyter notebooks, Word docs, and Markdown. -![](images/diagram.png) +_powered by [fastpages](https://github.com/fastai/fastpages)_ -`fastpages` uses [GitHub Actions](https://github.com/features/actions) to simplify the process of creating [Jekyll blog posts](https://jekyllrb.com/) on [GitHub Pages](https://pages.github.com/) from a variety of input formats. -### `fastpages` provides the following features: +## What To Do Next? -- Create posts containing code, outputs of code (which can be interactive), formatted text, etc directly from [Jupyter Notebooks](https://jupyter.org/); Notebook posts support features such as: - - Interactive visualizations made with [Altair](https://altair-viz.github.io/) remain interactive. - - Hide or show cell input and output. - - Collapsable code cells that are either open or closed by default. - - Define the Title, Summary and other metadata via a special markdown cells - - Ability to add links to [Colab](https://colab.research.google.com/), [Deepnote](https://deepnote.com/) and GitHub automatically. -- Support for comments, supported natively through GitHub Issues. -- Built-in search. -- Support for customizing the styling of your site. -- Embed Twitter cards and YouTube videos. -- Categorization of blog posts by user-supplied tags for discoverability. -- Create and edit [Markdown](https://guides.github.com/features/mastering-markdown/) posts. -- Create posts, including formatting and images, directly from Microsoft Word documents. -- Write posts on your local machine and [preview them with live reload](#running-the-blog-on-your-local-machine). +Great! You have setup your repo. Now its time to start writing content. Some helpful links: -See below for a more detailed list of features. +- [Writing Blogs With Jupyter](https://github.com/fastai/fastpages#writing-blog-posts-with-jupyter) +- [Writing Blogs With Markdown](https://github.com/fastai/fastpages#writing-blog-posts-with-markdown) -**[See the demo site](https://fastpages.fast.ai/)** +- [Writing Blog Posts With Word](https://github.com/fastai/fastpages#writing-blog-posts-with-microsoft-word) ---- +- [(Optional) Preview Your Blog Locally](_fastpages_docs/DEVELOPMENT.md) - +Note: you may want to remove example blog posts from the `_posts`, `_notebooks` or `_word` folders (but leave them empty, don't delete these folders) if you don't want these blog posts to appear on your site. -- [Welcome To `fastpages`](#welcome-to-fastpages) - - [`fastpages` provides the following features:](#fastpages-provides-the-following-features) - - [Setup Instructions](#setup-instructions) - - [Customizing Blog Posts With Front Matter](#customizing-blog-posts-with-front-matter) - - [Configure Title & Summary](#configure-title--summary) - - [Table of Contents](#table-of-contents) - - [Colab, Binder, Deepnote and GitHub Badges](#colab-binder-deepnote-and-github-badges) - - [Categories](#categories) - - [Enabling Comments](#enabling-comments) - - [Setting an Image For Social Media](#setting-an-image-for-social-media) - - [Hiding A Blog Post](#hiding-a-blog-post) - - [Pinning A Blog Post](#pinning-a-blog-post) - - [Toggle Search Visibility](#toggle-search-visibility) - - [Site Wide Configuration Options](#site-wide-configuration-options) - - [Adjusting Page Width](#adjusting-page-width) - - [Annotations and Highlighting With hypothes.is](#annotations-and-highlighting-with-hypothesis) - - [Subscribing with RSS](#subscribing-with-rss) - - [Syntax Highlighting](#syntax-highlighting) - - [Dark Mode](#dark-mode) - - [Adding Citations via BibTeX](#adding-citations-via-bibtex) - - [Writing Blog Posts With Jupyter](#writing-blog-posts-with-jupyter) - - [Hide Input/Output Cells](#hide-inputoutput-cells) - - [Collapsable Code Cells](#collapsable-code-cells) - - [Embedded Twitter and YouTube Content](#embedded-twitter-and-youtube-content) - - [Adding Footnotes](#adding-footnotes) - - [Automatically Convert Notebooks To Blog Posts](#automatically-convert-notebooks-to-blog-posts) - - [Writing Blog Posts With Markdown](#writing-blog-posts-with-markdown) - - [Writing Blog Posts With Microsoft Word](#writing-blog-posts-with-microsoft-word) - - [Specifying front-matter for Word documents](#specifying-front-matter-for-word-documents) -- [Running the blog on your local machine](#running-the-blog-on-your-local-machine) -- [Using The GitHub Action & Your Own Custom Blog](#using-the-github-action--your-own-custom-blog) - - [Optional Inputs](#optional-inputs) -- [Contributing To Fastpages](#contributing-to-fastpages) -- [Upgrading Fastpages](#upgrading-fastpages) -- [FAQ](#faq) -- [Customizing Fastpages](#customizing-fastpages) -- [Troubleshooting fastpages](#troubleshooting-fastpages) - - - - -## Setup Instructions - -1. Generate a copy of this repo by clicking [on this link](https://github.com/fastai/fastpages/generate). Make sure to sign in to your account, or you will see a 404 error. Name your repo anything you like **except** {your-username}.github.io. - -2. **GitHub Actions will automatically open a PR** on your new repository ~ 30 seconds after the copy is created. Follow the instructions in that PR to continue. - ->If you are not seeing a PR, please make sure you have third party actions enabled in your organization: **Settings -> Actions -> Actions Permissions -> Enable local and third party Actions for this repository** - -For a live walk-through of the setup steps (with some additional tips) see this [video tutorial of setting up a fastpages blog](https://youtu.be/L0boq3zqazI) by Abdul Majed. - - -3. In some cases because of permissions step 2 may fail to create a Pull Request. If this occurs, go to your repository settings and in the Actions section, grant `Read and Write` permissions and check `Allow GitHub Actions to create and approve pull requests`. - -![](2022-05-15-07-21-16.png) - -Once you have granted permissions, go to the `Actions` tab at the top of your repository home page, where you will be presented with a list of Actions runs. First click on the failed run (the item with the red X): - -![](2022-05-15-07-25-15.png) - -You will be taken to a screen where there will be a button on the upper right hand side allowing you to re-run jobs. - -![](2022-05-15-07-24-25.png) - -After doing this, a pull request should appear. - -4. To create your first post, add content in the `_posts`, `_notebooks` or `_word` directories. You can follow examples of content in those folders in this repo of how to structure the content. The most important thing to pay attention to is the front matter, which is discussed in more detail below. Furthermore, you can add additional pages that will appear on your blog's navbar in the `_pages` directory. Note that content in the `_word` directory does not support front matter. - -## Customizing Blog Posts With Front Matter - -[Front matter](https://jekyllrb.com/docs/front-matter/) allows you to toggle various options on/off for each blog post, as well as pass metadata to various features of fastpages. - -In a notebook, front matter is defined as a markdown cell at the beginning of the notebook with the following contents: - - ```markdown - # "Title" - > "Awesome summary" - - - toc: false - - branch: master - - badges: true - - comments: true - - categories: [fastpages, jupyter] - - image: images/some_folder/your_image.png - - hide: false - - search_exclude: true - - metadata_key1: metadata_value1 - - metadata_key2: metadata_value2 - ``` - -Similarly, in a markdown document the same front matter would be defined like this at the beginning of the document: - - ```yaml - --- - title: "My Title" - description: "Awesome description" - layout: post - toc: false - comments: true - image: images/some_folder/your_image.png - hide: false - search_exclude: true - categories: [fastpages, jupyter] - metadata_key1: metadata_value1 - metadata_key2: metadata_value2 - --- - ``` - -Additional metadata is optional and allows you to set custom [front matter](https://jekyllrb.com/docs/front-matter/). - -Note that anything defined in front matter must be valid YAML. **Failure to provide valid YAML could result in your page not rendering** in your blog. For example, if you want a colon in your title you must escape it with double quotes like this: - -` - title: "Deep learning: A tutorial"` - -See this [tutorial on YAML](https://rollout.io/blog/yaml-tutorial-everything-you-need-get-started/) for more information. - -### Configure Title & Summary - - Replace `Title`, with your desired title, and `Awesome summary` with your desired summary. - -**Note:** It is recommended to enclose these values in double quotes, so that you can escape colons and other characters that may break the YAML parser. - -### Table of Contents - - `fast_template` will automatically generate a table of contents for you based on [markdown headers](https://guides.github.com/features/mastering-markdown/)! You can toggle this feature on or off by setting `toc:` to either `true` or `false`. - -### Colab, Binder, Deepnote and GitHub Badges - -This option works for **notebooks only** - - - The `branch` field is used to optionally render a link your notebook to Colab and GitHub in your blog post. It'll default to `master` if you don't specify it in the notebook. - - If you do not want to show Colab / GitHub badges on your blog post (perhaps because your repo is private and the links would be broken) set `badges` to `false`. This defaults to `true` - - By default, when you omit this parameter from your front matter, or you set `badges: true`, **all four badges (GitHub, Binder, Deepnote, Colab)** will appear by default. You can adjust these defaults in with the `default_badges` parameter in [Site Wide Configuration Options](#site-wide-configuration-options). - - If only want to hide a badge on an individual post, you can set the front matter `hide_{github,colab,binder,deepnote}_badge: true`. For example, if you wanted to hide the Binder badge for an individual notebook but you want the other badges to show up, you can set this in your front matter: - - ```yaml - - badges: true - - hide_binder_badge: true - ``` - - **Note about Binder**: Binder allows you to customize the dependencies and other aspects of the Jupyter Notebook environment for your readers. The easiest way is to add a `requirements.txt` file with common packages you use for all your notebooks at the root of your repository, you can learn more [on the official Binder docs](https://mybinder.readthedocs.io/en/latest/introduction.html). - -### Categories - - You can have a comma seperated list inside square brackets of categories for a blog post, which will make the post visible on the tags page of your blog's site. For example: - - In a notebook: - - ``` - # "My Title" - - categories: [fastpages, jupyter] - ``` - - In a markdown document: - - ``` - --- - title: "My Title" - categories: [fastpages, jupyter] - --- - ``` - - You can see a preview of what this looks like [here](https://fastpages.fast.ai/categories/). - - - - You can toggle the display of tags on/off by setting `show_tags` to `true` or `false` in `_config.yml`: - -```yaml -# Set this to true to display tags on each post -show_tags: true -``` - -### Enabling Comments - -Commenting on blog posts is powered by [Utterances](https://github.com/utterance/utterances), an open-source and ad-free way of implementing comments. All comments are stored in issues on your blog's GitHub repo. You can turn this on setting `comments` to `true`. This defaults to `false`. - -To enable comments with [Utterances](https://github.com/utterance/utterances) you will need to do the following: - - - Make sure the repo is public, otherwise your readers will not be able to view the issues/comments. - - Make sure the [utterances app](https://github.com/apps/utterances) is installed on the repo, otherwise users will not be able to post comments. - - If your repo is a fork, navigate to it's settings tab and confirm the issues feature is turned on. - -### Setting an Image For Social Media - -On social media sites like Twitter, an image preview can be automatically shown with your URL. Specifying the front matter `image` provides this metadata to social media sites to render this image for you. You can set this value as follows: - -`- image: images/diagram.png` - -Note: for this setting **you can only reference image files and folders in the `/images` folder of your repo.** - -### Hiding A Blog Post - -You may want to prevent a blog post from being listed on the home page, but still have a public url that you can preview or share discreetly. You can hide a blog post from the home page by setting the front matter `hide` to `true`. This is set to `false` by default. - -It is recommended that you use [permalinks](https://jekyllrb.com/docs/permalinks/) in order to generate a predictable url for hidden blog posts. You can also set the front matter `search_exclude` to `true` if you don't want users to find your hidden post in a search. - -### Pinning A Blog Post - -By default, posts are sorted by date on your homepage. However, you may want one or more blog posts to always appear at the very top of your homepage. In other words, you may want certain posts to be "pinned" or "sticky". To accomplish this, specify the `sticky_rank` front matter in the order you would like your sticky posts to appear. Blog posts that do not set this parameter are sorted in the default way by date after the sticky posts. - -For example, consider these three markdown posts (also works for notebooks). - -`2020-01-01-Post-One.md` -```yaml ---- -title: Post One -sticky_rank: 1 ---- -``` - -`2020-02-01-Post-Two.md` -```yaml ---- -title: Post Two -sticky_rank: 2 ---- -``` - -`2020-04-01-Post-Three.md` -```yaml ---- -title: Post Three ---- -``` - -However, since `sticky_rank` is specified, blog posts will **first be sorted by sticky_rank in ascending order, then by date in descending order**, so the order of these posts will appear like so: - -- Post One -- Post Two -- Post Three - -_Without `sticky_rank` the above posts would actually be sorted in reverse order due to the dates associated with each post._ - -_Note: pinning also works for notebooks:_ - -``` -# "My cool blog post" -> "Description of blog post" - -- sticky_rank: 2 -``` - -### Toggle Search Visibility - -fastpages comes with built in keyword search powered by [lunr.js](https://lunrjs.com/). You can prevent a blog post or page from appearing in search results by setting the front matter `search_exclude` to `false`. This is set to `true` by default. - - -## Site Wide Configuration Options - -**It is recommended that everyone personalizes their blogging site by setting site-wide configration options**. These options can be found in `/_config.yml`. Below is a description of various options that are available. - -- `title`: this is the title that appears on the upper left hand corner on the header of all your pages. -- `description`: this description will show up in various places when a preview for your site is generated (for example, on social media). -- `github_username`: this allows your site to display a link to your GitHub page in the footer. -- `github_repo`: this allows your site to render links back to your repository for various features such as links to GitHub, Colab and Deepnote for notebooks. -- `url`: This does not need to be changed unless you have a custom domain. **Note: leave out the trailing / from this value.** -- `baseurl`: See the comments in `/_config.yml` for instructions ( "Special Instructions for baseurl" on setting this value properly. If you do not have a custom domain, then you can likely ignore this option. -- `email`: this is currently unused. Ignore. -- `twitter_username`: creates a link in your footer to your twitter page. -- `use_math`: Set this to `true` to get LaTeX math equation support. This is off by default as it otherwhise loads javascript into each page that may not be used. -- `show_description`: This shows a description under the title of your blog posts on your homepage that contains a list of your blog posts. Set to `true` by default. -- `google_analytics`: Optionally use a [Google Analytics](http://www.google.com/analytics/) ID for tracking if desired. -- `show_image`: If set to true, this uses the `image` parameter in the front matter of your blog posts to render a preview of your blogs as shown below. This is set to `false` by default. - When show_image is set to `true` your homepage will look like this: - - ![home page](/_fastpages_docs/_show_image_true.png) - -- `show_tags`: You can toggle the display of tags on your blog posts on or off by setting this value to `false`. This is set to `true` by default, which which renders the following links for tags on your blog posts like this: - - ![tags](_fastpages_docs/_post_tags.png) - -- `pagination`: This is the maximum number of posts to show on each page of your home page. Any posts exceeding this amount will be paginated onto another page. This is set to `15` by default. When this is triggered, you will see pagination at the bottom of your home page appear like this: - - ![paginate](_fastpages_docs/_paginate.png) - - Note: if you are using an older version of fastpages, **you cannot use the automated upgrade process** to get pagination. Instead you must follow these steps: - - 1. Rename your index.md file to index.html - > mv index.md index.html - 2. Replace the `Gemfile` and `Gemfile.lock` in the root of your repo with the files in this repo. - 3. Edit your `_config.yml` as follows (look at [_config.yml](_config.yml) for an example): - ```yaml - gems: - - jekyll-paginate - - paginate: 10 - paginate_path: /page:num/ - ``` - - _Alternatively, you can copy all of your posts over to a newly created repository created from the fastpages template._ - -- `default_badges`: By default GitHub, Binder, Deepnote, and Colab badges will show up on notebook blog posts. You can adjust these defaults by setting the appropriate value in `default_badges` to false. For example, if you wanted to turn Binder badges off by default, you would change `default_badges` to this: - - ```yaml - default_badges: - github: true - binder: false - deepnote: false - colab: true - ``` - -- `html_escape`: this allows you to toggle escaping of HTML in various components of blog posts on or off. At this moment, you can only toggle this for the `description` field in your posts. -This is set to `false` by default. - -## Adjusting Page Width - -You can adjust the page width of fastpages on various devices by editing [/_sass/minima/custom-variables.scss](_sass/minima/custom-variables.scss). - -These are the default values, which can be adjusted to suit your preferences: - -```scss -// width of the content area -// can be set as "px" or "%" -$content-width: 1000px; -$on-palm: 800px; -$on-laptop: 1000px; -$on-medium: 1000px; -$on-large: 1200px; -``` - -## Annotations and Highlighting With hypothes.is - -[hypothes.is](https://web.hypothes.is/) is an open platform that provides a way to annotate and higlight pages, which can be either public or private. When this feature is enabled, readers of your blog will be presented with the following tooltip when highlighting text: - -![annotation](_fastpages_docs/annotate.png) - -**This is disabled by default in fastpages.** You can enable or disable this in your [_config.yml](_config.yml) file by setting `annotations` to `true` or `false`: - -```yaml -# Set this to true to turn on annotations with hypothes.is -annotations: false -``` - -> You can customize hypothes.is by reading [these configuration options](http://h.readthedocs.io/projects/client/en/latest/publishers/config/). It is also a good idea to read [these docs](https://web.hypothes.is/for-publishers/#embedding) if you want to do more with hypothes.is. However, before trying to customize this feature you should read the [customizing fastpages](#customizing-fastpages) section for important caveats. - -## Subscribing with RSS - -You can direct your readers to subscribe with [RSS feeds](https://en.wikipedia.org/wiki/RSS). There are many RSS subscription services available on the internet. Some examples include: - -1. [Feedrabbit](https://feedrabbit.com/) -2. [Blogtrottr](https://blogtrottr.com/) - -## Syntax Highlighting - -`fastpages` overrides the default syntax highlighting of minima with the [Dracula theme](https://draculatheme.com/). - -- The default highlighting in fastpages looks like this: - - ![default-highlighting](_fastpages_docs/highlight_dracula.png) - -- However, you can make the syntax highlighting to look like this, if you choose: - - ![default-highlighting](_fastpages_docs/highlight_original.png) - - If you wish to revert to the light theme above, you can remove the below line in [_sass/minima/custom-styles.scss](_sass/minima/custom-styles.scss) - - ```scss - @import "minima/fastpages-dracula-highlight"; - ``` -- If you don't like either of these themes, you can add your own CSS in [`_sass/minima/custom-styles.scss`](_sass/minima/custom-styles.scss). See [customizing fastpages](#customizing-fastpages) for more details. - -## Dark Mode - -[This blog post](https://prudhvirampey.com/blog/colours/jekyll/css/fastpages/2020/10/30/hello-dark-mode.html) describes how to enable Dark Mode for fastpages. - -## Adding Citations via BibTeX - -Users who prefer to use the citation system BibTeX may do so; it requires enabling the [jekyll-scholar](https://github.com/inukshuk/jekyll-scholar) plugin. Please see [Citations in Fastpages via BibTeX and jekyll-scholar](https://drscotthawley.github.io/devblog4/2020/07/01/Citations-Via-Bibtex.html) for instructions on implementing this. - -## Writing Blog Posts With Jupyter - -### Hide Input/Output Cells - -Place the comment `#hide` at the beginning of a code cell and it wil **hide both the input and the output** of that cell. - -A `#hide_input` comment at the top of any cell will **only hide the input**. - -Furthermore, the `hide input` [Jupyter Extension](https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/hide_input/readme.html) can be used to hide cell inputs or outputs, which will be respected by fastpages. - -### Collapsable Code Cells - -You may want some code to be hidden in a collapsed element that the user can expand, rather than completely hiding the code from the reader. - -- To include code in a collapsable cell that **is collapsed by default**, place the comment `#collapse` at the top of the code cell. -- To include code in a collapsable cell that **is open by default**, place the comment `#collapse_show` or `#collapse-show` at the top of the code cell. -- To include the output under a collapsable element that is closed by default, place the comment `#collapse_output` or `#collapse-output` at the top of the code cell. - -### Embedded Twitter and YouTube Content -In a markdown cell in your notebook, use the following markdown shortcuts to embed Twitter cards and YouTube Videos. - - - ```markdown - > youtube: https://youtu.be/your-link - > twitter: https://twitter.com/some-link - ``` -### Adding Footnotes - -Adding footnotes in notebooks is a bit different than markdown. Please see the [Detailed Guide To Footnotes in Notebooks](https://github.com/fastai/fastpages/blob/master/_fastpages_docs/NOTEBOOK_FOOTNOTES.md). - -### Automatically Convert Notebooks To Blog Posts - -1. Save your notebook with the naming convention `YYYY-MM-DD-*.` into the `/_notebooks` or `/_word` folder of this repo, respectively. For example `2020-01-28-My-First-Post.ipynb`. This [naming convention is required by Jekyll](https://jekyllrb.com/docs/posts/) to render your blog post. - - Be careful to name your file correctly! It is easy to forget the last dash in `YYYY-MM-DD-`. Furthermore, the character immediately following the dash should only be an alphabetical letter. Examples of valid filenames are: - - ```shell - 2020-01-28-My-First-Post.ipynb - 2012-09-12-how-to-write-a-blog.ipynb - ``` - - - If you fail to name your file correctly, `fastpages` will automatically attempt to fix the problem by prepending the last modified date of your file to your generated blog post, however, it is recommended that you name your files properly yourself for more transparency. - - -2. [Commit and push](https://help.github.com/en/github/managing-files-in-a-repository/adding-a-file-to-a-repository-using-the-command-line) your file(s) to GitHub in your repository's master branch. - -3. GitHub will automatically convert your files to blog posts. **It will take ~5 minutes for the conversion process to take place**. You can click on the Actions tab of your repo to view the logs of this process. There will be two workflows that are triggered with each push you make to your master branch: (1) "CI" and (2) "GH Pages Status". Both workflows must complete with a green checkmark for your latest commit before your site is updated. - -4. If you wish, you can preview how your blog will look locally before commiting to GitHub. See [this section](#running-the-blog-on-your-local-machine) for a detailed guide on running the preview locally. - - -## Writing Blog Posts With Markdown - -If you are writing your blog post in markdown, save your `.md` file into the `/_posts` folder with the same naming convention (`YYYY-MM-DD-*.md`) specified for notebooks. - -## Writing Blog Posts With Microsoft Word - -Save your Microsoft Word documents into the `/_word` folder with the same naming convention (`YYYY-MM-DD-*.docx`) specified for notebooks. - -_Note:_ [alt text](https://support.office.com/en-us/article/add-alternative-text-to-a-shape-picture-chart-smartart-graphic-or-other-object-44989b2a-903c-4d9a-b742-6a75b451c669) in Word documents are not yet supported by fastpages, and will break links to images. - -### Specifying front-matter for Word documents - -`fastpages` does not have a robust way to specify [front matter](https://jekyllrb.com/docs/front-matter/) for Word documents. At the moment, you can only specify front matter globally for all Word documents by editing [_action_files/word_front_matter.txt](_action_files/word_front_matter.txt). - -To specify unique front matter per Word document, you will need to convert Word to markdown files manually. You can follow the steps in this [blog post](https://www.fast.ai/2020/01/18/gitblog/), which walk you through how to use [pandoc](https://pandoc.org/installing.html) to do the conversion. Note: If you wish to customize your Word generated blog post in markdown, make sure you delete your Word document from the _word directory so your markdown file doesn’t get overwritten! - -_If your primary method of writing blog posts is Word documents, and you plan on always manually editing markdown files converted from Word, you are probably better off using [fast_template](https://github.com/fastai/fast_template) instead of fastpages._ - -# Running the blog on your local machine - -See the [development guide](_fastpages_docs/DEVELOPMENT.md). - - -# Using The GitHub Action & Your Own Custom Blog - -The `fastpages` action allows you to convert notebooks from `/_notebooks` and word documents from `/_word` directories in your repo into [Jekyll](https://jekyllrb.com/) compliant blog post markdown files located in `/_posts`. **Note: This directory structure is currently inflexible** for this Action, as it is designed to be used with Jekyll. - -If you already have sufficient familiarity with [Jekyll](https://jekyllrb.com/) and wish to use this automation in your own theme, you can use this GitHub Action by referencing `fastai/fastpages@master` as follows: - -```yaml -... - -uses: fastai/fastpages@master - -... -``` -An illustrative example of what a complete workflow may look like: - - - -```yaml -jobs: - build-site: - runs-on: ubuntu-latest - ... - - - name: convert notebooks and word docs to posts - uses: fastai/fastpages@master - - ... - - - name: Jekyll build - uses: docker://jekyll/jekyll - with: - args: jekyll build - - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - if: github.event_name == 'push' - with: - deploy_key: ${{ secrets.SSH_DEPLOY_KEY }} - publish_branch: gh-pages - publish_dir: ./_site -``` - -Note that this Action **does not have any required inputs, and has no output variables**. - -### Optional Inputs - - - `BOOL_SAVE_MARKDOWN`: Either 'true' or 'false'. Whether or not to commit converted markdown files from notebooks and word documents into the _posts directory in your repo. This is useful for debugging. _default: false_ - - `SSH_DEPLOY_KEY`: a ssh deploy key is required if BOOL_SAVE_MARKDOWN = 'true' - -See the API spec for this action in [action.yml](action.yml) - -Detailed instructions on how to customize this blog are beyond the scope of this README. ( We invite someone from the community to contribute a blog post on how to do this in this repo! ) - -# Contributing To Fastpages - -Please see the [contributing guide](_fastpages_docs/CONTRIBUTING.md). - -# Upgrading Fastpages - -Please see the [upgrading guide](_fastpages_docs/UPGRADE.md). - -# FAQ - -- **Q:** Where are the markdown files in `_posts/` that are generated from my Jupyter notebooks or word documents? **A:** The GitHub Actions workflow in this repo converts your notebook and word documents to markdown on the fly before building your site, but never commits these intermediate markdown files to this repo. This is in order to save you from the annoyance of your local environment being constantly out of sync with your repository. You can optionally see these intermediate markdown files by setting the `BOOL_SAVE_MARKDOWN` and `SSH_DEPLOY_KEY` inputs to the fastpages action in your `.github/workflows/ci.yaml` file as follows: - -```yaml - ... - - - name: convert notebooks and word docs to posts - uses: fastai/fastpages@master - with: - BOOL_SAVE_MARKDOWN: true - SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }} - - ... -``` - -- **Q:** Can I use `fastpages` for Jekyll docs sites or for things that are not Jekyll blog posts? **A:** At the moment, `fastpages` is a highly opinionated solution that works only for Jekyll blog posts. If you want to write documentation for your module or library with Jupyter notebooks, we suggest you use [fastai/nbdev](https://github.com/fastai/nbdev) which is expressly built for this purpose. - -- **Q:** What is the difference between [fast_template](https://github.com/fastai/fast_template) and fastpages? Which one should I use? **A:** Because `fastpages` is more flexible and extensible, we recommend using it where possible. `fast_template` may be a better option for getting folks blogging who have no technical expertise at all, and will only be creating posts using Github's integrated online editor. - -# Customizing Fastpages - -fastpages builds upon the [minima theme](https://github.com/jekyll/minima). If you want to customize the styling or layout of fastpages, you can find instructions [in minima's README](https://github.com/jekyll/minima/blob/master/README.md). It is a good idea to read the full contents of the README to understand the directory structure. Furthermore, it is a good idea to have a basic understanding of Jekyll before customizing your theme. For those new to Jekyll, [the official docs](https://jekyllrb.com/docs/) are a good place to start. Concretely, you can override css in fastpages in `_sass/minima/custom-styles.scss`. *NOTE that minima's "skins" feature is currently incompatible with fastpages' css settings.* - -**If you choose to make customizations to fastpages** It is possible that customizations you make could collide with current or future versions of fastpages and we recommend doing so only if you feel sufficiently comfortable with HTML and CSS. - -# Troubleshooting fastpages - -Please see the [troubleshooting guide](https://github.com/fastai/fastpages/blob/master/_fastpages_docs/TROUBLESHOOTING.md). +Please use the [nbdev & blogging channel](https://forums.fast.ai/c/fastai-users/nbdev/48) in the fastai forums for any questions or feature requests. diff --git a/_action_files/settings.ini b/_action_files/settings.ini index 415570d..a4c105e 100644 --- a/_action_files/settings.ini +++ b/_action_files/settings.ini @@ -7,7 +7,7 @@ description = Writing a library entirely in notebooks keywords = jupyter notebook author = Sylvain Gugger and Jeremy Howard author_email = info@fast.ai -baseurl = +baseurl = /fastpages title = nbdev copyright = fast.ai license = apache2 @@ -41,3 +41,4 @@ custom_sidebar = False cell_spacing = 1 monospace_docstrings = False jekyll_styles = note,warning,tip,important,youtube,twitter + diff --git a/_config.yml b/_config.yml index dfb5bf9..0e3b588 100644 --- a/_config.yml +++ b/_config.yml @@ -8,13 +8,13 @@ title: fastpages description: An easy to use blogging platform with support for Jupyter Notebooks. -github_username: fastai +github_username: shreya-ahujaa # you can comment the below line out if your repo name is not different than your baseurl github_repo: "fastpages" # OPTIONAL: override baseurl and url if using a custom domain # Note: leave out the trailing / from this value. -url: "https://fastpages.fast.ai" # the base hostname & protocol for your site, e.g. http://example.com +url: "https://shreya-ahujaa.github.io" # the base hostname & protocol for your site, e.g. http://example.com ########################################################### ######### Special Instructions for baseurl ############### @@ -34,7 +34,7 @@ url: "https://fastpages.fast.ai" # the base hostname & protocol for your site, e # # 3. You must replace the parameter `baseurl` in _action_files/settings.ini with the same value as you set here but WITHOUT QUOTES. # -baseurl: "" # the subpath of your site, e.g. "/blog". +baseurl: "/fastpages" # the subpath of your site, e.g. "/blog". # Github and twitter are optional: minima: @@ -58,7 +58,7 @@ annotations: false show_tags: true # Add your Google Analytics ID here if you have one and want to use it -google_analytics: UA-57531313-5 +google_analytics: exclude: - docker-compose.yml diff --git a/_fastpages_docs/_setup_pr_template.md b/_fastpages_docs/_setup_pr_template.md index 7cffc74..8160a5f 100644 --- a/_fastpages_docs/_setup_pr_template.md +++ b/_fastpages_docs/_setup_pr_template.md @@ -1,25 +1,25 @@ -Hello :wave: @{_username_}! Thank you for using fastpages! +Hello :wave: @shreya-ahujaa! Thank you for using fastpages! ## Before you merge this PR 1. Create an ssh key-pair. Open this utility. Select: `RSA` and `4096` and leave `Passphrase` blank. Click the blue button `Generate-SSH-Keys`. -2. Navigate to this link and click `New repository secret`. Copy and paste the **Private Key** into the `Value` field. This includes the "---BEGIN RSA PRIVATE KEY---" and "--END RSA PRIVATE KEY---" portions. **In the `Name` field, name the secret `SSH_DEPLOY_KEY`.** +2. Navigate to this link and click `New repository secret`. Copy and paste the **Private Key** into the `Value` field. This includes the "---BEGIN RSA PRIVATE KEY---" and "--END RSA PRIVATE KEY---" portions. **In the `Name` field, name the secret `SSH_DEPLOY_KEY`.** -3. Navigate to this link and click the `Add deploy key` button. Paste your **Public Key** from step 1 into the `Key` box. In the `Title`, name the key anything you want, for example `fastpages-key`. Finally, **make sure you click the checkbox next to `Allow write access`** (pictured below), and click `Add key` to save the key. +3. Navigate to this link and click the `Add deploy key` button. Paste your **Public Key** from step 1 into the `Key` box. In the `Title`, name the key anything you want, for example `fastpages-key`. Finally, **make sure you click the checkbox next to `Allow write access`** (pictured below), and click `Add key` to save the key. ![](https://raw.githubusercontent.com/fastai/fastpages/master/_fastpages_docs/_checkbox.png) ### What to Expect After Merging This PR -- GitHub Actions will build your site, which will take 2-3 minutes to complete. **This will happen anytime you push changes to the master branch of your repository.** You can monitor the logs of this if you like on the [Actions tab of your repo](https://github.com/{_username_}/{_repo_name_}/actions). +- GitHub Actions will build your site, which will take 2-3 minutes to complete. **This will happen anytime you push changes to the master branch of your repository.** You can monitor the logs of this if you like on the [Actions tab of your repo](https://github.com/shreya-ahujaa/fastpages/actions). - Your GH-Pages Status badge on your README will eventually appear and be green, indicating your first successful build. -- You can monitor the status of your site in the GitHub Pages section of your [repository settings](https://github.com/{_username_}/{_repo_name_}/settings). +- You can monitor the status of your site in the GitHub Pages section of your [repository settings](https://github.com/shreya-ahujaa/fastpages/settings). If you are not using a custom domain, your website will appear at: -#### https://{_username_}.github.io/{_repo_name_} +#### https://shreya-ahujaa.github.io/fastpages ## Optional: Using a Custom Domain diff --git a/_notebooks/2020-02-21-introducing-fastpages.ipynb b/_notebooks/2020-02-21-introducing-fastpages.ipynb deleted file mode 100644 index 71823b1..0000000 --- a/_notebooks/2020-02-21-introducing-fastpages.ipynb +++ /dev/null @@ -1,573 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Introducing fastpages\n", - "> An easy to use blogging platform with extra features for Jupyter Notebooks.\n", - "\n", - "- toc: true \n", - "- badges: true\n", - "- comments: true\n", - "- sticky_rank: 1\n", - "- author: Jeremy Howard & Hamel Husain\n", - "- image: images/diagram.png\n", - "- categories: [fastpages, jupyter]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![](https://github.com/fastai/fastpages/raw/master/images/diagram.png \"https://github.com/fastai/fastpages\")\n", - "\n", - "We are very pleased to announce the immediate availability of [fastpages](https://github.com/fastai/fastpages). `fastpages` is a platform which allows you to create and host a blog for free, with no ads and many useful features, such as:\n", - "\n", - "- Create posts containing code, outputs of code (which can be interactive), formatted text, etc directly from [Jupyter Notebooks](https://jupyter.org/); for instance see this great [example post](https://drscotthawley.github.io/devblog3/2019/02/08/My-1st-NN-Part-3-Multi-Layer-and-Backprop.html) from Scott Hawley. Notebook posts support features such as:\n", - " - Interactive visualizations made with [Altair](https://altair-viz.github.io/) remain interactive.\n", - " - Hide or show cell input and output.\n", - " - Collapsable code cells that are either open or closed by default.\n", - " - Define the Title, Summary and other metadata via a special markdown cells\n", - " - Ability to add links to [Colab](https://colab.research.google.com/) and GitHub automatically.\n", - "- Create posts, including formatting and images, directly from Microsoft Word documents.\n", - "- Create and edit [Markdown](https://guides.github.com/features/mastering-markdown/) posts entirely online using GitHub's built-in markdown editor.\n", - "- Embed Twitter cards and YouTube videos.\n", - "- Categorization of blog posts by user-supplied tags for discoverability.\n", - "- ... and [much more](https://github.com/fastai/fastpages)\n", - "\n", - "[fastpages](https://github.com/fastai/fastpages) relies on Github pages for hosting, and [Github Actions](https://github.com/features/actions) to automate the creation of your blog. The setup takes around three minutes, and does not require any technical knowledge or expertise. Due to built-in automation of fastpages, you don't have to fuss with conversion scripts. All you have to do is save your Jupyter notebook, Word document or markdown file into a specified directory and the rest happens automatically. Infact, this blog post is written in a Jupyter notebook, which you can see with the \"View on GitHub\" link above.\n", - "\n", - "[fast.ai](https://www.fast.ai/) have previously released a similar project called [fast_template](https://www.fast.ai/2020/01/16/fast_template/), which is even easier to set up, but does not support automatic creation of posts from Microsoft Word or Jupyter notebooks, including many of the features outlined above.\n", - "\n", - "**Because `fastpages` is more flexible and extensible, we recommend using it where possible.** `fast_template` may be a better option for getting folks blogging who have no technical expertise at all, and will only be creating posts using Github's integrated online editor." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Setting Up Fastpages\n", - "\n", - "[The setup process](https://github.com/fastai/fastpages#setup-instructions) of fastpages is automated with GitHub Actions, too! Upon creating a repo from the fastpages template, a pull request will automatically be opened (after ~ 30 seconds) configuring your blog so it can start working. The automated pull request will greet you with instructions like this:\n", - "\n", - "![Imgur](https://i.imgur.com/JhkIip8.png)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "All you have to do is follow these instructions (in the PR you receive) and your new blogging site will be up and running!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Jupyter Notebooks & Fastpages\n", - "\n", - "In this post, we will cover special features that fastpages provides for Jupyter notebooks. You can also write your blog posts with Word documents or markdown in fastpages, which contain many, but not all the same features. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Options via FrontMatter\n", - "\n", - "The first cell in your Jupyter Notebook or markdown blog post contains front matter. Front matter is metadata that can turn on/off options in your Notebook. It is formatted like this:\n", - "\n", - "```\n", - "# Title\n", - "> Awesome summary\n", - "\n", - "- toc: true\n", - "- branch: master\n", - "- badges: true\n", - "- comments: true\n", - "- author: Hamel Husain & Jeremy Howard\n", - "- categories: [fastpages, jupyter]\n", - "```\n", - "\n", - "**All of the above settings are enabled in this post, so you can see what they look like!**\n", - "\n", - "- the summary field (preceeded by `>`) will be displayed under your title, and will also be used by social media to display as the description of your page.\n", - "- `toc`: setting this to `true` will automatically generate a table of contents\n", - "- `badges`: setting this to `true` will display Google Colab and GitHub links on your blog post.\n", - "- `comments`: setting this to `true` will enable comments. See [these instructions](https://github.com/fastai/fastpages#enabling-comments) for more details.\n", - "- `author` this will display the authors names. \n", - "- `categories` will allow your post to be categorized on a \"Tags\" page, where readers can browse your post by categories.\n", - "\n", - "\n", - "_Markdown front matter is formatted similarly to notebooks. The differences between the two can be [viewed on the fastpages README](https://github.com/fastai/fastpages#front-matter-related-options)._" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Code Folding" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "put a `#collapse-hide` flag at the top of any cell if you want to **hide** that cell by default, but give the reader the option to show it:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#hide\n", - "!pip install pandas altair" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [], - "source": [ - "#collapse-hide\n", - "import pandas as pd\n", - "import altair as alt" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "put a `#collapse-show` flag at the top of any cell if you want to **show** that cell by default, but give the reader the option to hide it:" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "#collapse-show\n", - "cars = 'https://vega.github.io/vega-datasets/data/cars.json'\n", - "movies = 'https://vega.github.io/vega-datasets/data/movies.json'\n", - "sp500 = 'https://vega.github.io/vega-datasets/data/sp500.csv'\n", - "stocks = 'https://vega.github.io/vega-datasets/data/stocks.csv'\n", - "flights = 'https://vega.github.io/vega-datasets/data/flights-5k.json'" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If you want to completely hide cells (not just collapse them), [read these instructions](https://github.com/fastai/fastpages#hide-inputoutput-cells)." - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "# hide\n", - "df = pd.read_json(movies) # load movies data\n", - "df.columns = [x.replace(' ', '_') for x in df.columns.values]\n", - "genres = df['Major_Genre'].unique() # get unique field values\n", - "genres = list(filter(lambda d: d is not None, genres)) # filter out None values\n", - "genres.sort() # sort alphabetically" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Interactive Charts With Altair\n", - "\n", - "Interactive visualizations made with [Altair](https://altair-viz.github.io/) remain interactive! \n", - "\n", - "We leave this below cell unhidden so you can enjoy a preview of syntax highlighting in fastpages, which uses the [Dracula theme](https://draculatheme.com/)." - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - "
\n", - "" - ], - "text/plain": [ - "alt.LayerChart(...)" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# select a point for which to provide details-on-demand\n", - "label = alt.selection_single(\n", - " encodings=['x'], # limit selection to x-axis value\n", - " on='mouseover', # select on mouseover events\n", - " nearest=True, # select data point nearest the cursor\n", - " empty='none' # empty selection includes no data points\n", - ")\n", - "\n", - "# define our base line chart of stock prices\n", - "base = alt.Chart().mark_line().encode(\n", - " alt.X('date:T'),\n", - " alt.Y('price:Q', scale=alt.Scale(type='log')),\n", - " alt.Color('symbol:N')\n", - ")\n", - "\n", - "alt.layer(\n", - " base, # base line chart\n", - " \n", - " # add a rule mark to serve as a guide line\n", - " alt.Chart().mark_rule(color='#aaa').encode(\n", - " x='date:T'\n", - " ).transform_filter(label),\n", - " \n", - " # add circle marks for selected time points, hide unselected points\n", - " base.mark_circle().encode(\n", - " opacity=alt.condition(label, alt.value(1), alt.value(0))\n", - " ).add_selection(label),\n", - "\n", - " # add white stroked text to provide a legible background for labels\n", - " base.mark_text(align='left', dx=5, dy=-5, stroke='white', strokeWidth=2).encode(\n", - " text='price:Q'\n", - " ).transform_filter(label),\n", - "\n", - " # add text labels for stock prices\n", - " base.mark_text(align='left', dx=5, dy=-5).encode(\n", - " text='price:Q'\n", - " ).transform_filter(label),\n", - " \n", - " data=stocks\n", - ").properties(\n", - " width=500,\n", - " height=400\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Data Tables\n", - "\n", - "You can display tables per the usual way in your blog:" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
TitleWorldwide_GrossProduction_BudgetIMDB_Rating
0The Land Girls146083.08000000.06.1
1First Love, Last Rites10876.0300000.06.9
2I Married a Strange Person203134.0250000.06.8
3Let's Talk About Sex373615.0300000.0NaN
4Slam1087521.01000000.03.4
\n", - "
" - ], - "text/plain": [ - " Title Worldwide_Gross Production_Budget IMDB_Rating\n", - "0 The Land Girls 146083.0 8000000.0 6.1\n", - "1 First Love, Last Rites 10876.0 300000.0 6.9\n", - "2 I Married a Strange Person 203134.0 250000.0 6.8\n", - "3 Let's Talk About Sex 373615.0 300000.0 NaN\n", - "4 Slam 1087521.0 1000000.0 3.4" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# display table with pandas\n", - "df[['Title', 'Worldwide_Gross', \n", - " 'Production_Budget', 'IMDB_Rating']].head()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Other Features" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### GitHub Flavored Emojis\n", - "\n", - "Typing `I give this post two :+1:!` will render this:\n", - "\n", - "I give this post two :+1:!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Images w/Captions\n", - "\n", - "You can include markdown images with captions like this:\n", - "\n", - "```\n", - "![](https://www.fast.ai/images/fastai_paper/show_batch.png \"Credit: https://www.fast.ai/2020/02/13/fastai-A-Layered-API-for-Deep-Learning/\")\n", - "```\n", - "\n", - "\n", - "![](https://www.fast.ai/images/fastai_paper/show_batch.png \"Credit: https://www.fast.ai/2020/02/13/fastai-A-Layered-API-for-Deep-Learning/\")\n", - "\n", - "Of course, the caption is optional." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Tweetcards\n", - "\n", - "Typing `> twitter: https://twitter.com/jakevdp/status/1204765621767901185?s=20` will render this:\n", - "\n", - "> twitter: https://twitter.com/jakevdp/status/1204765621767901185?s=20" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Youtube Videos\n", - "\n", - "Typing `> youtube: https://youtu.be/XfoYk_Z5AkI` will render this:\n", - "\n", - "\n", - "> youtube: https://youtu.be/XfoYk_Z5AkI" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Boxes / Callouts \n", - "\n", - "Typing `> Warning: There will be no second warning!` will render this:\n", - "\n", - "\n", - "> Warning: There will be no second warning!\n", - "\n", - "\n", - "\n", - "Typing `> Important: Pay attention! It's important.` will render this:\n", - "\n", - "> Important: Pay attention! It's important.\n", - "\n", - "\n", - "\n", - "Typing `> Tip: This is my tip.` will render this:\n", - "\n", - "> Tip: This is my tip.\n", - "\n", - "\n", - "\n", - "Typing `> Note: Take note of this.` will render this:\n", - "\n", - "> Note: Take note of this.\n", - "\n", - "\n", - "\n", - "Typing `> Note: A doc link to [an example website: fast.ai](https://www.fast.ai/) should also work fine.` will render in the docs:\n", - "\n", - "> Note: A doc link to [an example website: fast.ai](https://www.fast.ai/) should also work fine." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## More Examples\n", - "\n", - "This [tutorial](https://fastpages.fast.ai/jupyter/2020/02/20/test.html) contains more examples of what you can do with notebooks. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## How fastpages Converts Notebooks to Blog Posts" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "fastpages uses [nbdev](https://nbdev.fast.ai/index.html) to power the conversion process of Jupyter Notebooks to blog posts. When you save a notebook into the `/_notebooks` folder of your repository, GitHub Actions applies `nbdev` against those notebooks automatically. The same process occurs when you save Word documents or markdown files into the `_word` or `_posts` directory, respectively.\n", - "\n", - "We will discuss how GitHub Actions work in a follow up blog post." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Resources & Next Steps" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We highly encourage you to start blogging with `fastpages`! Some resources that may be helpful:\n", - "\n", - "- [fastpages repo](https://github.com/fastai/fastpages) - this is where you can go to create your own fastpages blog!\n", - "- Fastai forums - [nbdev & blogging category](https://forums.fast.ai/c/fastai-users/nbdev/). You can ask questions about fastpages here, as well as suggest new features.\n", - "- [nbdev](https://github.com/fastai/nbdev): this project powers the conversion of Jupyter notebooks to blog posts.\n", - "\n", - "If you end up writing a blog post using fastpages, please let us know on Twitter: [@jeremyphoward](https://twitter.com/jeremyphoward), [@HamelHusain](https://twitter.com/hamelhusain)." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.3" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/_notebooks/2020-09-01-fastcore.ipynb b/_notebooks/2020-09-01-fastcore.ipynb deleted file mode 100755 index 06d246b..0000000 --- a/_notebooks/2020-09-01-fastcore.ipynb +++ /dev/null @@ -1,1366 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# \"fastcore: An Underrated Python Library\"\n", - "\n", - "> A unique python library that extends the python programming language and provides utilities that enhance productivity.\n", - "- author: \"Hamel Husain\"\n", - "- toc: false\n", - "- image: images/copied_from_nb/fastcore_imgs/td.png\n", - "- comments: true\n", - "- categories: [fastcore, fastai]\n", - "- permalink: /fastcore/\n", - "- badges: true" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![screenshot with code](fastcore_imgs/td.png)\n", - "\n", - "# Background\n", - "\n", - "I recently embarked on a journey to sharpen my python skills: I wanted to learn advanced patterns, idioms, and techniques. I started with reading books on advanced Python, however, the information didn't seem to stick without having somewhere to apply it. I also wanted the ability to ask questions from an expert while I was learning -- which is an arrangement that is hard to find! That's when it occurred to me: What if I could find an open source project that has fairly advanced python code and write documentation and tests? I made a bet that if I did this it would force me to learn everything very deeply, and the maintainers would be appreciative of my work and be willing to answer my questions. \n", - "\n", - "And that's exactly what I did over the past month! I'm pleased to report that it has been the most efficient learning experience I've ever experienced. I've discovered that writing documentation forced me to deeply understand not just what the code does but also _why the code works the way it does_, and to explore edge cases while writing tests. Most importantly, I was able to ask questions when I was stuck, and maintainers were willing to devote extra time knowing that their mentorship was in service of making their code more accessible! It turns out the library I choose, [fastcore](https://fastcore.fast.ai/) is some of the most fascinating Python I have ever encountered as its purpose and goals are fairly unique.\n", - "\n", - "For the uninitiated, [fastcore](https://fastcore.fast.ai/) is a library on top of which many [fast.ai](https://github.com/fastai) projects are built on. Most importantly, [fastcore](https://fastcore.fast.ai/) extends the python programming language and strives to eliminate boilerplate and add useful functionality for common tasks. In this blog post, I'm going to highlight some of my favorite tools that fastcore provides, rather than sharing what I learned about python. My goal is to pique your interest in this library, and hopefully motivate you to check out the documentation after you are done to learn more!\n", - "\n", - "# Why fastcore is interesting\n", - "\n", - "1. **Get exposed to ideas from other languages without leaving python:** I’ve always heard that it is beneficial to learn other languages in order to become a better programmer. From a pragmatic point of view, I’ve found it difficult to learn other languages because I could never use them at work. Fastcore extends python to include patterns found in languages as diverse as Julia, Ruby and Haskell. Now that I understand these tools I am motivated to learn other languages.\n", - "2. **You get a new set of pragmatic tools**: fastcore includes utilities that will allow you to write more concise expressive code, and perhaps solve new problems.\n", - "3. **Learn more about the Python programming language:** Because fastcore extends the python programming language, many advanced concepts are exposed during the process. For the motivated, this is a great way to see how many of the internals of python work. \n", - " \n", - "\n", - "# A whirlwind tour through fastcore\n", - "\n", - "Here are some things you can do with fastcore that immediately caught my attention." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Collecting git+git://github.com/fastai/fastcore@master\n", - " Cloning git://github.com/fastai/fastcore (to revision master) to /private/var/folders/88/9mddczp92wg04x0ykmw940q00000gn/T/pip-req-build-fph52w2h\n", - " Running command git clone -q git://github.com/fastai/fastcore /private/var/folders/88/9mddczp92wg04x0ykmw940q00000gn/T/pip-req-build-fph52w2h\n", - "Requirement already satisfied, skipping upgrade: pip in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from fastcore==1.0.12) (20.1.1)\n", - "Requirement already satisfied, skipping upgrade: packaging in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from fastcore==1.0.12) (20.4)\n", - "Requirement already satisfied, skipping upgrade: six in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from packaging->fastcore==1.0.12) (1.15.0)\n", - "Requirement already satisfied, skipping upgrade: pyparsing>=2.0.2 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from packaging->fastcore==1.0.12) (2.4.7)\n", - "Building wheels for collected packages: fastcore\n", - " Building wheel for fastcore (setup.py) ... \u001b[?25ldone\n", - "\u001b[?25h Created wheel for fastcore: filename=fastcore-1.0.12-py3-none-any.whl size=40633 sha256=8275b4eaa351c9c867e9c1f83105bc6ec25f251caf1efcf247a8e9ecc0f16f76\n", - " Stored in directory: /private/var/folders/88/9mddczp92wg04x0ykmw940q00000gn/T/pip-ephem-wheel-cache-x8fbj38b/wheels/9b/c8/80/1e03649fe9e96f2b8231a1f38d4e20389036c7cb204afd8563\n", - "Successfully built fastcore\n", - "Installing collected packages: fastcore\n", - " Attempting uninstall: fastcore\n", - " Found existing installation: fastcore 1.0.12\n", - " Uninstalling fastcore-1.0.12:\n", - " Successfully uninstalled fastcore-1.0.12\n", - "Successfully installed fastcore-1.0.12\n", - "Collecting git+git://github.com/fastai/nbdev@master\n", - " Cloning git://github.com/fastai/nbdev (to revision master) to /private/var/folders/88/9mddczp92wg04x0ykmw940q00000gn/T/pip-req-build-whf785xv\n", - " Running command git clone -q git://github.com/fastai/nbdev /private/var/folders/88/9mddczp92wg04x0ykmw940q00000gn/T/pip-req-build-whf785xv\n", - "Requirement already satisfied, skipping upgrade: pip in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbdev==1.0.19) (20.1.1)\n", - "Requirement already satisfied, skipping upgrade: packaging in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbdev==1.0.19) (20.4)\n", - "Requirement already satisfied, skipping upgrade: fastcore>=1.0.10 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbdev==1.0.19) (1.0.12)\n", - "Requirement already satisfied, skipping upgrade: nbformat>=4.4.0 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbdev==1.0.19) (5.0.7)\n", - "Requirement already satisfied, skipping upgrade: nbconvert<6 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbdev==1.0.19) (5.6.1)\n", - "Requirement already satisfied, skipping upgrade: pyyaml in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbdev==1.0.19) (5.3.1)\n", - "Requirement already satisfied, skipping upgrade: jupyter_client in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbdev==1.0.19) (6.1.6)\n", - "Requirement already satisfied, skipping upgrade: ipykernel in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbdev==1.0.19) (5.3.2)\n", - "Requirement already satisfied, skipping upgrade: six in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from packaging->nbdev==1.0.19) (1.15.0)\n", - "Requirement already satisfied, skipping upgrade: pyparsing>=2.0.2 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from packaging->nbdev==1.0.19) (2.4.7)\n", - "Requirement already satisfied, skipping upgrade: ipython-genutils in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbformat>=4.4.0->nbdev==1.0.19) (0.2.0)\n", - "Requirement already satisfied, skipping upgrade: jsonschema!=2.5.0,>=2.4 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbformat>=4.4.0->nbdev==1.0.19) (3.0.2)\n", - "Requirement already satisfied, skipping upgrade: traitlets>=4.1 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbformat>=4.4.0->nbdev==1.0.19) (4.3.3)\n", - "Requirement already satisfied, skipping upgrade: jupyter-core in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbformat>=4.4.0->nbdev==1.0.19) (4.6.3)\n", - "Requirement already satisfied, skipping upgrade: pandocfilters>=1.4.1 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbconvert<6->nbdev==1.0.19) (1.4.2)\n", - "Requirement already satisfied, skipping upgrade: entrypoints>=0.2.2 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbconvert<6->nbdev==1.0.19) (0.3)\n", - "Requirement already satisfied, skipping upgrade: bleach in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbconvert<6->nbdev==1.0.19) (3.1.5)\n", - "Requirement already satisfied, skipping upgrade: testpath in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbconvert<6->nbdev==1.0.19) (0.4.4)\n", - "Requirement already satisfied, skipping upgrade: defusedxml in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbconvert<6->nbdev==1.0.19) (0.6.0)\n", - "Requirement already satisfied, skipping upgrade: jinja2>=2.4 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbconvert<6->nbdev==1.0.19) (2.11.2)\n", - "Requirement already satisfied, skipping upgrade: mistune<2,>=0.8.1 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbconvert<6->nbdev==1.0.19) (0.8.4)\n", - "Requirement already satisfied, skipping upgrade: pygments in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from nbconvert<6->nbdev==1.0.19) (2.6.1)\n", - "Requirement already satisfied, skipping upgrade: tornado>=4.1 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from jupyter_client->nbdev==1.0.19) (6.0.4)\n", - "Requirement already satisfied, skipping upgrade: python-dateutil>=2.1 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from jupyter_client->nbdev==1.0.19) (2.8.1)\n", - "Requirement already satisfied, skipping upgrade: pyzmq>=13 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from jupyter_client->nbdev==1.0.19) (19.0.1)\n", - "Requirement already satisfied, skipping upgrade: appnope; platform_system == \"Darwin\" in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from ipykernel->nbdev==1.0.19) (0.1.0)\n", - "Requirement already satisfied, skipping upgrade: ipython>=5.0.0 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from ipykernel->nbdev==1.0.19) (7.16.1)\n", - "Requirement already satisfied, skipping upgrade: setuptools in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.4.0->nbdev==1.0.19) (49.2.0.post20200714)\n", - "Requirement already satisfied, skipping upgrade: attrs>=17.4.0 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.4.0->nbdev==1.0.19) (19.3.0)\n", - "Requirement already satisfied, skipping upgrade: pyrsistent>=0.14.0 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.4.0->nbdev==1.0.19) (0.16.0)\n", - "Requirement already satisfied, skipping upgrade: decorator in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from traitlets>=4.1->nbformat>=4.4.0->nbdev==1.0.19) (4.4.2)\n", - "Requirement already satisfied, skipping upgrade: webencodings in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from bleach->nbconvert<6->nbdev==1.0.19) (0.5.1)\n", - "Requirement already satisfied, skipping upgrade: MarkupSafe>=0.23 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from jinja2>=2.4->nbconvert<6->nbdev==1.0.19) (1.1.1)\n", - "Requirement already satisfied, skipping upgrade: backcall in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from ipython>=5.0.0->ipykernel->nbdev==1.0.19) (0.2.0)\n", - "Requirement already satisfied, skipping upgrade: jedi>=0.10 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from ipython>=5.0.0->ipykernel->nbdev==1.0.19) (0.17.1)\n", - "Requirement already satisfied, skipping upgrade: pickleshare in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from ipython>=5.0.0->ipykernel->nbdev==1.0.19) (0.7.5)\n", - "Requirement already satisfied, skipping upgrade: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from ipython>=5.0.0->ipykernel->nbdev==1.0.19) (3.0.5)\n", - "Requirement already satisfied, skipping upgrade: pexpect; sys_platform != \"win32\" in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from ipython>=5.0.0->ipykernel->nbdev==1.0.19) (4.8.0)\n", - "Requirement already satisfied, skipping upgrade: parso<0.8.0,>=0.7.0 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from jedi>=0.10->ipython>=5.0.0->ipykernel->nbdev==1.0.19) (0.7.0)\n", - "Requirement already satisfied, skipping upgrade: wcwidth in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->ipython>=5.0.0->ipykernel->nbdev==1.0.19) (0.2.5)\n", - "Requirement already satisfied, skipping upgrade: ptyprocess>=0.5 in /Users/hamelsmu/anaconda3/lib/python3.8/site-packages (from pexpect; sys_platform != \"win32\"->ipython>=5.0.0->ipykernel->nbdev==1.0.19) (0.6.0)\n", - "Building wheels for collected packages: nbdev\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - " Building wheel for nbdev (setup.py) ... \u001b[?25ldone\n", - "\u001b[?25h Created wheel for nbdev: filename=nbdev-1.0.19-py3-none-any.whl size=51832 sha256=69a997325e38de84de9410724f59a24deeab6514bc4bea80bdfc90d12acfcff8\n", - " Stored in directory: /private/var/folders/88/9mddczp92wg04x0ykmw940q00000gn/T/pip-ephem-wheel-cache-r2gv8q50/wheels/28/83/ee/f8ff336622886142e3bc00cfc9ba627f277f30f2ad3d7030f0\n", - "Successfully built nbdev\n", - "Installing collected packages: nbdev\n", - " Attempting uninstall: nbdev\n", - " Found existing installation: nbdev 1.0.19\n", - " Uninstalling nbdev-1.0.19:\n", - " Successfully uninstalled nbdev-1.0.19\n", - "Successfully installed nbdev-1.0.19\n", - "Collecting numpy\n", - " Downloading numpy-1.19.2-cp38-cp38-macosx_10_9_x86_64.whl (15.3 MB)\n", - "\u001b[K |████████████████████████████████| 15.3 MB 4.7 MB/s eta 0:00:01\n", - "\u001b[?25hInstalling collected packages: numpy\n", - " Attempting uninstall: numpy\n", - " Found existing installation: numpy 1.18.5\n", - " Uninstalling numpy-1.18.5:\n", - " Successfully uninstalled numpy-1.18.5\n", - "Successfully installed numpy-1.19.2\n" - ] - } - ], - "source": [ - "#hide\n", - "! pip install -U git+git://github.com/fastai/fastcore@master\n", - "! pip install -U git+git://github.com/fastai/nbdev@master\n", - "! pip install -U numpy\n", - "from fastcore.foundation import *\n", - "from fastcore.meta import *\n", - "from fastcore.utils import *\n", - "from fastcore.test import *\n", - "from nbdev.showdoc import *\n", - "from fastcore.dispatch import typedispatch\n", - "from functools import partial\n", - "import numpy as np\n", - "import inspect" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---\n", - "\n", - "## Making **kwargs transparent\n", - "\n", - "Whenever I see a function that has the argument **kwargs, I cringe a little. This is because it means the API is obfuscated and I have to read the source code to figure out what valid parameters might be. Consider the below example:" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def baz(a, b=2, c=3, d=4): return a + b + c\n", - "\n", - "def foo(c, a, **kwargs):\n", - " return c + baz(a, **kwargs)\n", - "\n", - "inspect.signature(foo)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Without reading the source code, it might be hard for me to know that `foo` also accepts and additional parameters `b` and `d`. We can fix this with [`delegates`](https://fastcore.fast.ai/foundation.html#delegates):" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def baz(a, b=2, c=3, d=4): return a + b + c\n", - "\n", - "@delegates(baz) # this decorator will pass down keyword arguments from baz\n", - "def foo(c, a, **kwargs):\n", - " return c + baz(a, **kwargs)\n", - "\n", - "inspect.signature(foo)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can customize the behavior of this decorator. For example, you can have your cake and eat it too by passing down your arguments and also keeping `**kwargs`:" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "@delegates(baz, keep=True)\n", - "def foo(c, a, **kwargs):\n", - " return c + baz(a, **kwargs)\n", - "\n", - "inspect.signature(foo)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can also exclude arguments. For example, we exclude argument `d` from delegation:" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def basefoo(a, b=2, c=3, d=4): pass\n", - "\n", - "@delegates(basefoo, but=['d']) # exclude `d`\n", - "def foo(c, a, **kwargs): pass\n", - "\n", - "inspect.signature(foo)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can also delegate between classes:" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "class BaseFoo:\n", - " def __init__(self, e, c=2): pass\n", - "\n", - "@delegates()# since no argument was passsed here we delegate to the superclass\n", - "class Foo(BaseFoo):\n", - " def __init__(self, a, b=1, **kwargs): super().__init__(**kwargs)\n", - " \n", - "inspect.signature(Foo)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "For more information, read the [docs on delegates](https://fastcore.fast.ai/foundation.html#delegates).\n", - "\n", - "___" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Avoid boilerplate when setting instance attributes\n", - "\n", - "Have you ever wondered if it was possible to avoid the boilerplate involved with setting attributes in `__init__`?" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "class Test:\n", - " def __init__(self, a, b ,c): \n", - " self.a, self.b, self.c = a, b, c" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Ouch! That was painful. Look at all the repeated variable names. Do I really have to repeat myself like this when defining a class? Not Anymore! Checkout [store_attr](https://fastcore.fast.ai/basics.html#store_attr):" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "class Test:\n", - " def __init__(self, a, b, c): \n", - " store_attr()\n", - " \n", - "t = Test(5,4,3)\n", - "assert t.b == 4" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can also exclude certain attributes:" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], - "source": [ - "class Test:\n", - " def __init__(self, a, b, c): \n", - " store_attr(but=['c'])\n", - " \n", - "t = Test(5,4,3)\n", - "assert t.b == 4\n", - "assert not hasattr(t, 'c')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "There are many more ways of customizing and using `store_attr` than I highlighted here. Check out [the docs](https://fastcore.fast.ai/basics.html#store_attr) for more detail.\n", - "\n", - "P.S. you might be thinking that Python [dataclasses](https://docs.python.org/3/library/dataclasses.html) also allow you to avoid this boilerplate. While true in some cases, `store_attr` is more flexible.{% fn 1 %}\n", - "\n", - "{{ \"For example, store_attr does not rely on inheritance, which means you won't get stuck using multiple inheritance when using this with your own classes. Also, unlike dataclasses, store_attr does not require python 3.7 or higher. Furthermore, you can use store_attr anytime in the object lifecycle, and in any location in your class to customize the behavior of how and when variables are stored.\" | fndetail: 1 }}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Avoiding subclassing boilerplate\n", - "\n", - "One thing I hate about python is the `__super__().__init__()` boilerplate associated with subclassing. For example:" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [], - "source": [ - "class ParentClass:\n", - " def __init__(self): self.some_attr = 'hello'\n", - " \n", - "class ChildClass(ParentClass):\n", - " def __init__(self):\n", - " super().__init__()\n", - "\n", - "cc = ChildClass()\n", - "assert cc.some_attr == 'hello' # only accessible b/c you used super" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can avoid this boilerplate by using the metaclass [PrePostInitMeta](https://fastcore.fast.ai/foundation.html#PrePostInitMeta). We define a new class called `NewParent` that is a wrapper around the `ParentClass`:" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "class NewParent(ParentClass, metaclass=PrePostInitMeta):\n", - " def __pre_init__(self, *args, **kwargs): super().__init__()\n", - "\n", - "class ChildClass(NewParent):\n", - " def __init__(self):pass\n", - " \n", - "sc = ChildClass()\n", - "assert sc.some_attr == 'hello' " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---\n", - "\n", - "## Type Dispatch\n", - "\n", - "Type dispatch, or [Multiple dispatch](https://en.wikipedia.org/wiki/Multiple_dispatch#Julia), allows you to change the way a function behaves based upon the input types it receives. This is a prominent feature in some programming languages like Julia. For example, this is a [conceptual example](https://en.wikipedia.org/wiki/Multiple_dispatch#Julia) of how multiple dispatch works in Julia, returning different values depending on the input types of x and y:\n", - "\n", - "```julia\n", - "collide_with(x::Asteroid, y::Asteroid) = ... \n", - "# deal with asteroid hitting asteroid\n", - "\n", - "collide_with(x::Asteroid, y::Spaceship) = ... \n", - "# deal with asteroid hitting spaceship\n", - "\n", - "collide_with(x::Spaceship, y::Asteroid) = ... \n", - "# deal with spaceship hitting asteroid\n", - "\n", - "collide_with(x::Spaceship, y::Spaceship) = ... \n", - "# deal with spaceship hitting spaceship\n", - "```\n", - "\n", - "Type dispatch can be especially useful in data science, where you might allow different input types (i.e. Numpy arrays and Pandas dataframes) to a function that processes data. Type dispatch allows you to have a common API for functions that do similar tasks.\n", - "\n", - "Unfortunately, Python does not support this out-of-the box. Fortunately, there is the [@typedispatch](https://fastcore.fast.ai/dispatch.html#typedispatch-Decorator) decorator to the rescue. This decorator relies upon type hints in order to route inputs the correct version of the function:" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [], - "source": [ - "@typedispatch\n", - "def f(x:str, y:str): return f'{x}{y}'\n", - "\n", - "@typedispatch\n", - "def f(x:np.ndarray): return x.sum()\n", - "\n", - "@typedispatch\n", - "def f(x:int, y:int): return x+y" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Below is a demonstration of type dispatch at work for the function `f`:" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Hello World!'" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "f('Hello ', 'World!')" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "5" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "f(2,3)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "20" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "f(np.array([5,5,5,5]))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "There are limitations of this feature, as well as other ways of using this functionality that [you can read about here](https://fastcore.fast.ai/dispatch.html). In the process of learning about typed dispatch, I also found a python library called [multipledispatch](https://github.com/mrocklin/multipledispatch) made by [Mathhew Rocklin](https://github.com/mrocklin) (the creator of Dask). \n", - "\n", - "After using this feature, I am now motivated to learn languages like Julia to discover what other paradigms I might be missing.\n", - "\n", - "---" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## A better version of functools.partial\n", - "\n", - "`functools.partial` is a great utility that creates functions from other functions that lets you set default values. Lets take this function for example that filters a list to only contain values >= `val`:" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[3, 4, 5, 6]" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "test_input = [1,2,3,4,5,6]\n", - "def f(arr, val): \n", - " \"Filter a list to remove any values that are less than val.\"\n", - " return [x for x in arr if x >= val]\n", - "\n", - "f(test_input, 3)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can create a new function out of this function using `partial` that sets the default value to 5:" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[5, 6]" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "filter5 = partial(f, val=5)\n", - "filter5(test_input)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "One problem with `partial` is that it removes the original docstring and replaces it with a generic docstring:" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'partial(func, *args, **keywords) - new function with partial application\\n of the given arguments and keywords.\\n'" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "filter5.__doc__" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "[fastcore.utils.partialler](https://fastcore.fast.ai/basics.html#partialler) fixes this, and makes sure the docstring is retained such that the new API is transparent:" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Filter a list to remove any values that are less than val.'" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "filter5 = partialler(f, val=5)\n", - "filter5.__doc__" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---\n", - "\n", - "## Composition of functions\n", - "\n", - "A technique that is pervasive in functional programming languages is function composition, whereby you chain a bunch of functions together to achieve some kind of result. This is especially useful when applying various data transformations. Consider a toy example where I have three functions: (1) Removes elements of a list less than 5 (from the prior section) (2) adds 2 to each number (3) sums all the numbers:" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "15" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def add(arr, val): return [x + val for x in arr]\n", - "def arrsum(arr): return sum(arr)\n", - "\n", - "# See the previous section on partialler\n", - "add2 = partialler(add, val=2)\n", - "\n", - "transform = compose(filter5, add2, arrsum)\n", - "transform([1,2,3,4,5,6])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "But why is this useful? You might me thinking, I can accomplish the same thing with:\n", - "\n", - "```py\n", - "arrsum(add2(filter5([1,2,3,4,5,6])))\n", - "```\n", - "You are not wrong! However, composition gives you a convenient interface in case you want to do something like the following:" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[7.5, 7.5]" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "def fit(x, transforms:list):\n", - " \"fit a model after performing transformations\"\n", - " x = compose(*transforms)(x)\n", - " y = [np.mean(x)] * len(x) # its a dumb model. Don't judge me\n", - " return y\n", - "\n", - "# filters out elements < 5, adds 2, then predicts the mean\n", - "fit(x=[1,2,3,4,5,6], transforms=[filter5, add2])" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "For more information about `compose`, read [the docs](https://fastcore.fast.ai/basics.html#compose).\n", - "\n", - "---" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## A more useful __repr__\n", - "\n", - "In python, `__repr__` helps you get information about an object for logging and debugging. Below is what you get by default when you define a new class. (Note: we are using `store_attr`, which was discussed earlier)." - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "<__main__.Test at 0x7ffcd766cee0>" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "class Test:\n", - " def __init__(self, a, b=2, c=3): store_attr() # `store_attr` was discussed previously\n", - " \n", - "Test(1)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can use [basic_repr](https://fastcore.fast.ai/basics.html#basic_repr) to quickly give us a more sensible default:" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Test(a=2, b=2, c=3)" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "class Test:\n", - " def __init__(self, a, b=2, c=3): store_attr() \n", - " __repr__ = basic_repr('a,b,c')\n", - " \n", - "Test(2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---\n", - "\n", - "## Monkey Patching With A Decorator\n", - "\n", - "It can be convenient to [monkey patch](https://www.geeksforgeeks.org/monkey-patching-in-python-dynamic-behavior/) with a decorator, which is especially helpful when you want to patch an external library you are importing. We can use the [decorator @patch](https://fastcore.fast.ai/foundation.html#patch) from `fastcore.foundation` along with type hints like so:" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [], - "source": [ - "class MyClass(int): pass \n", - "\n", - "@patch\n", - "def func(self:MyClass, a): return self+a\n", - "\n", - "mc = MyClass(3)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Now, `MyClass` has an additional method named `func`:" - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "13" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mc.func(10)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Still not convinced? I'll show you another example of this kind of patching in the next section." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---\n", - "\n", - "## A better pathlib.Path\n", - "\n", - "When you see [these extensions](https://fastcore.fast.ai/xtras.html#Extensions-to-Pathlib.Path) to pathlib.path you won't ever use vanilla pathlib again! A number of additional methods have been added to pathlib, such as:\n", - "\n", - "- `Path.readlines`: same as `with open('somefile', 'r') as f: f.readlines()`\n", - "- `Path.read`: same as `with open('somefile', 'r') as f: f.read()`\n", - "- `Path.save`: saves file as pickle\n", - "- `Path.load`: loads pickle file\n", - "- `Path.ls`: shows the contents of the path as a list. \n", - "- etc.\n", - "\n", - "[Read more about this here](https://fastcore.fast.ai/xtras.html#Extensions-to-Pathlib.Path). Here is a demonstration of `ls`: " - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(#7) [Path('2020-09-01-fastcore.ipynb'),Path('README.md'),Path('fastcore_imgs'),Path('2020-02-20-test.ipynb'),Path('.ipynb_checkpoints'),Path('2020-02-21-introducing-fastpages.ipynb'),Path('my_icons')]" - ] - }, - "execution_count": 27, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from fastcore.utils import *\n", - "from pathlib import Path\n", - "p = Path('.')\n", - "p.ls() # you don't get this with vanilla Pathlib.Path!!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Wait! What's going on here? We just imported `pathlib.Path` - why are we getting this new functionality? Thats because we imported the `fastcore.utils` module, which patches this module via the `@patch` decorator discussed earlier. Just to drive the point home on why the `@patch` decorator is useful, I'll go ahead and add another method to `Path` right now:" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'This is fun!'" - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "@patch\n", - "def fun(self:Path): return \"This is fun!\"\n", - "\n", - "p.fun()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "That is magical, right? I know! That's why I'm writing about it!" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---\n", - "\n", - "## An Even More Concise Way To Create Lambdas\n", - "\n", - "\n", - "`Self`, with an uppercase S, is an even more concise way to create lambdas that are calling methods on an object. For example, let's create a lambda for taking the sum of a Numpy array:" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [], - "source": [ - "arr=np.array([5,4,3,2,1])\n", - "f = lambda a: a.sum()\n", - "assert f(arr) == 15" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can use `Self` in the same way:" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [], - "source": [ - "f = Self.sum()\n", - "assert f(arr) == 15" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Let's create a lambda that does a groupby and max of a Pandas dataframe:" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
Another Column
Some Column
a6
b60
\n", - "
" - ], - "text/plain": [ - " Another Column\n", - "Some Column \n", - "a 6\n", - "b 60" - ] - }, - "execution_count": 31, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import pandas as pd\n", - "df=pd.DataFrame({'Some Column': ['a', 'a', 'b', 'b', ], \n", - " 'Another Column': [5, 7, 50, 70]})\n", - "\n", - "f = Self.groupby('Some Column').mean()\n", - "f(df)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Read more about `Self` in [the docs](https://fastcore.fast.ai/basics.html#Self-(with-an-uppercase-S))." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---\n", - "\n", - "## Notebook Functions\n", - "\n", - "These are simple but handy, and allow you to know whether or not code is executing in a Jupyter Notebook, Colab, or an Ipython Shell:" - ] - }, - { - "cell_type": "code", - "execution_count": 32, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(True, False, True)" - ] - }, - "execution_count": 32, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from fastcore.imports import in_notebook, in_colab, in_ipython\n", - "in_notebook(), in_colab(), in_ipython()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "This is useful if you are displaying certain types of visualizations, progress bars or animations in your code that you may want to modify or toggle depending on the environment." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "---\n", - "\n", - "## A Drop-In Replacement For List\n", - "\n", - "You might be pretty happy with Python's `list`. This is one of those situations that you don't know you needed a better list until someone showed one to you. Enter `L`, a list like object with many extra goodies. \n", - "\n", - "The best way I can describe `L` is to pretend that `list` and `numpy` had a pretty baby:" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "define a list (check out the nice `__repr__` that shows the length of the list!)" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(#3) [1,2,3]" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "L(1,2,3)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Shuffle a list:" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(#20) [8,7,5,12,14,16,2,15,19,6...]" - ] - }, - "execution_count": 34, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "p = L.range(20).shuffle()\n", - "p" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Index into a list:" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(#3) [5,14,2]" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "p[2,4,6]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "L has sensible defaults, for example appending an element to a list:" - ] - }, - { - "cell_type": "code", - "execution_count": 36, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(#4) [1,2,3,4]" - ] - }, - "execution_count": 36, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "1 + L(2,3,4)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "There is much more `L` has to offer. Read [the docs](https://fastcore.fast.ai/foundation.html#Class-L-Methods) to learn more." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# But Wait ... There's More!\n", - "\n", - "![](fastcore_imgs/bwtm.jpg)\n", - "\n", - "There are more things I would like to show you about fastcore, but there is no way they would reasonably fit into a blog post. Here is a list of some of my favorite things that I didn't demo in this blog post:\n", - "\n", - "## Utilities\n", - "\n", - "The [Basics](https://fastcore.fast.ai/basics.html) section contain many shortcuts to perform common tasks or provide an additional interface to what standard python provides. \n", - "\n", - "- [mk_class](https://fastcore.fast.ai/basics.html#mk_class): quickly add a bunch of attributes to a class\n", - "- [wrap_class](https://fastcore.fast.ai/basics.html#wrap_class): add new methods to a class with a simple decorator\n", - "- [groupby](https://fastcore.fast.ai/basics.html#groupby): similar to Scala's groupby\n", - "- [merge](https://fastcore.fast.ai/basics.html#merge): merge dicts\n", - "- [fasttuple](https://fastcore.fast.ai/basics.html#fastuple): a tuple on steroids\n", - "- [Infinite Lists](https://fastcore.fast.ai/basics.html#Infinite-Lists): useful for padding and testing\n", - "- [chunked](https://fastcore.fast.ai/basics.html#chunked): for batching and organizing stuff\n", - "\n", - "## Multiprocessing\n", - "\n", - "The [Multiprocessing section](http://fastcore.fast.ai/xtras.html#Multiprocessing) extends python's multiprocessing library by offering features like:\n", - "\n", - "- progress bars\n", - "- ability to pause to mitigate race conditions with external services\n", - "- processing things in batches on each worker, ex: if you have a vectorized operation to perform in chunks\n", - "\n", - "## Functional Programming\n", - "\n", - "The [functional programming section](https://fastcore.fast.ai/basics.html#Functions-on-Functions) is my favorite part of this library. \n", - "\n", - "- [maps](https://fastcore.fast.ai/basics.html#maps): a map that also composes functions\n", - "- [mapped](https://fastcore.fast.ai/xtras.html#mapped): A more robust `map` \n", - "- [using_attr](https://fastcore.fast.ai/basics.html#using_attr): compose a function that operates on an attribute\n", - "\n", - "## Transforms\n", - "\n", - "[Transforms](https://fastcore.fast.ai/transform.html) is a collection of utilities for creating data transformations and associated pipelines. These transformation utilities build upon many of the building blocks discussed in this blog post.\n", - "\n", - "\n", - "## Further Reading\n", - "\n", - "**It should be noted that you should read the [main page of the docs](https://fastcore.fast.ai/) first, followed by the section on [tests](https://fastcore.fast.ai/) to fully understand the documentation.**\n", - "\n", - "- The [fastcore documentation site](https://fastcore.fast.ai/).\n", - "- The [fastcore GitHub repo](https://github.com/fastai/fastcore).\n", - "- Blog post on [delegation](https://www.fast.ai/2019/08/06/delegation/)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Shameless plug: fastpages\n", - "\n", - "This blog post was written entirely in a Jupyter Notebook, which GitHub automatically converted into to a blog post! Sound interesting? [Check out fastpages](https://github.com/fastai/fastpages)." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "fastai", - "language": "python", - "name": "fastai" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.3" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/_notebooks/2020-11-17-linkcheck.ipynb b/_notebooks/2020-11-17-linkcheck.ipynb deleted file mode 100755 index 2caa934..0000000 --- a/_notebooks/2020-11-17-linkcheck.ipynb +++ /dev/null @@ -1,470 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# \"Introducing fastlinkcheck\"\n", - "\n", - "> Say goodbye broken links on your static sites. Platform independent, fast, and built in python.\n", - "- author: \"Jeremy Howard and Hamel Husain\"\n", - "- toc: false\n", - "- image: images/copied_from_nb/fastlinkcheck_images/fastlinkcheck.png\n", - "- comments: true\n", - "- categories: [nbdev, fastlinkcheck]\n", - "- permalink: /fastlinkcheck/\n", - "- badges: true" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![diagram](fastlinkcheck_images/fastlinkcheck.png)\n", - "\n", - "# Motivation\n", - "\n", - "Recently, fastai has been hard at work improving and overhauling [nbdev](https://nbdev.fast.ai/), a literate programming environment for python. A key feature of nbdev is automated generation of documentation from Jupyter notebooks. This documentation system adds many niceties, such as the following types of hyperlinks automatically:\n", - "\n", - " - Links to source code on GitHub.\n", - " - Links to both internal and external documentation by introspecting variable names in backticks.\n", - "\n", - "Because documentation is so easy to create and maintain in nbdev, we find ourselves and others creating much more of it! In addition to automatic hyperlinks, we often include our own links to relevant websites, blogs and videos when documenting code. For example, one of the largest nbdev generated sites, [docs.fast.ai](https://docs.fast.ai/), has more than 300 external and internal links at the time of this writing. \n", - "\n", - "\n", - "# The Solution\n", - "\n", - "Due to the continued popularity of [fastai](https://github.com/fastai/fastai) and the growth of new nbdev projects, grooming these links manually became quite tedious. We investigated solutions that could verify links for us automatically, but were not satisfied with any existing solutions. These are the features we desired:\n", - "\n", - "- A platform independent solution that is not tied to a specific static site generator like Jekyll or Hugo.\n", - "- Intelligent introspection of external links that are actually internal links. For example, if we are building the site docs.fast.ai, a link to `https://docs.fast.ai/tutorial` should not result in a web request, but rather introspection of the local file system for the presence of `tutorial.html` in the right location.\n", - "- Verification of any links to assets like CSS, data, javascript or other files. \n", - "- Logs that are well organized that allow us to see each broken link or reference to a non-existent path, and the pages these are found in.\n", - "- Parallelism to verify links as fast as possible. \n", - "- Lightweight, easy to install with minimal dependencies.\n", - "\n", - "We tried tools such as [linkchecker](https://github.com/wummel/linkchecker) and [pylinkvalidator](https://github.com/bartdag/pylinkvalidator), but these required your site to be first be hosted. Since we wanted to check links on a static site, hosting is overhead we wanted to avoid.\n", - "\n", - "This is what led us to create [fastlinkcheck](https://fastlinkcheck.fast.ai/), which we discuss below.\n", - "\n", - "> Note: For Ruby users, [htmlproofer](https://github.com/gjtorikian/html-proofer) apperas to provide overlapping functionality. We have not tried this library. " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# A tour of fastlinkcheck\n", - "\n", - "For this tour we will be referring to the files in the [fastlinkcheck repo](https://github.com/fastai/fastlinkcheck). You should clone this repo in the current directory in order to follow along:" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Cloning into 'fastlinkcheck'...\n", - "remote: Enumerating objects: 135, done.\u001b[K\n", - "remote: Counting objects: 100% (135/135), done.\u001b[K\n", - "remote: Compressing objects: 100% (98/98), done.\u001b[K\n", - "remote: Total 608 (delta 69), reused 76 (delta 34), pack-reused 473\u001b[K\n", - "Receiving objects: 100% (608/608), 1.12 MiB | 10.47 MiB/s, done.\n", - "Resolving deltas: 100% (302/302), done.\n" - ] - } - ], - "source": [ - "git clone https://github.com/fastai/fastlinkcheck.git\n", - "cd fastlinkcheck" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Installation\n", - "\n", - "You can install `fastlinkcheck` with pip:" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "`pip install fastlinkcheck`" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Usage" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "After installing `fastlinkcheck`, the cli command `link_check` is available from the command line. We can see various options with the `--help` flag." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "usage: link_check [-h] [--host HOST] [--config_file CONFIG_FILE] [--pdb]\n", - " [--xtra XTRA]\n", - " path\n", - "\n", - "Check for broken links recursively in `path`.\n", - "\n", - "positional arguments:\n", - " path Root directory searched recursively for HTML files\n", - "\n", - "optional arguments:\n", - " -h, --help show this help message and exit\n", - " --host HOST Host and path (without protocol) of web server\n", - " --config_file CONFIG_FILE\n", - " Location of file with urls to ignore\n", - " --pdb Run in pdb debugger (default: False)\n", - " --xtra XTRA Parse for additional args (default: '')\n" - ] - } - ], - "source": [ - "link_check --help" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "From the root of [fastlinkcheck repo](https://github.com/fastai/fastlinkcheck), We can search the directory `_example/broken_links` recursively for broken links like this:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " \n", - "ERROR: The Following Broken Links or Paths were found:\n", - "\n", - "- 'http://fastlinkcheck.com/test.html' was found in the following pages:\n", - " - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`\n", - "\n", - "- 'http://somecdn.com/doesntexist.html' was found in the following pages:\n", - " - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`\n", - "\n", - "- Path('/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.js') was found in the following pages:\n", - " - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`" - ] - }, - { - "ename": "", - "evalue": "1", - "output_type": "error", - "traceback": [] - } - ], - "source": [ - "link_check _example/broken_links " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Specifying the `--host` parameter allows you detect links that are internal by identifying links with that host name. External links are verified by making a request to the appropriate website. On the other hand, internal links are verified by inspecting the presence and content of local files. \n", - "\n", - "We must be careful when using the `--host` argument to only pass the host (and path, if necessary) **without** the protocol. For example, this is how we specify the hostname if your site's url is `http://fastlinkcheck.com/test.html`:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " \n", - "ERROR: The Following Broken Links or Paths were found:\n", - "\n", - "- 'http://somecdn.com/doesntexist.html' was found in the following pages:\n", - " - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`\n", - "\n", - "- Path('/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.js') was found in the following pages:\n", - " - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`" - ] - }, - { - "ename": "", - "evalue": "1", - "output_type": "error", - "traceback": [] - } - ], - "source": [ - "link_check _example/broken_links --host fastlinkcheck.com" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We now have one less broken link as there is indeed a file named `test.html` in the root of the path we are searching. However, if we add a path to the end of `--host` , such as `fastlinkcheck.com/mysite` the link would again be listed as broken because `_example/broken_links/mysite/test.html` does not exist:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " \n", - "ERROR: The Following Broken Links or Paths were found:\n", - "\n", - "- 'http://fastlinkcheck.com/test.html' was found in the following pages:\n", - " - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`\n", - "\n", - "- 'http://somecdn.com/doesntexist.html' was found in the following pages:\n", - " - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`\n", - "\n", - "- Path('/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.js') was found in the following pages:\n", - " - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`" - ] - }, - { - "ename": "", - "evalue": "1", - "output_type": "error", - "traceback": [] - } - ], - "source": [ - "link_check _example/broken_links --host fastlinkcheck.com/mysite" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can ignore links by creating a text file that contains a list of urls and paths to ignore. For example, the file `_example/broken_links/linkcheck.rc` contains:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "test.js\n", - "https://www.google.com\n" - ] - } - ], - "source": [ - "cat _example/broken_links/linkcheck.rc" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can use this file to ignore urls and paths with the `--config_file` argument. This will filter out references to the broken link `/test.js` from our earlier results:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - " \n", - "ERROR: The Following Broken Links or Paths were found:\n", - "\n", - "- 'http://somecdn.com/doesntexist.html' was found in the following pages:\n", - " - `/Users/hamelsmu/github/fastlinkcheck/_example/broken_links/test.html`" - ] - }, - { - "ename": "", - "evalue": "1", - "output_type": "error", - "traceback": [] - } - ], - "source": [ - "link_check _example/broken_links --host fastlinkcheck.com --config_file _example/broken_links/linkcheck.rc" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Finally, if there are no broken links, `link_check` will not return anything. The directory `_example/no_broken_links/` does not contain any HTML files with broken links:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "█\r", - "\r", - " |--------------------| 0.00% [0/2 00:00<00:00]\r", - "\r", - " |██████████----------| 50.00% [1/2 00:00<00:00]\r", - "\r", - " |████████████████████| 100.00% [2/2 00:00<00:00]\r", - "\r", - " \r", - "No broken links found!\n" - ] - } - ], - "source": [ - "link_check _example/no_broken_links" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Python" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "You can also use these utilities from python instead of the terminal. Please see [these docs](https://fastlinkcheck.fast.ai/linkcheck.html/) for more information." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Using `link_check` in GitHub Actions\n", - "\n", - "\n", - "The `link_check` CLI utility that is installed with `fastlinkcheck` can be very useful in continuous integration systems like [GitHub Actions](https://github.com/features/actions). Here is an example GitHub Actions workflow that uses `link_check`:\n", - "\n", - "\n", - "```yaml\n", - "name: Check Links\n", - "on: [workflow_dispatch, push]\n", - "\n", - "jobs:\n", - " check-links:\n", - " runs-on: ubuntu-latest\n", - " steps:\n", - " - uses: actions/checkout@v2\n", - " - uses: actions/setup-python@v2\n", - " - name: check for broken links\n", - " run: |\n", - " pip install fastlinkcheck\n", - " link_check _example \n", - "```\n", - "\n", - "We can a few more lines of code to open an issue instead when a broken link is found, using the [gh cli](https://github.com/cli/cli):\n", - "\n", - "```yaml\n", - "...\n", - " - name: check for broken links\n", - " run: |\n", - " pip install fastlinkcheck\n", - " link_check _example 2> err || true\n", - " export GITHUB_TOKEN=\"YOUR_TOKEN\"\n", - " [[ -s err ]] && gh issue create -t \"Broken links found\" -b \"$(< err)\" -R \"yourusername/yourrepo\"\n", - "```\n", - "\n", - "We can extend this even further to only open an issue when another issue with a specific label isn't already open:\n", - "\n", - "```yaml\n", - "...\n", - " - name: check for broken links\n", - " run: |\n", - " pip install fastlinkcheck\n", - " link_check \"docs/_site\" --host \"docs.fast.ai\" 2> err || true\n", - " export GITHUB_TOKEN=\"YOUR_TOKEN\"\n", - " if [[ -z $(gh issue list -l \"broken-link\")) && (-s err) ]]; then\n", - " gh issue create -t \"Broken links found\" -b \"$(< err)\" -l \"broken-link\" -R \"yourusername/yourrepo\"\n", - " fi\n", - "```\n", - "\n", - "\n", - "See the [GitHub Actions docs](https://docs.github.com/en/free-pro-team@latest/actions) for more information." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Resources\n", - "\n", - "The following resources are relevant for those interested in learning more about `fastlinkcheck`:\n", - "\n", - "- The fastlinkcheck [GitHub repo](https://github.com/fastai/fastlinkcheck)\n", - "- The fastlinkcheck [docs](https://fastlinkcheck.fast.ai/)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.2" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/_notebooks/fastcore_imgs/bwtm.jpg b/_notebooks/fastcore_imgs/bwtm.jpg deleted file mode 100644 index 2fd6f3f..0000000 Binary files a/_notebooks/fastcore_imgs/bwtm.jpg and /dev/null differ diff --git a/_notebooks/fastcore_imgs/td.png b/_notebooks/fastcore_imgs/td.png deleted file mode 100644 index 8f45e47..0000000 Binary files a/_notebooks/fastcore_imgs/td.png and /dev/null differ diff --git a/_notebooks/fastlinkcheck_images/fastlinkcheck.png b/_notebooks/fastlinkcheck_images/fastlinkcheck.png deleted file mode 100755 index 0b2baed..0000000 Binary files a/_notebooks/fastlinkcheck_images/fastlinkcheck.png and /dev/null differ diff --git a/_posts/2020-03-06-fastpages-actions.md b/_posts/2020-03-06-fastpages-actions.md deleted file mode 100755 index acc3a30..0000000 --- a/_posts/2020-03-06-fastpages-actions.md +++ /dev/null @@ -1,282 +0,0 @@ ---- -title: "GitHub Actions: Providing Data Scientists With New Superpowers" -description: A Tutorial on GitHub Actions For Data Scientists -toc: true -comments: true -layout: post -categories: [actions, markdown] -image: images/fastpages_posts/actions/actions_logo.png -author: Hamel Husain & Jeremy Howard ---- - -# What Superpowers? - -Hi, I'm [Hamel Husain](https://twitter.com/HamelHusain). I'm a machine learning engineer at GitHub. Recently, GitHub released a new product called [GitHub Actions](https://github.com/features/actions), which has mostly flown under the radar in the machine learning and data science community as just another continuous integration tool. - -Recently, I've been able to use GitHub Actions to build some very unique tools for Data Scientists, which I want to share with you today. Most importantly, I hope to get you excited about GitHub Actions, and the promise it has for giving you new superpowers as a Data Scientist. Here are two projects I recently built with Actions that show off its potential: - -## fastpages - -[fastpages](https://github.com/fastai/fastpages) is an automated, open-source blogging platform with enhanced support for Jupyter notebooks. You save your notebooks, markdown, or Word docs into a directory on GitHub, and they automatically become blog posts. Read the announcement below: - -
{% twitter https://twitter.com/jeremyphoward/status/1232059428238581760?s=20 %}
- -## Machine Learning Ops - -Wouldn't it be cool if you could invoke a chatbot natively on GitHub to test your machine learning models on the infrastructure of your choice (GPUs), log all the results, and give you a rich report back in a pull request so that everyone could see the results? You can with GitHub Actions! - -Consider the below annotated screenshot of [this Pull Request](https://github.com/machine-learning-apps/actions-ml-cicd/pull/34): - -![](/images/fastpages_posts/actions/pr_1.png) -![](/images/fastpages_posts/actions/pr_2.png) - -A more in-depth explanation about the above project can be viewed in this video: - -{% include youtube.html content="https://youtu.be/Ll50l3fsoYs" %} - -Using GitHub Actions for machine learning workflows is starting to catch on. [Julien Chaumond](https://twitter.com/julien_c), CTO of [Hugging Face](https://huggingface.co/), says: - -> GitHub Actions are great because they let us do CI on GPUs (as most of our users use the library on GPUs not on CPUs), on our own infra! [^1] - -Additionally, you can host a GitHub Action for other people so others can use parts of your workflow without having to re-create your steps. I provide examples of this below. - -# A Gentle Introduction To GitHub Actions - -## What Are GitHub Actions? - -[GitHub Actions](https://github.com/features/actions) allow you to run arbitrary code in response to [events](https://help.github.com/en/actions/reference/events-that-trigger-workflows). Events are activities that happen on GitHub such as: - -- Opening a pull request -- Making an issue comment -- Labeling an issue -- Creating a new branch -- ... [and many more](https://help.github.com/en/actions/reference/events-that-trigger-workflows) - -When an event is created, the GitHub Actions context is hydrated with a [payload](https://developer.github.com/v3/activity/events/types/) containing metadata for that event. Below is an example of a payload that is received when an issue is created: - -{% raw %} - -```json -{ - "action": "created", - "issue": { - "id": 444500041, - "number": 1, - "title": "Spelling error in the README file", - "user": { - "login": "Codertocat", - "type": "User", - }, - "labels": [ - { - "id": 1362934389, - "node_id": "MDU6TGFiZWwxMzYyOTM0Mzg5", - "name": "bug", - } - ], - "body": "It looks like you accidently spelled 'commit' with two 't's." -} -``` - -This functionality allows you to respond to various events on GitHub in an automated way. In addition to this payload, GitHub Actions also provide a plethora [of variables](https://help.github.com/en/actions/reference/contexts-and-expression-syntax-for-github-actions#github-context) and [environment variables](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables) that afford easy to access metadata such as the username and the owner of the repo. Additionally, other people can package useful functionality into an Action that other people can inherit. For example, consider the below Action that helps you [publish python packages to PyPi](https://github.com/pypa/gh-action-pypi-publish): - -The [Usage](https://github.com/pypa/gh-action-pypi-publish#usage) section describes how this Action can be used: - -```yaml -- name: Publish a Python distribution to PyPI - uses: pypa/gh-action-pypi-publish@master - with: - user: __token__ - password: ${{ secrets.pypi_password }} -``` - -This Action expects two inputs: `user` and a `password`. You will notice that the password is referencing a variable called `secrets`, which is a variable that contains an [encrypted secret](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) that you can upload to your GitHub repository. There are thousands of Actions (that are free) for a wide variety of tasks that can be discovered on the [GitHub Marketplace](https://github.com/marketplace?type=actions). The ability to inherit ready-made Actions in your workflow allows you to accomplish complex tasks without implementing all of the logic yourself. Some useful Actions for those getting started are: - -- [actions/checkout](https://github.com/actions/checkout): Allows you to quickly clone the contents of your repository into your environment, which you often want to do. This does a number of other things such as automatically mount your repository’s files into downstream Docker containers. -- [mxschmitt/action-tmate](https://github.com/mxschmitt/action-tmate): Proivdes a way to debug Actions interactively. This uses port forwarding to give you a terminal in the browser that is connected to your Actions runner. Be careful not to expose sensitive information if you use this. -- [actions/github-script](https://github.com/actions/github-script): Gives you a pre-authenticated [ocotokit.js](https://octokit.github.io/rest.js/) client that allows you to interact with the GitHub API to accomplish almost any task on GitHub automatically. Only [these endpoints](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#permissions-for-the-github_token) are supported (for example, the [secrets endpoint](https://developer.github.com/v3/actions/secrets/) is not in that list). - -In addition to the aforementioned Actions, it is helpful to go peruse the official [GitHub Actions docs](https://help.github.com/en/actions) before diving in. - -## Example: A fastpages Action Workflow - -The best to way familiarize yourself with Actions is by studying examples. Let’s take a look at the Action workflow that automates the build of [fastpages](https://fastpages.fast.ai/fastpages/jupyter/2020/02/21/introducing-fastpages.html) (the platform used to write this blog post). - -### Part 1: Define Workflow Triggers - -First, we define triggers in [ci.yaml](https://github.com/fastai/fastpages/blob/master/.github/workflows/ci.yaml). Like all Actions workflows, this is a YAML file located in the .github/workflows directory of the GitHub repo. - -The top of this YAML file looks like this: - -```yaml -name: CI -on: - push: - branches: - - master - pull_request: -``` - -This means that this workflow is triggered on either a [push](https://help.github.com/en/actions/reference/events-that-trigger-workflows#push-event-push) or [pull request](https://help.github.com/en/actions/reference/events-that-trigger-workflows#pull-request-event-pull_request) event. Furthermore, push events are filtered such that only pushes to the master branch will trigger the workflow, whereas all pull requests will trigger this workflow. It is important to note that pull requests opened from forks will have read-only access to the base repository and cannot access any secrets for security reasons. The reason for defining the workflow in this way is we wanted to trigger the same workflow to test pull requests as well as build and deploy the website when a PR is merged into master. This will be clarified as we step through the rest of the YAML file. - -### Part 2: Define Jobs - -Next, we define jobs (there is only one in this workflow). Per [the docs](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobs): - -> A workflow run is made up of one or more jobs. Jobs run in parallel by default. - -```yaml -jobs: - build-site: - if: ( github.event.commits[0].message != 'Initial commit' ) || github.run_number > 1 - runs-on: ubuntu-latest - steps: -``` - -The keyword `build-site` is the name of your job and you can name it whatever you want. In this case, we have a conditional if statement that dictates if this job should be run or not. We are trying to ensure that this workflow does not run when the first commit to a repo is made with the message ‘Initial commit’. The first variable in the if statement, [github.event](https://help.github.com/en/actions/reference/contexts-and-expression-syntax-for-github-actions#github-context), contains a [json payload](https://developer.github.com/v3/activity/events/types/#webhook-payload-example-31) of the event that triggered this workflow. When developing workflows, it is helpful to print this variable in order to inspect its structure, which you can accomplish with the following YAML: - -```yaml - - name: see payload - run: | - echo "PAYLOAD:\n${PAYLOAD}\n" - env: - PAYLOAD: ${{ toJSON(github.event) }} -``` -_Note: the above step is only for debugging and is not currently in the workflow._ - -[toJson](https://help.github.com/en/actions/reference/contexts-and-expression-syntax-for-github-actions#tojson) is a handy function that returns a pretty-printed JSON representation of the variable. The output is printed directly in the logs contained in the Actions tab of your repo. In this example, printing the payload for a push event will look like this (truncated for brevity): - -```json -{ - "ref": "refs/tags/simple-tag", - "before": "6113728f27ae8c7b1a77c8d03f9ed6e0adf246", - "created": false, - "deleted": true, - "forced": false, - "base_ref": null, - "commits": [ - { - "message": "updated README.md", - "author": "hamelsmu" - }, - ], - "head_commit": null, -} -``` - -Therefore, the variable `github.event.commits[0].message` will retrieve the first commit message in the array of commits. Since we are looking for situations where there is only one commit, this logic suffices. The second variable in the if statement, [github.run_number](https://help.github.com/en/actions/reference/contexts-and-expression-syntax-for-github-actions#github-context) is a special variable in Actions which: - -> [is a] unique number for each run of a particular workflow in a repository. This number begins at 1 for the workflow's first run, and increments with each new run. This number does not change if you re-run the workflow run. - -Therefore, the `if` statement introduced above: -```yaml -if: ( github.event.commits[0].message != 'Initial commit' ) || github.run_number > 1 -``` - -Allows the workflow to run when the commit message is “Initial commit” as long as it is not the first commit. ( `||` is a logical `or` operator). - -Finally, the line `runs-on: ubuntu-latest` specifies the [host operating system](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on) that your workflows will run in. - -### Part 3: Define Steps - -Per the [docs](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idsteps): - -> A job contains a sequence of tasks called steps. Steps can run commands, run setup tasks, or run an Action in your repository, a public repository, or an Action published in a Docker registry. Not all steps run Actions, but all Actions run as a step. Each step runs in its own process in the runner environment and has access to the workspace and filesystem. Because steps run in their own process, changes to environment variables are not preserved between steps. GitHub provides built-in steps to set up and complete a job. - -Below are the first two steps [in our workflow](https://github.com/fastai/fastpages/blob/master/.github/workflows/ci.yaml): - -```yaml - - name: Copy Repository Contents - uses: actions/checkout@master - with: - persist-credentials: false - - - name: convert notebooks and word docs to posts - uses: ./_action_files -``` - -The first step creates a copy of your repository in the Actions file system, with the help of the utility [action/checkout](https://github.com/actions/checkout). This utility only fetches the last commit by default and saves files into a directory (whose path is stored in the environment variable [GITHUB_WORKSPACE](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables) that is accessible by subsequent steps in your job. The second step runs the [fastai/fastpages](https://github.com/fastai/fastpages#using-the-github-action--your-own-custom-blog) Action, which converts notebooks and word documents to blog posts automatically. In this case, the syntax: - -```yaml -uses: ./_action_files -``` - -is a special case where the pre-made GitHub Action we want to run happens to be defined in the same repo that runs this workflow. This syntax allows us to test changes to this pre-made Action when evaluating PRs by referencing the directory in the current repository that defines that pre-made Action. _Note: Building pre-made Actions is beyond the scope of this tutorial._ - -The next three steps in our workflow are defined below: - -```yaml - - name: setup directories for Jekyll build - run: | - rm -rf _site - sudo chmod -R 777 . - - - name: Jekyll build - uses: docker://fastai/fastpages-jekyll - with: - args: bash -c "gem install bundler && jekyll build -V" - env: - JEKYLL_ENV: 'production' - - - name: copy CNAME file into _site if CNAME exists - run: | - sudo chmod -R 777 _site/ - cp CNAME _site/ 2>/dev/null || : -``` - -The step named `setup directories for Jekyll build` executes shell commands that remove the `_site` folder in order to get rid of stale files related to the page we want to build, as well as grant permissions to all the files in our repo to subsequent steps. - -The step named `Jekyll build` executes a docker container hosted by the Jekyll community [on Dockerhub called `jekyll/jekyll`](https://hub.docker.com/r/jekyll/jekyll/). For those not familiar with Docker, see [this tutorial](https://towardsdatascience.com/how-docker-can-help-you-become-a-more-effective-data-scientist-7fc048ef91d5?source=friends_link&sk=c554b55109102d47145c4b3381bee3ee). The name of this container is called `fastai/fastpages-jekyll` because I'm adding some additional dependencies to `jekyll/jekyll` and hosting those on my DockerHub account for faster build times[^2]. The [args parameter](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepswithargs) allows you to execute arbitrary commands with the Docker container by overriding the CMD instruction in the Dockerfile. We use this Docker container hosted on Dockerhub so we don’t have to deal with installing and configuring all of the complicated dependencies for Jekyll. The files from our repo are already available in the Actions runtime due to the first step in this workflow, and are mounted into this Docker container automatically for us. In this case, we are running the command `jekyll build`, which builds our website and places relevant assets them into the `_site` folder. For more information about Jekyll, [read the official docs](https://jekyllrb.com/docs/). Finally, the `env` parameter allows me to pass an environment variable into the Docker container. - -The final command above copies a `CNAME` file into the _site folder, which we need for the custom domain [https://fastpages.fast.ai](https://fastpages.fast.ai/). Setting up custom domains are outside the scope of this article. - -The final step in our workflow is defined below: - -```yaml - - name: Deploy - if: github.event_name == 'push' - uses: peaceiris/actions-gh-pages@v3 - with: - deploy_key: ${{ secrets.SSH_DEPLOY_KEY }} - publish_dir: ./_site -``` - -{% endraw %} - -The statement -```yaml -if: github.event_name == 'push' -``` -uses the variable [github.event_name](https://help.github.com/en/actions/reference/contexts-and-expression-syntax-for-github-actions#github-context) to ensure this step only runs when a push event ( in this case only pushes to the master branch trigger this workflow) occur. - -This step deploys the fastpages website by copying the contents of the `_site` folder to the root of the `gh-pages` branch, which [GitHub Pages](https://pages.github.com/) uses for hosting. This step uses the [peaceiris/actions-gh-pages](https://github.com/peaceiris/actions-gh-pages) Action, pinned at version 3. [Their README](https://github.com/peaceiris/actions-gh-pages) describes various options and inputs for this Action. - -# Conclusion - -We hope that this has shed some light on how we use GitHub Actions to automate fastpages. While we only covered one workflow above, we hope this provides enough intuition to understand the [other workflows](https://github.com/fastai/fastpages/tree/master/.github/workflows) in fastpages. We have only scratched the surface of GitHub Actions in this blog post, but we provide other materials below for those who want to dive in deeper. We have not covered how to host an Action for other people, but you can [start with these docs](https://help.github.com/en/actions/building-actions) to learn more. - -Still confused about how GitHub Actions could be used for Data Science? Here are some ideas of things you can build: - -- Jupyter Widgets that trigger GitHub Actions to perform various tasks on GitHub via the [repository dispatch event](https://help.github.com/en/actions/reference/events-that-trigger-workflows#external-events-repository_dispatch) -- Integration with [Pachyderm](https://www.pachyderm.com/) for data versioning. -- Integration with your favorite cloud machine learning services, such [Sagemaker](https://aws.amazon.com/sagemaker/), [Azure ML](https://azure.microsoft.com/en-us/free/machine-learning/) or GCP's [AI Platform](https://cloud.google.com/ai-platform). - -## Related Materials - -- GitHub Actions official [documentation](https://help.github.com/en/actions) -- [Hello world Docker Action](https://github.com/actions/hello-world-docker-action): A template to demonstrate how to build a Docker Action for other people to use. -- [Awesome Actions](https://github.com/sdras/awesome-actions): A curated list of interesting GitHub Actions by topic. -- [A tutorial on Docker](https://towardsdatascience.com/how-docker-can-help-you-become-a-more-effective-data-scientist-7fc048ef91d5?source=friends_link&sk=c554b55109102d47145c4b3381bee3ee) for Data Scientists. - -### Getting In Touch - -Please feel free to get in touch with us on Twitter: - -- Hamel Husain [@HamelHusain](https://twitter.com/HamelHusain) -- Jeremy Howard [@jeremyphoward](https://twitter.com/jeremyphoward) - -___ -##### Footnotes - -[^1]: You can see some of Hugging Face's Actions workflows for machine learning [on GitHub](https://github.com/huggingface/transformers/tree/master/.github/workflows) -[^2]: These additional dependencies are [defined here](https://github.com/fastai/fastpages/blob/master/_action_files/fastpages-jekyll.Dockerfile), which uses the "jekyll build" command to add ruby dedpendencies from the Gemfile located at the root of the repo. Additionally, this docker image is built by another Action workflow [defined here](https://github.com/fastai/fastpages/blob/master/.github/workflows/docker.yaml). diff --git a/_posts/2020-12-10-codespaces.md b/_posts/2020-12-10-codespaces.md deleted file mode 100755 index a78f700..0000000 --- a/_posts/2020-12-10-codespaces.md +++ /dev/null @@ -1,114 +0,0 @@ ---- -title: "nbdev + GitHub Codespaces: A New Literate Programming Environment" -description: How a new GitHub feature makes literate programming easier than ever before. -comments: true -hide: false -toc: false -layout: post -hide: false -categories: [codespaces, nbdev] -image: images/fastpages_posts/codespaces/codespaces.png -author: "Hamel Husain & Jeremy Howard" -permalink: /codespaces ---- - -**Today, we are going to show you how to set up a literate programming environment, allowing you to use an IDE (VS Code) and an interactive computing environment (Jupyter), without leaving your browser, for free, in under 5 minutes. You'll even see how VSCode and Jupyter work together automatically!** But first, what is literate programming? And how did I go from skeptic to a zealot of literate programming? - -## Introduction - -> Literate programming is a programming paradigm introduced by [Donald Knuth](https://en.wikipedia.org/wiki/Donald_Knuth) in which a computer program is given an explanation of its logic in a natural language, such as English, interspersed with snippets of macros and traditional source code, from which compilable source code can be generated. According to Knuth, literate programming provides higher-quality programs by forcing programmers to explicitly state the thoughts behind the program. This process makes poorly thought-out design decisions more obvious. Knuth also claims that literate programming provides a first-rate documentation system, which is not an add-on, but is grown naturally in the process of exposition of one's thoughts during a program's creation. [^1] - -When I first learned about literate programming, I was quite skeptical. For the longest time, I had wrongly equated [Jupyter notebooks](https://jupyter.org/) with literate programming. Indeed, Jupyter is a brilliant interactive computing system, which was awarded the Association of Computing Machinery (ACM) [Software System Award](https://blog.jupyter.org/jupyter-receives-the-acm-software-system-award-d433b0dfe3a2), and is loved by many developers. However, Jupyter falls short of the literate programming paradigm for the following reasons:[^2] - -- It can be difficult to compile source code from notebooks. -- It can be difficult to diff and use version control with notebooks because they are not stored in plain text. -- It is not clear how to automatically generate documentation from notebooks. -- It is not clear how to properly run tests suites when writing code in notebooks. - -My skepticism quickly evaporated when I began using [nbdev](https://nbdev.fast.ai/), a project that extends notebooks to complete the literate programming ideal. I spent a month, full time, using nbdev while contributing to the python library [fastcore](https://github.com/fastai/fastcore), and can report that Donald Knuth was definitely onto something. The process of writing prose and tests alongside code forced me to deeply understand why the code does what it does, and to think deeply about its design. Furthermore, the reduced cognitive load and speed of iteration of having documentation, code, and tests in one location boosted my productivity to levels I have never before experienced as a software developer. Furthermore, I found that developing this way bolstered collaboration such that code reviews not only happened faster but were more meaningful. In short, nbdev may be the most profound productivity tool I have ever used. - -As a teaser, look how easy it is to instantiate this literate programming environment, which includes a notebook, a docs site and an IDE with all dependencies pre-installed! :point_down: - -{% include video.html url="https://github.com/machine-learning-apps/demo-videos/raw/master/codespaces-nbdev/e2e_small.mp4" %} - -


- -## Features of nbdev - -As discussed in the [docs](https://nbdev.fast.ai/), nbdev provides the following features: - -- Searchable, hyperlinked documentation, which can be automatically hosted on [GitHub Pages](https://docs.github.com/en/github/working-with-github-pages) for free. -- Python modules, following best practices such as [automatically defining `__all__`](http://xion.io/post/code/python-all-wild-imports.html) with your exported functions, classes, and variables. -- Pip and Conda installers. -- Tests defined directly in notebooks which run in parallel. This testing system has been thoroughly tested with [GitHub Actions](https://github.com/features/actions). -- Navigate and edit your code in a standard text editor or IDE, and export any changes automatically back into your notebooks. - -Since you are in a notebook, you can also add charts, text, links, images, videos, etc, that are included automatically in the documentation of your library, along with standardized documentation generated automatically from your code. [This site](https://docs.fast.ai/) is an example of docs generated automatically by nbdev. - -## GitHub Codespaces - -Thanks to [Conda](https://docs.conda.io/en/latest/) and [nbdev_template](https://github.com/fastai/nbdev_template), setting up a development environment with nbdev is far easier than it used to be. However, we realized it could be even easier, thanks to a new GitHub product called [Codespaces](https://github.com/features/codespaces). Codespaces is a fully functional development environment in your browser, accessible directly from GitHub, that provides the following features: - -1. A full VS Code IDE. -2. An environment that has files from the repository mounted into the environment, along with your GitHub credentials. -3. A development environment with dependencies pre-installed, backed by [Docker](https://www.docker.com/). -4. The ability to serve additional applications on arbitrary ports. For nbdev, we serve a Jupyter notebook server as well as a [Jekyll](https://jekyllrb.com/) based documentation site. -5. A shared file system, which facilitates editing code in one browser tab and rendering the results in another. -6. ... [and more](https://docs.github.com/en/github/developing-online-with-codespaces). - -Codespaces enables developers to immediately participate in a project without wasting time on DevOps or complicated setup steps. Most importantly, CodeSpaces with nbdev allows developers to quickly get started with creating their own software with literate programming. - -## A demo of nbdev + Codespaces - -This demo uses the project [fastai/fastcore](https://github.com/fastai/fastcore), which was built with nbdev, as an example. First, we can navigate to this repo and launch a Codespace: - -{% include video.html url="https://github.com/machine-learning-apps/demo-videos/raw/master/codespaces-nbdev/1_open.mp4" %} - -


- -If you are launching a fresh Codespace, it may take several minutes to set up. Once the environment is ready, we can verify that all dependencies we want are installed (in this case `fastcore` and `nbdev`): - -{% include video.html url="https://github.com/machine-learning-apps/demo-videos/raw/master/codespaces-nbdev/2_verify.mp4" %} - -


- -Additionally, we can serve an arbitrary number of applications on user-specified ports, which we can open through VSCode as shown below: - -{% include video.html url="https://github.com/machine-learning-apps/demo-videos/raw/master/codespaces-nbdev/3_nb_small.mp4" %} - -


- -In this case, these applications are a notebook and docs site. Changes to a notebook are reflected immediately in the data docs. Furthermore, we can use the cli command `nbdev_build_lib` to sync our notebooks with python modules. This functionality is shown below: - -{% include video.html url="https://github.com/machine-learning-apps/demo-videos/raw/master/codespaces-nbdev/4_reload_small.mp4" %} - -


- -This is amazing! With a click of a button, I was able to: - -1. Launch an IDE with all dependencies pre-installed. -2. Launch two additional applications: a Jupyter Notebook server on port 8080 and a docs site on port 4000. -3. Automatically update the docs and modules every time I make a change to a Jupyter notebook. - -This is just the tip of the iceberg. There are additional utilities for [writing and executing tests](https://nbdev.fast.ai/test.html), [diffing notebooks](https://nbdev.fast.ai/sync.html#Diff-notebook---library), [special flags](https://nbdev.fast.ai/magic_flags.html#How-do-comment-flags-correspond-to-magic-flags?) for hiding, showing, and collapsing cells in the generated docs, as well as [git hooks](https://nbdev.fast.ai/cli.html#nbdev_install_git_hooks) for automation. This and more functionality is covered in [the nbdev docs](https://nbdev.fast.ai/). - -## Give It A Try For Yourself - -To try out nbdev yourself, [take this tutorial](https://nbdev.fast.ai/tutorial.html), which will walk you through everything you need to know. The tutorial also shows you how to use a repository template with the configuration files necessary to enable Codespaces with nbdev. - -## You Can Write Blogs With Notebooks, Too! - -This blog post was written in [fastpages](https://github.com/fastai/fastpages) which is also built on nbdev! We recommend [fastpages](https://github.com/fastai/fastpages) if you want an easy way to blog with Jupyter notebooks. - -## Additional Resources - -1. The [GitHub Codepaces site](https://github.com/features/codespaces). -1. The official [docs for Codespaces](https://docs.github.com/en/github/developing-online-with-codespaces). -1. The nbdev [docs](https://nbdev.fast.ai/). -2. The nbdev [GitHub repo](https://github.com/fastai/nbdev). -3. [fastpages](https://github.com/fastai/fastpages): The project used to write this blog. -4. The GitHub repo [fastai/fastcore](https://github.com/fastai/fastcore), which is what we used in this blog post as an example. - ----- -[^1]: Wikipedia article: [Literate Programming](https://en.wikipedia.org/wiki/Literate_programming) -[^2]: This is not a criticism of Jupyter. Jupyter doesn't claim to be a full literate programming system. However, people can sometimes (unfairly) judge Jupyter according to this criteria. diff --git a/_word/2020-01-01-Microsoft-Word-Example-Post.docx b/_word/2020-01-01-Microsoft-Word-Example-Post.docx deleted file mode 100644 index c58f9bf..0000000 Binary files a/_word/2020-01-01-Microsoft-Word-Example-Post.docx and /dev/null differ diff --git a/action.yml b/action.yml deleted file mode 100644 index 8fd3e1a..0000000 --- a/action.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: 'fastpages: An easy to use blogging platform with support for Jupyter Notebooks.' -description: Converts Jupyter notebooks and Word docs into Jekyll blog posts. -author: Hamel Husain -inputs: - BOOL_SAVE_MARKDOWN: - description: Either 'true' or 'false'. Whether or not to commit converted markdown files from notebooks and word documents into the _posts directory in your repo. This is useful for debugging. - required: false - default: false - SSH_DEPLOY_KEY: - description: a ssh deploy key is required if BOOL_SAVE_MARKDOWN = 'true' - required: false -branding: - color: 'blue' - icon: 'book' -runs: - using: 'docker' - image: '_action_files/Dockerfile' diff --git a/images/fastpages_posts/actions/actions_logo.png b/images/fastpages_posts/actions/actions_logo.png deleted file mode 100755 index e3c5650..0000000 Binary files a/images/fastpages_posts/actions/actions_logo.png and /dev/null differ diff --git a/images/fastpages_posts/actions/pr_1.png b/images/fastpages_posts/actions/pr_1.png deleted file mode 100755 index c6c1fd2..0000000 Binary files a/images/fastpages_posts/actions/pr_1.png and /dev/null differ diff --git a/images/fastpages_posts/actions/pr_2.png b/images/fastpages_posts/actions/pr_2.png deleted file mode 100755 index 6f93c08..0000000 Binary files a/images/fastpages_posts/actions/pr_2.png and /dev/null differ diff --git a/images/fastpages_posts/codespaces/codespaces.png b/images/fastpages_posts/codespaces/codespaces.png deleted file mode 100755 index b19bdb9..0000000 Binary files a/images/fastpages_posts/codespaces/codespaces.png and /dev/null differ