Skip to content

Commit

Permalink
Fix usage file and get publish to work
Browse files Browse the repository at this point in the history
  • Loading branch information
pydanny committed Sep 28, 2023
1 parent 172d7ba commit a23d068
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 21 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: deploy

on:
# Trigger the deploy on push to main branch
push:
branches:
- main
- add-jupyter-books-docs
schedule:
# jupyter-book is updated regularly, let's run this deployment every month in case something fails
# <minute [0,59]> <hour [0,23]> <day of the month [1,31]> <month of the year [1,12]> <day of the week [0,6]>
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html#tag_20_25_07
# https://crontab.guru/every-month
# Run cron job every month
- cron: '0 0 1 * *'

jobs:
# This job deploys the example book
deploy-example-book:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.10]
steps:
- uses: actions/checkout@v2
# Install CC
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -r requirements.txt
# Use default CC
- name: Cookiecutter no GHA
run: |
cookiecutter . --no-input include_ci=no
# Install requirements.txt
- name: Install requirements
run: |
pip install -r my_book/requirements.txt
# Build the example book
- name: Build book
run: |
jupyter-book build my_book/my_book/
# Deploy html to gh-pages
- name: GitHub Pages action
uses: peaceiris/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: my_book/my_book/_build/html
publish_branch: gh-pages
43 changes: 22 additions & 21 deletions docs/usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,50 @@
"source": [
"# Usage\n",
"\n",
"First, find your project's `manage.py` file and open it. Copy whatever is being set to `DJANGO_SETTINGS_MODULE` into your clipboard.\n",
"\n",
"Create an ipython notebook in the same directory as `manage.py`. In VSCode,\n",
"simply add a new `.ipynb` file. If using Jupyter Lab, use the `File -> New ->\n",
"Notebook` menu option.\n",
"Notebook` menu option. \n",
"\n",
"Where `DJANGO_SETTINGS_MODULE_VALUE` is the 'dot' seperated value of your `DJANGO_SETTINGS_MODULE` setting, in the first cell enter:\n",
"In the first cell type the following:\n",
"\n",
"```python\n",
"\n",
"from dj_notebook import activate\n",
"\n",
"plus = activate(\"DJANGO_SETTINGS_MODULE_VALUE\")\n",
"```\n",
"\n",
"See below for an example that works with our Django test project: "
"Then, find your project's `manage.py` file and open it. Copy whatever is being set to `DJANGO_SETTINGS_MODULE` as a string argument to `activate` function. \n",
"\n",
"See below for an example that works with dj-notebook's Django test project: "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"execution_count": 1,
"metadata": {
"tags": [
"remove-input"
]
},
"outputs": [],
"source": [
"# Special configuration\n",
"import pathlib\n",
"import sys\n",
"\n",
"# project base\n",
"here = pathlib.Path('.').parent\n",
"KRAKEN_ROOT = (here / \"..\" / \"tests\" / \"django_test_project\").resolve()\n",
"sys.path.insert(0, str(KRAKEN_ROOT))\n",
"sys.path.insert(0, str(KRAKEN_ROOT))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"\n",
"from dj_notebook import activate\n",
"\n",
Expand All @@ -61,19 +75,6 @@
"source": [
"plus.User.objects.all()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In future cells, you can now load and run Django objects, including the ORM. This three line snippet should give an idea of what you can now do:\n",
"\n",
"```python\n",
"from django.contrib.auth import get_user_model\n",
"User = get_user_model()\n",
"User.objects.all()\n",
"```"
]
}
],
"metadata": {
Expand Down

0 comments on commit a23d068

Please sign in to comment.