Coding#

Important

This tutorial assumes you have a working development environment.

In this tutorial, we’ll show you how to ensure everything is ready for you to start contributing.

Syncing your fork#

In the Setting up tutorial, you forked the repository you’ll contribute to. Before starting to code it’s important to ensure that the main branch in your fork is synced with the main branch in the original repository. To do so, click on sync fork:

sync-fork

If you have problems syncing your fork, message us on Slack.

Creating a new branch#

Now, let’s create a new branch. Move to the directory that contains your fork and create a new branch:

git checkout -b my-new-branch

Tip

Change my-new-branch for a descriptive name that reflects what this branch is about.

All the code changes that you do will take place in this new branch. Let’s now verify your IDE configuration.

Committing your work#

commit as much as you want

it won’t destroy anything

once you’re ready to show your work, open a PR

Tip

We encourage you to start working on your contribution and open a draft Pull Request to request early feedback, this will helps us ensure we’re on the same page.

Verifying conda environment#

First, open a terminal and activate the environment for the project you’ll be working on:

conda environment ENV_NAME

Important

Take note on the ENV_NAME, since we’ll need this value later.

Now, execute the following:

python -c 'import sys; print(sys.prefix)'

You should see something like this if you installed miniconda:

path/to/miniconda3/envs/ENV_NAME/bin/python

Or like this, if you installed Anaconda:

path/to/anaconda3/envs/ENV_NAME/bin/python

Warning

If the output does not contain miniconda or anaconda, send us a message on Slack and we’ll help you.

JupyterLab#

Warning

Starting JupyterLab from another environment or Anaconda’s graphical user interface might create issues. We highly recommend you install and start JupyterLab from the same conda environment, as described below.

If you want to use JupyterLab for developing, ensure you install and start it from the same conda environment:

# activate environment
conda activate ENV_NAME

# install JupyterLab
pip install jupyterlab

# start JupyterLab
jupyter lab

Once JupyterLab opens, open a notebook, a terminal:

notebook-and-terminal

And run the following, in the notebook:

import sys; print("sys.prefix:", sys.prefix)

Verify that the printed value is the same as you saw in the Verifying conda environment section (the ENV_NAME).

Now, open a terminal and run the following:

python -c 'import sys; print("sys.prefix:", sys.prefix)'

Then, ensure that what’s printed is ENV_NAME; if it’s not, then you’ll have to run conda activate ENV_NAME every time you open a terminal.

Warning

Once a package is imported in Jupyter, changes to the source code are not automatically reflected. You need to restart the kernel or enable autoreload

If you’ll be contributing with code, go to the Coding section, if you’ll be contributing with documentation, go to the Building documentation section.

VSCode#

When using VSCode, you must ensure that you’re using the right Python installation. You can easily set this by opening the command paletter, then typing Python: Select Interpreter:

vscode-1-py-interpreter

Then, type the ENV_NAME. For example, if I’m setting up JupySQL, ENV_NAME is jupysql, so once I type it, I’ll see this:

vscode-2-env-name

And type enter. Then, whenever you open a terminal, the conda environment will be automatically activated:

vscode-3-terminal

If it doesn’t execute automatically, you’ll have to run the conda activate ENV_NAME command every time you open a terminal.

VSCode notebooks#

If you want to write notebooks from VSCode, you need to ensure that the right kernel is enabled. Once you open a notebook, click on “Select Kernel”:

vscode-4-kernel

Then, select the Python Environments... option and type Enter:

vscode-5-kernel-name

Finally, type the ENV_NAME, choose the option that matches the location of the conda environment and press Enter:

vscode-6-kernel-select