Software Development

Looking for resources to get started with software development? Check out the  Scientific Python Development Guide . The  Turing Way Guide for Reproducible Research  and  Turing Way Guide for Project Design  are also useful.

Templates

If you're starting a new GitHub repository for a Python package, it helps to start from a template. We have one such template at  https://github.com/Quantum-Accelerators/template . Click "Use this template", replace all instances of "template" with your desired package name, and you should be good to go! Further details can be found in the  template repository's documentation  and corresponding video.

Unit Tests

When developing any new software package in the group or contributing to existing open-source software packages, it is absolutely essential to write and regularly use unit tests (i.e. tests that evaluate the behavior and output of your various functions and classes). Simply put, this is the only way to know if your code is working as intended and if changes break your code in unexpected ways.

While it may seem annoying at first to develop unit tests, they will save you an immense amount of pain in the long-term. We use  pytest  for our unit tests. The Turing Way Guide for Reproducible Research has a  "Code Testing" section  that is very useful. In general, if you are developing code to be used by others, these tests should run automatically on GitHub via a continuous integration setup. There is also a  "Continuous Integration" section  in the Turing Way guide.

Most of the content in this handbook is merely a suggestion and a matter of personal preference. Writing unit tests for any production software, however, is a requirement.

Handling Paths

Where possible, you should strive for your code to be platform-agnostic. One of the main things to keep in mind is that different operating systems handle paths different. As a general rule, you should never define paths in your code with string concatenation (i.e. do not do  "/path/to/my/" + "folder" ). Instead, you should use the  pathlib  library. For instance:
from pathlib import Path

p = Path("path/to/my/folder")
# or...
p = Path("path/to/my") / "folder"

GitHub Add-Ons for Developers

The following are useful, automated tools to improve your GitHub experience and are all installed on the group GitHub page:
 Deepsource : This program will automatically analyze your GitHub code to identify potential errors. It can also "auto-fix" common issues as well. This is highly recommended for both personal and public projects given its ease-of-use.
 Codecov : This program will automatically analyze your GitHub code to determine which lines are (or are not) covered by your unit tests. This, or a related tool to measure code coverage, should be considered a requirement for any new package being developed in the group.
 Sourcery.ai : This program will automatically refactor and clean up your code. There is a convenient command-line interface that I generally recommend. The GitHub add-on can be a bit "chatty".