Sphinx
Sphinx ↗ is a tool that makes it easy to create documentation and was originally made for the publication of Python documentation. It is well known for its simplicity and ease of use.
In this guide, you will create a new Sphinx project and deploy it using Cloudflare Pages.
-
Python 3 - Sphinx is based on Python, therefore you must have Python installed
-
pip ↗ - The PyPA recommended tool for installing Python packages
-
pipenv ↗ - automatically creates and manages a virtualenv for your projects
The latest version of Python 3.7 is 3.7.11:
Refer to the official Python documentation for installation guidance:
If you already had an earlier version of Python installed before installing version 3.7, other global packages you may have installed could interfere with the following steps to install Pipenv, or your other Python projects which depend on global packages.
Pipenv ↗ is a Python-based package manager that makes managing virtual environments simple. This guide will not require you to have prior experience with or knowledge of Pipenv to complete your Sphinx site deployment. Cloudflare Pages natively supports the use of Pipenv and, by default, has the latest version installed.
The quickest way to install Pipenv is by running the command:
This command will install Pipenv to your user level directory and will make it accessible via your terminal. You can confirm this by running the following command and reviewing the expected output:
From your terminal, run the following commands to create a new directory and navigate to it:
Pipenv allows you to specify which version of Python to associate with a virtual environment. For the purpose of this guide, the virtual environment for your Sphinx project must use Python 3.7.
Use the following command:
You should see the following output:
List the contents of the directory:
Before installing Sphinx, create the directory you want your project to live in.
From your terminal, run the following command to install Sphinx:
You should see output similar to the following:
This will install Sphinx into a new virtual environment managed by Pipenv. You should see a directory structure like this:
With Sphinx installed, you can now run the quickstart command to create a template project for you. This command will only work within the Pipenv environment you created in the previous step. To enter that environment, run the following command from your terminal:
Now run the following command:
You will be presented with a number of questions, please answer them in the following:
This will create four new files in your active directory, source/conf.py
, index.rst
, Makefile
and make.bat
:
You now have everything you need to start deploying your site to Cloudflare Pages. For learning how to create documentation with Sphinx, refer to the official Sphinx documentation ↗.
All of the framework guides assume you already have a fundamental understanding of Git ↗. If you are new to Git, refer to this summarized Git handbook ↗ on how to set up Git on your local machine.
If you clone with SSH, you must generate SSH keys ↗ on each computer you use to push or pull from GitHub.
Refer to the GitHub documentation ↗ and Git documentation ↗ for more information.
In a separate terminal window that is not within the pipenv shell session, verify that SSH key-based authentication is working:
Create a new GitHub repository by visiting repo.new ↗. After your repository is set up, push your application to GitHub by running the following commands in your terminal:
To deploy your site to Pages:
- Log in to the Cloudflare dashboard ↗ and select your account.
- In Account Home, select Workers & Pages > Create application > Pages > Connect to Git.
- Select the new GitHub repository that you created and, in the Set up builds and deployments section, provide the following information:
Configuration option | Value |
---|---|
Production branch | main |
Build command | make html |
Build directory | build/html |
Below the configuration, make sure to set the environment variable for specifying the PYTHON_VERSION
.
For example:
Variable name | Value |
---|---|
PYTHON_VERSION | 3.7 |
After configuring your site, you can begin your first deploy. You should see Cloudflare Pages installing Pipenv
, your project dependencies, and building your site, before deployment.
After deploying your site, you will receive a unique subdomain for your project on *.pages.dev
. Every time you commit new code to your Sphinx site, Cloudflare Pages will automatically rebuild your project and deploy it.
You will also get access to preview deployments on new pull requests, so you can preview how changes look to your site before deploying them to production.
By completing this guide, you have successfully deployed your Sphinx site to Cloudflare Pages. To get started with other frameworks, refer to the list of Framework guides.